From 49da1d33b47647a027c1e142e396c418fe5230d3 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 9 Nov 2008 22:55:34 +0100 Subject: [PATCH] Better initd example. Signed-off-by: Florent Bruneau --- example/postlicyd.initd.sh | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/example/postlicyd.initd.sh b/example/postlicyd.initd.sh index e32764b..b07ecd9 100755 --- a/example/postlicyd.initd.sh +++ b/example/postlicyd.initd.sh @@ -9,32 +9,45 @@ POSTLICYD=/usr/sbin/postlicyd PIDFILE=/var/run/postlicyd/pid CONF=/etc/pfixtools/postlicyd.conf -[ -z $1 ] && die "usage $0 (start|stop|reload)" +[ -z $1 ] && die "usage $0 (start|stop|reload|check-conf)" + +mkdir -p `dirname "$PIDFILE"` || die "Can't create $PIDFILE" + +do_checkconf() { + $POSTLICYD -c "$CONF" &> /dev/null + return "$?" +} case "$1" in start) - mkdir -p `dirname "$PIDFILE"` || die "Can't create $PIDFILE" echo "Starting postlicyd..." - flock -x -n "$PIDFILE" -c "true" || die "Already started" - $POSTLICYD -p "$PIDFILE" "$CONF" || die "Failed" + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $POSTLICYD --text > /dev/null || die "Already running" + do_checkconf || die "Invalid configuration" + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $POSTLICYD -- -p "$PIDFILE" "$CONF" || die "Failed" echo "Started" ;; stop) echo "Stopping postlicyd..." - ( flock -x -n "$PIDFILE" -c "true" && die "Not started" ) \ - || ( kill `cat $PIDFILE` && echo "Stopped" ) \ - || die "Failed" + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name "postlicyd" + case "$?" in + 0) echo "Stopped" ;; + 1) die "Nothing to stop" ;; + 2) die "Cannot stop process" ;; + esac ;; reload) echo "Reloading postlicyd..." - ( flock -x -n "$PIDFILE" -c "true" && die "Not started" ) \ - || ( kill -HUP `cat $PIDFILE` && ( sleep 3; echo "Done" ) ) \ - || die "Failed" + do_checkconf || die "Invalid configuration" + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name postlicyd + ;; + + check-conf) + do_checkconf || die "Invalid configuration" ;; *) - die "usage $0 (start|stop|reload)" + die "usage $0 (start|stop|reload|check-conf)" ;; esac -- 2.20.1