2014-07-31 18:05:32 +04:00
#!/bin/bash
2014-07-30 21:18:42 +04:00
2014-11-25 00:28:13 +03:00
# Default configured services
if [ -e /etc/debian_version ]; then
2014-11-25 17:22:02 +03:00
TOWER_CONFIG="/etc/default/ansible-tower"
2014-07-30 21:18:42 +04:00
else
2014-11-25 17:22:02 +03:00
TOWER_CONFIG="/etc/sysconfig/ansible-tower"
2014-07-30 21:18:42 +04:00
fi
2014-11-25 17:22:02 +03:00
# Load default configuration
2014-11-25 00:28:13 +03:00
[ -e "${TOWER_CONFIG}" ] && . "${TOWER_CONFIG}"
2014-07-30 21:18:42 +04:00
service_action() {
2015-05-05 23:33:24 +03:00
SERVICES=$TOWER_SERVICES
for svc in ${SERVICES}; do
2015-07-14 18:14:13 +03:00
2014-11-17 21:25:33 +03:00
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
2016-03-30 16:09:07 +03:00
S_PID=$(pidof -x supervisord)
2015-05-18 19:05:47 +03:00
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
2014-11-17 21:25:33 +03:00
fi
2014-07-30 21:18:42 +04:00
done
}
2015-05-22 17:15:16 +03:00
usage() {
echo "Ansible Tower service helper utility"
echo "Usage: $0 {start|stop|restart|status}"
}
2014-08-01 17:50:51 +04:00
worst_return=0
2014-07-30 21:18:42 +04:00
case "$1" in
2015-05-22 17:15:16 +03:00
help | -help | --help | -h)
usage
;;
2014-07-30 21:18:42 +04:00
start)
2016-03-30 16:09:07 +03:00
echo "Starting Tower"
service_action start
;;
2014-07-30 21:18:42 +04:00
stop)
2016-03-30 16:09:07 +03:00
echo "Stopping Tower"
service_action stop
;;
2014-07-30 21:18:42 +04:00
restart)
2016-03-30 16:09:07 +03:00
echo "Restarting Tower"
service_action stop
service_action start
;;
2014-07-30 21:18:42 +04:00
status)
2016-03-30 16:09:07 +03:00
echo "Showing Tower Status"
service_action status
;;
2014-07-30 21:18:42 +04:00
*)
2015-05-22 17:15:16 +03:00
usage
worst_return=1
2014-07-30 21:18:42 +04:00
esac
2014-08-01 17:50:51 +04:00
exit $worst_return