Linux 守护进程启动

Mr.*_*ool 5 linux redhat daemon linux-kernel

我在linux(Redhat Server Edition 5.1)上编写了一项服务。它是由 shell script 启动的,如果我启动我的应用程序,我手动启动我的服务,现在我想在启动时启动我的服务,这意味着我将我的服务放在我的守护进程 init.d 文件夹中,而不是在启动时调用,有人知道如何在 Linux 上启动时启动守护进程吗?

这是我的样本,但不起作用

#!/bin/sh
#
# myservice     This shell script takes care of starting and stopping
#               the <myservice>
#

# Source function library
. /etc/rc.d/init.d/functions


# Do preliminary checks here, if any
#### START of preliminary checks #########


##### END of preliminary checks #######


# Handle manual control parameters like start, stop, status, restart, etc.

case "$1" in
  start)
    # Start daemons.

    echo -n $"Starting <myservice> daemon: "
    echo
    daemon <myservice>
    echo
    ;;

  stop)
    # Stop daemons.
    echo -n $"Shutting down <myservice>: "
    killproc <myservice>
    echo

    # Do clean-up works here like removing pid files from /var/run, etc.
    ;;
  status)
    status <myservice>

    ;;
  restart)
    $0 stop
    $0 start
    ;;

  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 1
esac

exit 0
Run Code Online (Sandbox Code Playgroud)

Gui*_*USE 4

在您的脚本中添加 2 条注释:

# chkconfig: - 90 10
# description: description of your service
Run Code Online (Sandbox Code Playgroud)

以 root 身份运行:

chkconfig --add my_service
Run Code Online (Sandbox Code Playgroud)