啟動時執行 Upstart 使用者作業

啟動時執行 Upstart 使用者作業

我正在運行 Ubuntu 伺服器 11.04。我已經按照描述建立了 Upstart 使用者作業這裡

我的目錄中有以下檔案/home/myuser/.init/sensors.conf

start on started mysql
stop on stopping mysql


chdir /home/myuser/mydir/project
exec /home/myuser/mydir/env/bin/python /home/myuser/mydir/project/manage.py sensors

respawn

respawn limit 10 90

因為myuser我可以正常啟動、停止和重新載入作業,所以它運作得很好:

$ start sensors
sensors start/running, process 1332
$ stop sensors
sensors stop/waiting

問題是該作業在啟動時不會在mysql啟動時自動啟動。重新啟動後,mysql正在運行,但我的sensors工作沒有。

奇怪的是,雖然工作不是在啟動時開始,但如果我sudo重新啟動mysql它確實會開始我的工作。以下命令myuser從全新啟動時運行:

$ status sensors
sensors stop/waiting
$ sudo restart mysql
mysql start/running, process 1209
$ status sensors
sensors start/running, process 1229

Upstart 使用者作業的文檔非常有限。讓使用者作業在系統啟動時自動啟動的正確技術是什麼?

我知道我可以扔一些東西rc.local來啟動它,或者我可以將我的移動sensors.conf/etc/init但我很好奇是否有一種方法可以僅使用 Upstart 來做到這一點。

答案1

問題是,在使用者透過執行其中一個initctl命令來建立 Upstart 會話之前,使用者作業不會載入到 Upstart 中。

我已經更詳細地描述了它http://bradleyayers.blogspot.com.au/2012/04/enabling-upstart-user-jobs-to-start-at.html並且還編寫了一個解決該問題的 Upstart 作業。

答案2

看看諸如/etc/init/mysql.conf和 之類的來源http://upstart.ubuntu.com/cookbook/#start-on在我看來你應該將你的start on線路更改為如下所示:

start on (mysql and runlevel [2345])

我不確定我是否同意暴發戶缺乏文檔,但有時我確實很難理解文檔。我通常只是反覆試驗,直到它起作用為止。上面的解決方案實際上可能有點矯枉過正......像這樣簡單的事情可能就足夠了:

start on mysql

相關內容