2015-06-21 103 views
0

我試圖複製/etc/init.d/skeleton並修改它以在後臺啓動程序。我想出了以下幾點:start-stop-daemon沒有檢測到已經運行的守護進程

do_start() 
{ 
    # Return 
    # 0 if daemon has been started 
    # 1 if daemon was already running 
    # 2 if daemon could not be started 
    start-stop-daemon --start --quiet --pidfile $PIDFILE -b --make-pidfile --exec $DAEMON --test > /dev/null \ 
     || return 1 
    start-stop-daemon --start --quiet --pidfile $PIDFILE -b --make-pidfile --exec $DAEMON -- \ 
     $DAEMON_ARGS \ 
     || return 2 
} 

do_stop() 
{ 
    # Return 
    # 0 if daemon has been stopped 
    # 1 if daemon was already stopped 
    # 2 if daemon could not be stopped 
    # other if a failure occurred 
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME 
    RETVAL="$?" 
    [ "$RETVAL" = 2 ] && return 2 
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON 
    [ "$?" = 2 ] && return 2 
    # Many daemons don't delete their pidfiles when they exit. 
    rm -f $PIDFILE 
    return "$RETVAL" 
} 

我有一個問題和幾個關於這方面的問題。我的問題是,啓動函數啓動一個守護進程,並返回0,無論守護進程是否已經運行。我的問題是,如果-b和--make-pidfile在第一個測試開始時是必需的。我是否正確地假設do_stop中的第一個命令向守護進程發送一個TERM信號,第二個命令強制終止守護進程?在這種情況下,我將不得不等待守護進程退出。

回答

1

我的問題是--exec,因爲我的腳本是一個解釋腳本start-stop-daemon找不到運行這個名字的程序,因爲解釋器只在運行。我通過使用--startas來解決這個問題,除了--exec。

相關問題