/*************************************************************************
* start-stop-daemon自动启动、关闭后台程序参数传递
* 说明:
* 看了使用start-stop-deamon启动脚本,没看到怎么传递参数的,测试一下怎么
* 使用。
*
* 2017-10-11 深圳 南山平山村 曾剑锋
************************************************************************/
一、参考文档:
1. start-stop-daemon(8)
http://man7.org/linux/man-pages/man8/start-stop-daemon.8.html
二、传递参数:
1. -S, --start [--] arguments
Check for the existence of a specified process. If such a
process exists, start-stop-daemon does nothing, and exits with
error status 1 (0 if --oknodo is specified). If such a
process does not exist, it starts an instance, using either
the executable specified by --exec or, if specified, by
--startas. Any arguments given after -- on the command line
are passed unmodified to the program being started.
2. 如上所述,在--之后加入命令行参数:
start-stop-daemon -S -b -x /usr/sbin/httpd -- -h /var/www
三、示例:
cat /etc/init.d/S71httpd
#! /bin/sh
set -e
DESC="httpd"
NAME=httpd
DAEMON=/usr/sbin/$NAME
case "$1" in
start)
printf "Starting $DESC: "
start-stop-daemon -S -b -x $NAME -- -h /var/www
echo "OK"
;;
stop)
printf "Stopping $DESC: "
start-stop-daemon -K -x $NAME
echo "OK"
;;
restart|force-reload)
echo "Restarting $DESC: "
$0 stop
sleep 1
$0 start
echo ""
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0