You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/debian/ngcp-panel.init

138 lines
3.0 KiB

#!/bin/sh
### BEGIN INIT INFO
# Provides: ngcp-panel
# Required-Start: $syslog $network $local_fs $remote_fs $time
# Required-Stop: $syslog $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: sshd
# Short-Description: Start the ngcp-panel webapp
# Description: Start the ngcp-panel webapp
### END INIT INFO
. /lib/lsb/init-functions
DAEMON=/usr/share/ngcp-panel/ngcp_panel_fastcgi.pl
HOMEDIR=/usr/share/ngcp-panel
HOMERUN=/var/run/fastcgi
PIDFILE=$HOMERUN/ngcp-panel.pid
USER=www-data
GROUP=www-data
NAME="ngcp-panel"
DESC="NGCP-Panel Webapp"
DEFAULTS=/etc/default/$NAME
USOCKET=$HOMERUN/ngcp-panel.sock
LOGERR=/var/log/ngcp/ngcp-panel.log
NPROC=1
OPTIONS="--listen $USOCKET --daemon --pidfile $PIDFILE --nproc $NPROC"
check_running() {
if [ -s $PIDFILE ]; then
kill -0 $(cat $PIDFILE) >/dev/null 2>&1
else
PID=`pidofproc $DAEMON`
if [ -z "$PID" ]; then
return 1
fi
fi
}
_start() {
rm -f $PIDFILE 2>/dev/null
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--exec $DAEMON --chdir $HOMEDIR \
--user $USER --group $GROUP --chuid $USER:$GROUP \
-- $OPTIONS || log_failure_msg "error"
sleep 1
if check_running ; then
return 0
else
return 1
fi
}
_stop() {
if ! check_running ; then
log_progress_msg " not running"
return 0
fi
if [ -e $PIDFILE ]; then
kill `cat $PIDFILE`;
else
PID=`pidofproc $DAEMON`
if [ -n "$PID" ]; then
kill $PID
fi
fi
for i in 1 2 3 4 5 6 7; do
log_progress_msg "."
sleep 1;
if ! check_running ; then
return 0
fi
done
if check_running ; then
return 1
fi
}
# Load startup options if available
if [ -f $DEFAULTS ]; then
. $DEFAULTS || true
fi
if [ "$RUN_DAEMON" != "yes" ]; then
log_failure_msg "$NAME not yet configured. Edit /etc/default/$NAME first."
log_end_msg 0
exit 0
fi
# $HOMERUN perms
mkdir -p $HOMERUN && chown -R $USER:$GROUP $HOMERUN
case "$1" in
start)
log_daemon_msg "Starting $DESC: $NAME"
if check_running; then
log_progress_msg "already running"
log_end_msg 0
exit 0
fi
_start; status="$?"
log_end_msg $status
exit $status
;;
stop)
log_daemon_msg "Stopping $DESC: $NAME"
_stop; status="$?"
log_end_msg $status
exit $status
;;
restart|force-reload)
log_daemon_msg "Restarting web application" $NAME
_stop; status="$?"
if [ "$status" = 0 ]; then
_start; status="$?"
fi
log_end_msg $status
exit $status
;;
status)
log_daemon_msg "Status of $DESC: "
if [ -s $PIDFILE ]; then
status_of_proc -p$PIDFILE $DAEMON $NAME
else
status_of_proc $DAEMON $NAME
fi
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0