Debian

儘管程序失敗,start-stop-daemon 始終返回“0”

  • March 1, 2019

我正在嘗試執行一個將nodejs作為守護程序啟動的**初始化腳本。**問題是,當我執行它時,無論 nodejs-daemon 可能返回什麼錯誤,它總是返回“0”。start-stop-daemon

據我所知,在使用開關時會出現start-stop-daemon問題--background

使用 switchstart-stop-daemon即使 nodejs-daemon 失敗,也總是返回 ‘0’。

root# start-stop-daemon --start --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --make-pidfile --pidfile $PIDFILE --exec $DAEMON  --background -- $DAEMON_ARGS ; echo ---error: $?
---error: 0

請注意,守護程序靜默失敗,此時未執行!

如果沒有 switch,我們實際上可以看到守護程序無法啟動。

root# start-stop-daemon --start --chuid $GHOST_USER:$GHOST_GROUP --chdir $GHOST_ROOT --make-pidfile --pidfile $PIDFILE --exec $DAEMON  -- $DAEMON_ARGS ; echo ---error: $?
ERROR: Unsupported version of Node
Ghost needs Node version ~0.10.0 || ~0.12.0 || ^4.2.0 you are using version 5.10.0

Please see http://support.ghost.org/supported-node-versions/ for more information
---error: 231

現在我正在尋找一個解決方案,這樣--background當它無法啟動 nodejs 守護程序時,我可以使用該開關並獲得大於“0”的錯誤程式碼。

這是記錄在案的行為。分叉後台程序後,前台程序完成。從手冊頁:

-b, --background
         Typically used with programs that don't detach on their own. This option will force start-stop-daemon to fork before starting the process, and  force
         it  into  the  background.   Warning:  start-stop-daemon  cannot check the exit status if the process fails to execute for any reason. This is a last
         resort, and is only meant for programs that either make no sense forking on their own, or where it's not feasible to add the code for them to do this
         themselves.

引用自:https://unix.stackexchange.com/questions/274541