【问题标题】:init.d start/stop scriptsinit.d 启动/停止脚本
【发布时间】: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。在我看来,两者都一样。

标签: linux bash daemon


【解决方案1】:

这是您需要将daemon 命令放入start function 的位置。

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
}

一般init.d 脚本应该记录 pid,killproc 应该知道在哪里可以找到 pid。

但是有很多方法无法按预期工作,您将学到很多有关修复它的 unix、perl 和 init.d 脚本的知识。

【讨论】:

    猜你喜欢
    • 2018-09-18
    • 1970-01-01
    • 2011-04-01
    • 2013-06-30
    • 2014-04-13
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 2018-03-17
    相关资源
    最近更新 更多