95 lines
3.2 KiB
Bash
95 lines
3.2 KiB
Bash
#!/bin/bash
|
|
### BEGIN INIT INFO
|
|
# Provides: {{ service_name }}
|
|
# Required-Start:
|
|
# Required-Stop:
|
|
# Default-Start: {{ service_start_levels }}
|
|
# Default-Stop:
|
|
# Short-Description: {{ service_name }}
|
|
# Description:
|
|
### END INIT INFO
|
|
|
|
|
|
service_is_running()
|
|
{
|
|
if [ -e {{ service_pid_file }} ]; then
|
|
PID=$(cat {{ service_pid_file }})
|
|
if $(ps $PID > /dev/null 2>&1); then
|
|
return 0
|
|
else
|
|
echo "Found obsolete PID file for {{ service_name }}...deleting it"
|
|
rm {{ service_pid_file }}
|
|
return 1
|
|
fi
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
|
|
case $1 in
|
|
start)
|
|
echo "Starting {{ service_name }}..."
|
|
if service_is_running; then
|
|
echo "{{ service_name }} is already running"
|
|
exit 0
|
|
fi
|
|
|
|
echo "
|
|
|
|
_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/_/_/_/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/_/_/_/ _/ _/_/_/_/ _/_/_/_/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/ _/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/ _/_/_/_/ _/ _/
|
|
|
|
|
|
_/_/_/_/ _/_/_/ _/_/_/_/ _/_/ _/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/_/_/ _/_/ _/_/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/_/ _/ _/ _/ _/ _/ _/ _/ _/
|
|
_/ _/_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/
|
|
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/ _/
|
|
_/ _/ _/ _/ _/ _/ _/_/ _/_/_/_/ _/ _/_/_/_/ _/ _/ _/ _/ _/
|
|
|
|
" >> {{ service_log_dir }}/{{ service_name }}.log
|
|
|
|
nohup sudo -u {{ service_user }} {{ virtualenv_location }}/bin/python \
|
|
{{ service_dir }}/{{ service_file }} \
|
|
>> {{ service_log_dir }}/{{ service_name }}.log \
|
|
2>> {{ service_log_dir }}/{{ service_name }}.log &
|
|
PID=$(echo $!)
|
|
if [ -z $PID ]; then
|
|
echo "{{ service_name }} failed to start"
|
|
else
|
|
echo $PID > {{ service_pid_file }}
|
|
echo "{{ service_name }} is running"
|
|
fi
|
|
;;
|
|
stop)
|
|
echo "Stopping {{ service_name }}..."
|
|
if service_is_running; then
|
|
PID=$(cat {{ service_pid_file }})
|
|
sudo kill -- -$(ps -o pgid= $PID | grep -o '[0-9]*')
|
|
rm {{ service_pid_file }}
|
|
echo "{{ service_name }} is stopped"
|
|
else
|
|
echo "{{ service_name }} is not running"
|
|
exit 0
|
|
fi
|
|
;;
|
|
status)
|
|
if service_is_running; then
|
|
echo "{{ service_name }} is running"
|
|
else
|
|
echo "{{ service_name }} is not running"
|
|
fi
|
|
;;
|
|
restart)
|
|
$0 stop
|
|
$0 start
|
|
;;
|
|
esac
|