您的位置:首页 > 运维架构

start-stop-daemon自动启动、关闭后台程序参数传递

2017-10-11 15:35 1946 查看
/*************************************************************************
*          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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐