【发布时间】:2011-11-29 06:49:47
【问题描述】:
我必须在启动/停止脚本中调用 perl 程序。我的 perl 程序在 path/to/program: /home/nuthan/server. 现在,我的任务是创建一个启动/停止脚本。即,需要在启动时调用命令 daemon -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 "$1" in
start)
start
;;
stop)
stop
;;
status)
status FOO
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
【问题讨论】:
-
好吧,我对这个脚本一无所知,我不得不承认我在读了大约 10 行之后就停止了阅读,但可能在它上面写着
FOO的任何地方。 -
你不需要不知道 perl 就不会理解这个脚本,因为它不是 perl。就像 shebang 说的,这是 bash。
-
TLP 可以使用 bash 而不是 perl。在我看来,两者都一样。