#!/usr/bin/env bash
# Exit if error and pipe any from ctl commands
#set -eo
# Stop Pushy Server
chef-server-ctl stop opscode-pushy-server
# Nuke it from DB
echo "drop database opscode_pushy;" | su -l opscode-pgsql -c "psql"
echo "DROP ROLE opscode_pushy" | su -l opscode-pgsql -c "psql"
echo "DROP ROLE opscode_pushy_ro" | su -l opscode-pgsql -c "psql"
# Stop everyone else so we can remove runit refs without complaints on start
chef-server-ctl stop
systemctl stop private_chef-runsvdir-start.service
# Remove and purge
yum remove opscode-push-jobs-server -y
dirs="
/var/log/opscode/opscode-pushy-server
/var/opt/opscode-push-jobs-server
/opt/opscode-push-jobs-server
/etc/opscode-push-jobs-server
/opt/opscode/service/opscode-pushy-server
/opt/opscode/sv/opscode-pushy-server
/var/opt/opscode/nginx/etc/addon.d/10-push_jobs_upstreams.conf
/var/opt/opscode/nginx/etc/addon.d/10-push_jobs_external.conf
"
for ii in $dirs;do
if [ -e $ii ];then
echo "EXISTS $ii"
rm -rf $ii
else
echo "NOPE $ii"
fi
done
# Catch any outliers but prompt so no accidents
for ii in `find / -type d | grep push | grep -v 'dev-lxc' | egrep 'job|server'`;do
if [ -d $ii ];then
echo "EXISTS $ii"
rm -ri $ii
else
echo "NOPE"
fi
done
# Up we go
systemctl start private_chef-runsvdir-start.service
sleep 2
# Not necessary at all but a quasi-sanity check of sorts
chef-server-ctl restart
echo "Grep push from ps aux"
ps aux | grep push