start-stop-daemon †
入手 †
$ tar -xf dpkg_1.17.6.tar.xz
$ cd dpkg-1.17.6
$ sudo yum install ncurses-devel ncurses
$ ./configure
$ make
$ cd utils
$ sudo cp start-stop-daemon /usr/local/bin
使用 †
#!/bin/bash
DAEMON=/usr/bin/python
PIDFILE=/home/xxx/hoge.pid
DAEMON_ARGS=/home/xxx/hoge.py
case "$1" in
"start")
start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
result=$?
if [ $result != "0" ]
then
pid=`cat $PIDFILE`
echo "daemon is already running. (pid=${pid})"
exit 1
fi
;;
"stop")
start-stop-daemon --stop --quiet --pidfile $PIDFILE
result=$?
if [ $result != "0" ]
then
echo "daemon is not running. (check $PIDFILE)."
exit 1
fi
rm -f $PIDFILE
;;
esac