awx/tools/scripts/ansible-tower
Matthew Jones e4936e4b80 Fix supervisor restart behavior for ubuntu, and adjust timeouts *way*
down on when supervisor can harikiri it's child processes
2015-05-18 12:06:29 -04:00

83 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
#
# ansible-tower
#
# chkconfig: - 20 80
# description: support init to manage tower and its related services
### BEGIN INIT INFO
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: support init to manage tower and its related services
# Description: Ansible Tower provides an easy-to-use UI and dashboard, role-based access control and more for your Ansible initiative
### END INIT INFO
# Default configured services
if [ -e /etc/debian_version ]; then
TOWER_CONFIG="/etc/default/ansible-tower"
else
TOWER_CONFIG="/etc/sysconfig/ansible-tower"
fi
# Load default configuration
[ -e "${TOWER_CONFIG}" ] && . "${TOWER_CONFIG}"
service_action() {
for svc in ${TOWER_SERVICES}; do
service ${svc} $1
this_return=$?
if [ $this_return -gt $worst_return ]; then
worst_return=$this_return
fi
# Allow supervisor time to cleanup child pids (ubuntu only)
if [[ ${svc} == supervisor* && ${1} == stop && -e /etc/debian_version ]]; then
S_PID=$(pidof -x supervisord)
echo "Waiting to allow supervisor time to cleanup ... pid ${S_PID}"
if [ "${S_PID}" ]; then
i=0
while kill -0 "${S_PID}" 2> /dev/null; do
if [ $i = '60' ]; then
break;
else
if [ $i == '0' ]; then
echo -n " ... waiting"
else
echo -n "."
fi
i=$(($i+1))
sleep 1
fi
done
fi
fi
done
}
worst_return=0
case "$1" in
start)
echo "Starting Tower"
service_action start
;;
stop)
echo "Stopping Tower"
service_action stop
;;
restart)
echo "Restarting Tower"
service_action stop
service_action start
;;
status)
echo "Showing Tower Status"
service_action status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit $worst_return