1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00
awx/tools/scripts/ansible-tower-service

100 lines
2.5 KiB
Plaintext
Raw Normal View History

2014-07-31 18:05:32 +04:00
#!/bin/bash
2014-07-30 21:18:42 +04:00
# Default configured services
if [ -e /etc/debian_version ]; then
TOWER_CONFIG="/etc/default/ansible-tower"
2014-07-30 21:18:42 +04:00
else
TOWER_CONFIG="/etc/sysconfig/ansible-tower"
2014-07-30 21:18:42 +04:00
fi
# Load default configuration
[ -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
# When determining whether mongod is required, postgres is required. The
# following ensures mongod is started after postgres, and stopped before
# postgres.
case ${1} in
start|status)
SERVICES="$SERVICES mongod"
;;
stop)
SERVICES="mongod $SERVICES"
;;
esac
2015-05-05 23:33:24 +03:00
for svc in ${SERVICES}; do
# Determine whether mongod is needed
if [[ ${svc} == mongod ]]; then
2015-07-14 19:10:01 +03:00
tower-manage uses_mongo --local 2> /dev/null >/dev/null
# if mongod is not required, break
if [ $? -ne 0 ]; then
continue
fi
fi
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
2014-07-30 21:18:42 +04:00
done
}
usage() {
echo "Ansible Tower service helper utility"
echo "Usage: $0 {start|stop|restart|status}"
}
worst_return=0
2014-07-30 21:18:42 +04:00
case "$1" in
help | -help | --help | -h)
usage
;;
2014-07-30 21:18:42 +04:00
start)
echo "Starting Tower"
service_action start
;;
2014-07-30 21:18:42 +04:00
stop)
echo "Stopping Tower"
service_action stop
;;
2014-07-30 21:18:42 +04:00
restart)
echo "Restarting Tower"
service_action stop
service_action start
;;
2014-07-30 21:18:42 +04:00
status)
echo "Showing Tower Status"
service_action status
;;
2014-07-30 21:18:42 +04:00
*)
usage
worst_return=1
2014-07-30 21:18:42 +04:00
esac
exit $worst_return