簡體   English   中英

比特幣重新生成功能的新貴腳本

[英]Upstart script for bitcoind, respawn feature

我有一個針對該比特幣的暴發戶腳本,它基於本主題中的腳本: https ://bitcointalk.org/index.php ? topic = 25518.0

我強烈需要重新產生以后的工作:如果發生某些情況,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

所以我終於在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

本質上,這是在告訴新貴,啟動時將分叉目標進程多少次。 如果輸入錯誤,它將在啟動時掛起。 在此處閱讀有關此內容的詳細信息。

另外,我已經在其下安裝/運行bitcoind的用戶是bitcoind而不是root

您應該能夠手動將bitcoind作為服務啟動,如下所示:

service bitcoind start

或像這樣停止它:

service bitcoind stop

如果重新啟動服務器,則應自動啟動bitcoind服務。 並且,如果比特幣進程被殺死或崩潰,它將自動重新生成。 您可以通過首先找到bitcoind進程的PID來在服務器上測試該部分:

ps cax | grep bitcoind

然后,手動終止該過程:

kill -9 PID_OF_BITCOIND

然后,嘗試再次獲取bitcoind進程的PID:

ps cax | grep bitcoind

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

oom never

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

oom score never

此外,除了關鍵系統服務外,切勿使用oom score。 請嘗試-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

因此,要讓新貴開始監視比特幣並在比特幣下跌時重新啟動它,

expect fork

另外,我沒有使用start-stop-daemon,而只是使用exec運行比特幣:

exec /path/to/bitcoind

定義正常的退出代碼(或代碼)很重要

normal exit 0 15

and variables in your upstart config. 不要忘記新貴的配置中的變量。

現在官方的比特幣項目有一個拉動請求,其中包括更好的新貴工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM