Monit无法确定比特币守护程序是否正在运行

我正在设置Monit来监视比特币守护进程,确保它运行24/7,并在出现问题时重新启动它。 比特币二进制文件位于/usr/local/bin/bitcoind ,数据目录位于/home/bitcoin/.bitcoin

我已经告诉/var/run/bitcoind.pid每隔2分钟通过pid文件/var/run/bitcoind.pid来监控守护进程,并以用户bitcoin开始/停止守护进程。 然而,这是我花了无数小时试图弄清楚什么是错的地方。

因为我没有bitcoind的启动脚本, bitcoind我直接将命令传递给二进制文件,这可以通过/etc/monit/monitrc文件来看到:

 set daemon 120 set logfile /var/log/monit.log check process bitcoind with pidfile "/var/run/bitcoind.pid" start program "/usr/local/bin/bitcoind -pid=/var/run/bitcoind.pid -datadir=/home/bitcoin/.bitcoin -daemon" as uid bitcoin and gid bitcoin stop program "/usr/local/bin/bitcoind stop" as uid bitcoin and gid bitcoin if failed port 8332 for 2 cycles then restart 

当系统初创时,我以用户bitcoinlogin并启动ps -u bitcoin 。 果然, bitcoind显示为在我的用户下运行。 但是,当我得到Monit通过not monitored monit status显示monit status ,响应首先显示为execution failed ,然后not monitored

我检查了/var/run/ while bitcoind正在运行,发现没有名为bitcoind.pid文件,这让我认为bitcoind没有足够的权限在/var/run创build一个pid文件而作为用户bitcoin运行。

对于另一种解决scheme,我将pid文件保留在默认位置( /home/bitcoin/.bitcoin/bitcoind.pid )中,但是root无法访问它,这也导致了相同的结果。

/var/log/monit.log文件没有提供有用的信息,所以有我试过的'包装'。

这一切都可以通过运行bitcoind作为root解决,但我担心安全问题。

您猜测bitcoin用户将无权写入/var/run ,但是root可以读取/home/bitcoin/.bitcoin/bitcoind.pid 。 我将把PID留在后面的位置,然后进一步研究为什么monit不会读取第二个位置。 我敢打赌,这将是monitconfigurationpath中的一个错字。