chkconfig 支持 Linux 服务需要什么?

Geo*_*Geo 37 scripting linux redhat chkconfig

我正在尝试通过

chkconfig -add <servicename> 
Run Code Online (Sandbox Code Playgroud)

我收到一条消息说

service <servicename> does not support chkconfig
Run Code Online (Sandbox Code Playgroud)

我正在使用 Red Hat Enterprise 4。我试图在启动时添加到自动启动的脚本如下:

#!/bin/sh

soffice_start() {   if [ -x /opt/openoffice.org2.4/program/soffice ]; then
        echo "Starting Open Office as a Service"
        #echo " soffice -headless -accept=socket,port=8100;urp;StarOffice.ServiceManager
-nofirststartwizard"
        /opt/openoffice.org2.4/program/soffice
-headless -accept="socket,host=0.0.0.0,port=8100;urp;StarOffice.ServiceManager"
-nofirststartwizard &   else
        echo "Error: Could not find the soffice program. Cannot Start SOffice."   fi }

soffice_stop() {   if [ -x /usr/bin/killall ]; then
        echo "Stopping Openoffice"
        /usr/bin/killall soffice 2> /dev/null   else
        echo "Eroor: Could not find killall.  Cannot Stop soffice."   fi }

case "$1" in  'start')    soffice_start    ;;  'stop')    soffice_stop    sleep 2    ;;  'restart')    soffice_stop    sleep 5  soffice_start    ;;  *)    if [ -x /usr/bin/basename ]; then
        echo "usage: '/usr/bin/basename $0' start| stop| restart"    else
        echo "usage: $0 start|stop|restart"    fi esac
Run Code Online (Sandbox Code Playgroud)

kat*_*iel 78

该脚本必须有 2 行:

# chkconfig: <levels> <start> <stop>
# description: <some description>
Run Code Online (Sandbox Code Playgroud)

例如:

# chkconfig: 345 99 01
# description: some startup script

345 - levels to configure
99 - startup order
01 - stop order
Run Code Online (Sandbox Code Playgroud)

添加上述标题后,您可以运行chkconfig --add <service>.

  • 以下是有关运行级别和其他内容的更多信息。http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html (2认同)

Kam*_*iel 6

虽然 katriel 已经用创建 init 脚本所需的最低限度回答了这个问题,但我认为您也可以查看/etc/init.d/skeleton并使用它作为 init 脚本的基础模板。您最终会得到一个更加一致和可读的脚本。

  • 理论上很好的建议,但是`/etc/init.d/skeleton` 不存在于RHEL 系统上,只存在于Debian 和相关系统(我认为是Ubuntu)上。 (6认同)