update start script

This commit is contained in:
ssamson-tis 2015-07-08 17:20:27 +02:00
parent 9a561e66bb
commit 6e2635fe30
2 changed files with 183 additions and 118 deletions

View File

@ -1,133 +1,99 @@
#!/usr/bin/env bash
#!/bin/sh
### BEGIN INIT INFO
# Provides: tisbackup_gui-uwsgi
# Required-Start: $all
# Required-Stop: $all
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the uwsgi app server for tisbackup_gui
# Description: starts uwsgi app server for tisbackup_gui using start-stop-daemon
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
set -e
VERSION=$(basename $0)
PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/$VERSION
RUN=/var/run/
NAME=$VERSION
CONFIG_FILE=/etc/tis/tisbackup_gui.ini
LOGFILE=/var/log/$NAME.log
OWNER=root
DESC=$VERSION
OP=$1
dir="/opt/tisbackup/"
cmd="python tisbackup_gui.py"
user="root"
DAEMON_OPTS=""
name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
# Include uwsgi defaults if available
if [[ -f /etc/default/$VERSION ]]; then
. /etc/default/$VERSION
fi
do_pid_check()
{
local PIDFILE=$1
[[ -f $PIDFILE ]] || return 0
local PID=$(cat $PIDFILE)
for p in $(pgrep $VERSION); do
[[ $p == $PID ]] && return 1
done
return 0
get_pid() {
cat "$pid_file"
}
do_start()
{
# for config in $ENABLED_CONFIGS; do
local PIDFILE=$RUN/$NAME.pid
if do_pid_check $PIDFILE; then
uwsgi -d $LOGFILE --pidfile $PIDFILE --ini $CONFIG_FILE
# sudo -u $OWNER -i $VERSION $config $DAEMON_OPTS --pidfile $PIDFILE
else
echo "Already running!"
fi
# done
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
send_sig()
{
local PIDFILE=$RUN/$NAME.pid
set +e
[[ -f $PIDFILE ]] && kill $1 $(cat $PIDFILE) > /dev/null 2>&1
set -e
}
wait_and_clean_pidfiles()
{
local PIDFILE=$RUN/$NAME.pid
until do_pid_check $PIDFILE; do
echo -n "";
done
rm -f $PIDFILE
}
do_stop()
{
send_sig -3
wait_and_clean_pidfiles
}
do_reload()
{
send_sig -1
}
do_force_reload()
{
send_sig -15
}
get_status()
{
send_sig -10
}
case "$OP" in
case "$1" in
start)
echo "Starting $DESC: "
do_start
echo "$NAME."
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
echo -n "Stopping $DESC: "
do_stop
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC: "
do_reload
echo "$NAME."
;;
force-reload)
echo -n "Force-reloading $DESC: "
do_force_reload
echo "$NAME."
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
echo "Restarting $DESC: "
do_stop
sleep 3
do_start
echo "$NAME."
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
get_status
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

99
scripts/tisbackup_huey Executable file
View File

@ -0,0 +1,99 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
dir="/opt/tisbackup/"
cmd="huey_consumer.py -n tisbackup_gui.huey"
user="root"
name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0