Re: looking for replacement for run (because of critical bug in
On Sat, Dec 23, 2000 at 06:46:46PM +0000, Marc Haber wrote:
> On Sat, 23 Dec 2000 09:14:25 +0100, Andreas Fuchs <asf@acm.org> wrote:
> >start-stop-daemon won't work,
>
> start-stop-daemon IIRC needs $program to background itself, and it
> can't IIRC restart dying processes. run stays around to keep a watch
> on its child.
Yes and no. It can daemonize a program, but will not restart it when it dies.
It sounds like what you want is a simple shell script that would be daemonized
by start-stop-daemon:
/usr/sbin/myprogram.wrapper:
#!/bin/sh
while true; do
myprogram
# Prevent excessive resource consumption if myprogram exits immediately
sleep 5
done
/etc/init.d/myprogram:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/myprogram.wrapper
NAME=myprogram
DESC="myprogram"
test -f $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --background --make-pidfile \
--pidfile /var/run/$NAME.pid --exec $DAEMON
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --background --make-pidfile
--pidfile /var/run/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
However, I would say that if the program dies so frequently that it needs a
wrapper like this, it should probably be fixed.
> >I wonder if a sh script could do what Marc described...
>
> You'd have to have a ton of precautions. The task at hand seems
> trivial, but it isn't :-(
init does a good job of this; if there were an easy, error-proof way to add
entries to inittab (i.e., without editing the file in your maintainer scripts),
using init's 'respawn' mode might not be a bad idea.
--
- mdz
Reply to: