2014-06-11 36 views
2

我對bitcoind新貴腳本,它基於本主題中的腳本:https://bitcointalk.org/index.php?topic=25518.0爲bitcoind新貴腳本,重生功能

我強烈需要重生的未來工作:萬一發生什麼事bitcoind自動重新啓動。我試圖模仿這種情況,但暴發戶沒有重新啓動這個過程。

問題:我該如何讓暴發戶(或別的東西)觀看bitcoind,如果發生了什麼不良事件,請重新啓動它?

實際腳本:

description "bitcoind" 

start on filesystem 
stop on runlevel [!2345] 
oom never 
expect daemon 
respawn 
respawn limit 10 60 # 10 times in 60 seconds 

script 
user=root 
home=/root/.bitcoin/ 
cmd=/usr/bin/bitcoind 
pidfile=$home/bitcoind.pid 
# Don't change anything below here unless you know what you're doing 
[[ -e $pidfile && ! -d "/proc/$(cat $pidfile)" ]] && rm $pidfile 
[[ -e $pidfile && "$(cat /proc/$(cat $pidfile)/cmdline)" != $cmd* ]] && rm $pidfile 
exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile --startas $cmd -b -m 
end script 
+0

你能解釋一下你怎麼模擬的情況pull請求? – CameronNemo

+0

我試着用-15和-9信號殺死它 –

回答

2
oom never 

是你的第一個問題。您需要:

oom score never 

此外,不要使用除關鍵系統服務以外永遠不會使用oom分數。改爲嘗試-500或-700。這應該是比大多數進程更高的優先級,但不是任何正在運行的系統所必需的優先級。所以你應該使用:

oom score -500 

第二個問題是你正在使用start-stop-daemon。你應該拋棄它,因爲Upstart可以處理所有事情。因此,生成的腳本應該是這樣的:

description "bitcoind" 

start on filesystem 
stop on runlevel [!2345] 

oom score -500 
chdir /root/.bitcoin 

respawn 
respawn limit 10 60 # 10 times in 60 seconds 

exec /usr/bin/bitcoind 

的最後一個問題可能是你沒有正確定義normal exit。您需要指定哪些返回代碼和信號構成正常退出,以便Upstart知道如果信號和返回代碼不匹配則重新生成。請參閱Upstart食譜如何做到這一點:http://upstart.ubuntu.com/cookbook/#normal-exit

+0

謝謝!它適用於正常的「正常退出」和「期望」變量。 –

0

因此,爲了新貴腕錶的比特幣,然後重新啓動它,如果它落在我用

expect fork 

而且,我沒有使用start-stop-daemon的,只是運行比特幣與高管:

exec /path/to/bitcoind 

,並確定正常退出代碼(或代碼)

normal exit 0 15 

不要忘記很重要respawn和 respawn限制變量在你的upstart配置中。

4

所以我終於在Ubuntu 14.04服務器上工作了。下面是最終的,工作/etc/init/bitcoind.conf樣子:

description "bitcoind" 

start on filesystem 
stop on runlevel [!2345] 
oom score -500 
expect fork 
respawn 
respawn limit 10 60 # 10 times in 60 seconds 

script 
    user=bitcoind 
    home=/home/$user 
    cmd=$home/bin/bitcoind 
    pidfile=$home/bitcoind.pid 
    # Don't change anything below here unless you know what you're doing 
    [[ -e $pidfile && ! -d "/proc/$(cat $pidfile)" ]] && rm $pidfile 
    [[ -e $pidfile && "$(cat /proc/$(cat $pidfile)/cmdline)" != $cmd* ]] && rm $pidfile 
    exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile -m --startas $cmd 
end script 

一旦你添加/更新您的/etc/init/bitcoin.conf文件,一定要運行以下命令:

initctl reload-configuration 

基本上這只是很多猜測並檢查以使這最終工作。這裏的重要位:

expect fork 

本質上,這是告訴新貴目標進程將在啓動時分叉多少次。如果你說錯了,它會在開始時掛起。有關詳細信息,請閱讀here

此外,我已安裝/正在運行的用戶是bitcoind而不是root

你應該能夠手動啓動bitcoind作爲一種服務,就像這樣:

service bitcoind start 

或者阻止它,就像這樣:

service bitcoind stop 

如果重新啓動服務器時,bitcoind服務應自動啓動。而且,如果bitcoind進程死亡或崩潰,它會自動重新生成。您可以通過首先找到bitcoind進程的PID測試的那部分服務器上:

ps cax | grep bitcoind 

然後,殺手動過程:

kill -9 PID_OF_BITCOIND 

然後,嘗試得到bitcoind的PID再次處理:

ps cax | grep bitcoind 

它應該仍在運行,並帶有新的PID。