Add restart to daemonize script

This commit is contained in:
Martin Polden 2013-04-10 13:52:20 +02:00
parent a200325d11
commit e963029ef7

View File

@ -2,8 +2,9 @@
NAME="ifconfig" NAME="ifconfig"
IFC_PATH=$(dirname $(readlink -f $0)) IFC_PATH=$(dirname $(readlink -f $0))
LOCK_FILE="$IFC_PATH/$NAME.lock" LOCK_FILE="$IFC_PATH/tmp/${NAME}.lock"
PID_FILE="$IFC_PATH/$NAME.pid" PID_FILE="$IFC_PATH/tmp/${NAME}.pid"
LOG_FILE="$IFC_PATH/tmp/${NAME}.log"
BIN="$IFC_PATH/$NAME" BIN="$IFC_PATH/$NAME"
E_USAGE=1 E_USAGE=1
@ -16,16 +17,16 @@ if [[ ! -x "$BIN" ]]; then
exit $E_NOTFOUND exit $E_NOTFOUND
fi fi
case "$1" in start () {
start)
if [[ -f "$LOCK_FILE" ]]; then if [[ -f "$LOCK_FILE" ]]; then
echo "Lock file $LOCK_FILE exists. Already running?" echo "Lock file $LOCK_FILE exists. Already running?"
exit $E_LOCKED exit $E_LOCKED
fi fi
echo "Starting $NAME" echo "Starting $NAME"
daemonize -c $IFC_PATH -o ${NAME}.log -p $PID_FILE -l $LOCK_FILE $BIN daemonize -c $IFC_PATH -o $LOG_FILE -p $PID_FILE -l $LOCK_FILE $BIN
;; }
stop)
stop () {
if [[ ! -s "$PID_FILE" ]]; then if [[ ! -s "$PID_FILE" ]]; then
echo "PID file $PID_FILE empty or not found. Not started?" echo "PID file $PID_FILE empty or not found. Not started?"
exit $E_NOPID exit $E_NOPID
@ -34,16 +35,32 @@ case "$1" in
echo "Stopping $NAME: $PID" echo "Stopping $NAME: $PID"
kill $PID kill $PID
rm -f -- $PID_FILE $LOCK_FILE rm -f -- $PID_FILE $LOCK_FILE
;; }
status)
status () {
if [[ ! -s "$PID_FILE" ]]; then if [[ ! -s "$PID_FILE" ]]; then
echo "$NAME is not running" echo "$NAME is not running"
else else
echo "$NAME is running: $(head -n1 $PID_FILE)" echo "$NAME is running: $(head -n1 $PID_FILE)"
fi fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;; ;;
*) *)
echo "usage: $0 {start|stop|status}" echo "usage: $0 {start|stop|restart|status}"
exit $E_USAGE exit $E_USAGE
;; ;;
esac esac