/************************************************************************* * 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