Linux
chkconfig 支持 linux 服務需要什麼?
我正在嘗試通過
chkconfig -add <servicename>
我收到一條消息說
service <servicename> does not support chkconfig
我正在使用 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
腳本必須有 2 行:
# chkconfig: <levels> <start> <stop> # description: <some description>
例如:
# chkconfig: 345 99 01 # description: some startup script 345 - levels to configure 99 - startup order 01 - stop order
添加上述標題後,您可以執行
chkconfig --add <service>
.
雖然 katriel 已經用創建 init 腳本所需的最低限度來回答這個問題,但我認為您也可以很好地查看
/etc/init.d/skeleton
並使用它作為您的 init 腳本的模板。你最終會得到一個更加一致和可讀的腳本。