echoip/daemonize.sh

65 lines
1.2 KiB
Bash
Raw Normal View History

2012-11-21 13:51:23 +01:00
#!/usr/bin/env bash
NAME="ifconfig"
2013-05-23 10:31:09 +02:00
PREFIX=$(dirname $(readlink -f $0))
DAEMON="$PREFIX/$NAME"
PID_FILE="${PREFIX}/tmp/${NAME}.pid"
LOCK_FILE="${PREFIX}/tmp/${NAME}.lock"
LOG_FILE="${PREFIX}/tmp/${NAME}.log"
2012-11-21 13:51:23 +01:00
E_USAGE=1
E_NOTFOUND=2
2013-05-23 10:31:09 +02:00
if [[ ! -x "$DAEMON" ]]; then
echo "$DAEMON does not exist or is not executable"
2012-11-21 13:51:23 +01:00
exit $E_NOTFOUND
fi
2013-04-10 13:52:20 +02:00
start () {
2013-05-23 10:31:09 +02:00
echo -n "Starting $NAME: "
mkdir -p $PREFIX/tmp
daemonize -c $PREFIX -o $LOG_FILE -p $PID_FILE -l $LOCK_FILE $DAEMON && \
echo "ok" || echo "failed"
2013-04-10 13:52:20 +02:00
}
stop () {
2013-05-23 10:31:09 +02:00
echo -n "Stopping $NAME: "
if [[ -s "$PID_FILE" ]]; then
PID=$(head -n1 $PID_FILE)
kill $PID 2> /dev/null && echo "ok" || echo "not running?"
2013-04-10 13:52:20 +02:00
fi
rm -f -- $PID_FILE $LOCK_FILE
}
status () {
2013-05-23 10:31:09 +02:00
if [[ -s "$PID_FILE" ]]; then
PID=$(head -n1 $PID_FILE)
kill -0 $PID 2> /dev/null && echo "$NAME is running (pid: $PID)" || \
echo "$NAME is not running"
2013-04-10 13:52:20 +02:00
else
2013-05-23 10:31:09 +02:00
echo "$NAME is not running"
2013-04-10 13:52:20 +02:00
fi
}
2012-11-21 13:51:23 +01:00
case "$1" in
start)
2013-04-10 13:52:20 +02:00
start
2012-11-21 13:51:23 +01:00
;;
stop)
2013-04-10 13:52:20 +02:00
stop
;;
restart)
stop
start
2012-11-21 13:51:23 +01:00
;;
status)
2013-04-10 13:52:20 +02:00
status
2012-11-21 13:51:23 +01:00
;;
*)
2013-04-10 13:52:20 +02:00
echo "usage: $0 {start|stop|restart|status}"
2012-11-21 13:51:23 +01:00
exit $E_USAGE
;;
esac
2013-05-23 10:31:09 +02:00
exit $?