From 6e2635fe3054f795bb62a06d0ca7260f854ee0a3 Mon Sep 17 00:00:00 2001 From: ssamson-tis Date: Wed, 8 Jul 2015 17:20:27 +0200 Subject: [PATCH] update start script --- scripts/tisbackup_gui | 202 +++++++++++++++++------------------------ scripts/tisbackup_huey | 99 ++++++++++++++++++++ 2 files changed, 183 insertions(+), 118 deletions(-) create mode 100755 scripts/tisbackup_huey diff --git a/scripts/tisbackup_gui b/scripts/tisbackup_gui index e155b5f..39e2c99 100755 --- a/scripts/tisbackup_gui +++ b/scripts/tisbackup_gui @@ -1,133 +1,99 @@ -#!/usr/bin/env bash - +#!/bin/sh ### BEGIN INIT INFO -# Provides: tisbackup_gui-uwsgi -# Required-Start: $all -# Required-Stop: $all -# 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 +# 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 -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." - ;; - status) - get_status - ;; - *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 + $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 + diff --git a/scripts/tisbackup_huey b/scripts/tisbackup_huey new file mode 100755 index 0000000..36adbcf --- /dev/null +++ b/scripts/tisbackup_huey @@ -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 +