啟動service的時候用nohup

來源:互聯網
上載者:User

這不是什麼時候都出問題,不過在我兩個用boost::asio寫的service需要安裝成Linux service時,在用newlisp的(exec "service data_service start")來啟動的時候,發現newlisp會掛起,這個問題我曾經在newlisp社區提過,直到我都已經忘記有這件事情都沒有人回答。:(

不過今天再次遇到這個問題,決定嘗試自己解決一下,首先推測是service的啟動指令碼寫的有問題

原來的在/etc/init.d/data-service中有一行

./data_service ./config.xml &


這個data_service指令檔在終端運行一切正常。

不過看了這個文章後http://stackoverflow.com/questions/4797050/how-to-run-process-as-background-and-never-die

想起來,自己之前還用過nohup,用它試一下如何。

nohup ./data_service_d ./config.xml > /dev/null 2>&1 &

好,問題解決了。

解釋在這裡:

nohup means: Do not terminate this process even when the stty is cut off.> /dev/null means: stdout goes to /dev/null (which is a dummy device that does not record any output).2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null).& at the end means: run this command as a background task.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.