2011-11-29 195 views
1

我必須在啓動/停止腳本中調用perl程序。我有我的perl程序在路徑/到/ 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新手。請幫忙,我在哪裏添加命令,還是我錯了?init.d啓動/停止腳本

#!/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 
+1

嗯,我對這個劇本一無所知,我不得不承認我在大約10行後停止閱讀,但可能在任何地方說'FOO'。 –

+3

你不需要不知道Perl不理解這個腳本,因爲它不是perl。就像shebang所說的那樣,這是bash。 – TLP

+0

TLP確定它的bash而不是perl。兩者在我看來都是一樣的。 – nuthan

回答

2

這是你需要把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腳本。