bash init.d 启动/停止脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8306938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
init.d start/stop scripts
提问by nuthan
I have to call a perl program in start/stop script. I have my perl program in path/to/program: /home/nuthan/server. Now, my task is to create a start/stop script. i.e., need to call command daemon -d -v -r perl /home/nuthan/server -l /tmp/kon start and kill the pid on stop. I found too many scripts on net, i found this at http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html. but I don't understand this, as I am new to Perl. Please help, where do i add the commands, or Am i wrong?
我必须在启动/停止脚本中调用 perl 程序。我在 path/to/program: /home/nuthan/server 中有我的 perl 程序。现在,我的任务是创建一个启动/停止脚本。即,需要在启动时调用命令守护进程 -d -v -r perl /home/nuthan/server -l /tmp/k并在停止时终止 pid。我在网上发现了太多脚本,我在http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html找到了这个。但我不明白这一点,因为我是 Perl 的新手。请帮忙,我在哪里添加命令,或者我错了吗?
#!/bin/bash
# description: Foo server
# Get function from functions library
. /etc/init.d/functions
# Start the service FOO
start() {
initlog -c "echo -n Starting FOO server: "
/path/to/FOO &
### Create the lock file ###
touch /var/lock/subsys/FOO
success $"FOO server startup"
echo
}
# Restart the service FOO
stop() {
initlog -c "echo -n Stopping FOO server: "
killproc FOO
### Now, delete the lock file ###
rm -f /var/lock/subsys/FOO
echo
}
### main logic ###
case "" in
start)
start
;;
stop)
stop
;;
status)
status FOO
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: start() {
initlog -c "echo -n Starting FOO server: "
daemon -d -v -r perl /home/nuthan/server -l /tmp/k
### Create the lock file ###
touch /var/lock/subsys/FOO
success $"FOO server startup"
echo
}
{start|stop|restart|reload|status}"
exit 1
esac
exit 0
回答by MattH
This is where you'd need to put the daemoncommand in the start function.
这是您需要将daemon命令放入start function.
Generally init.dscripts should record the pid and killprocshould know where to find the pid.
通常init.d脚本应该记录 pid 并且killproc应该知道在哪里可以找到 pid。
However there are so many ways that this could not work as expected, you'll be learning a lot about unix, perl and init.d scripts fixing it.
然而,有很多方法无法按预期工作,您将学到很多关于修复它的 unix、perl 和 init.d 脚本。

