<p>I'm running a RaspberryPi Bitcoin node. Since I discovered that the node had sometimes crashed due to overload, I put an hourly starting command into crontab:</p>

<pre><code>@hourly &lt;completePath&gt;/bitcoind -daemon -disablewallet
</code></pre>

<p>If <code>bitcoind</code> is already running, it fails to start due to not getting a lock on the data directory. Otherwise, the server will be restarted with at most one hour of downtime.</p>

<p>I'm sure there are more elegant solutions, but I didn't explore it much further as this worked for me.</p>

CC BY-SA 3.0
2015-11-16T23:53:28.820Z
2016-01-02T12:16:50.643Z
2016-01-02T12:16:50.643Z
Murch
<p>Add this to your <code>/etc/inittab</code>:</p>

<pre><code>bd:1234:respawn:sudo -u &lt;USERNAME_TO_RUN_bitcoind&gt; &lt;DIRECTORY_CONTAINING_bitcoind&gt;/bitcoind
</code></pre>

<p>Then run</p>

<pre><code>telinit q
</code></pre>

<p>to rescan the <code>inittab</code> file.</p>

<p>Change everything in the &lt;> in the above example to suite your case. Make sure the first two letters ("bd" for <strong>b</strong>itcoin<strong>d</strong> in the above example) are unique; you can make them any two letters, as long as nothing else in the <code>inittab</code> uses them.</p>

<p>This will make it so <code>bitcoind</code> restarts immediately after it crashes.</p>

<p>cf. <code>man inittab</code> for more info.</p>

CC BY-SA 3.0
2016-07-30T18:54:28.857Z
2016-07-30T18:54:28.857Z
Geremia
<p>On Ubuntu 14.04 I have not been able to get the Bitcoin daemon to automatically restart. Rarely the daemon dies and it is important that it starts again without manual intervention. To get it to start automatically with Upstart I have followed the guide linked below. It starts with <code>sudo start bitcoind</code> as expected but the service does not restart if it fails.</p>

<p><a href="https://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automatically">Ubuntu Linux — How do I start bitcoind as a service to run automatically?</a></p>

<p>My conf file in /etc/init/ is as follows.</p>

<pre><code>description "bitcoind"

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

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

<p>If I run <code>ps -aux | grep bitcoind</code> to get the process ID and kill it the daemon does not restart as desired. I have followed the guide and cannot see what is wrong with the set up. As a side note <code>sudo stop bitcoind</code> does not actually stop it from running.</p>

<p>Any help on this would be appreciated.</p>

CC BY-SA 3.0
2015-11-13T13:40:54.343Z
I'm not that well versed in Linux myself, but you should be able to run Bitcoind with regular user rights. Why do you use `sudo start bitcoind`?

My Bitcoin Node on a RaspberryPi had been crashing every once in a while from overload, so I had just put a command in a cron job that tries to start it every hour. If its already running, no problem. If it wasn't it is down no more than an hour.
Murch
CC BY-SA 3.0
2015-11-13T13:58:56.213Z
Starting as a normal user I get the following error `start: Rejected send message, 1 matched rules; type="method_call", sender=":1.13" (uid=1002 pid=5367 comm="start bitcoind ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")`
Peter Bushnell
CC BY-SA 3.0
2015-11-13T14:15:18.933Z
Sorry, I'm not familiar with the script you're using. I meant, I have installed Bitcoin with a regular account and then could start it using `bitcoind`, I didn't think that it would need to run with admin rights. But perhaps you need it because you are running it from another user account? Sorry that I'm not able to help, but I really don't know too much about Linux.
Murch
CC BY-SA 3.0
2015-11-13T14:26:44.040Z
Looks like he is running bitcoind as a normal user (bitcoinuser), he only uses the `start` command as root to trigger the service to start. (I'm not familiar with the latest Ubuntu, the more common command in linux would be `service bitcoind start` ). Murch's crontab suggestion is probably easiest.
Jannes
CC BY-SA 3.0
2015-11-13T16:11:51.900Z
I agree. This is not working for me and I've spent far too much time working on this when a simple cron job would work. So that is what I am going to do, thanks for the suggestion Murch.
Peter Bushnell
CC BY-SA 3.0
2015-11-16T23:43:56.487Z
Alright, I'll put it as an answer.
Murch
<server><daemon>
Automatically restart bitcoind on crash
Peter Bushnell
# Automatically restart bitcoind on crash

(Asked by: username_0 on 2015-11-13)

On Ubuntu 14.04 I have not been able to get the Bitcoin daemon to automatically restart. Rarely the daemon dies and it is important that it starts again without manual intervention. To get it to start automatically with Upstart I have followed the guide linked below. It starts with `sudo start bitcoind` as expected but the service does not restart if it fails.

[Ubuntu Linux — How do I start bitcoind as a service to run automatically?](https://bitcoin.stackexchange.com/questions/13795/ubuntu-linux-how-do-i-start-bitcoind-as-a-service-to-run-automatically)

My conf file in /etc/init/ is as follows.

```
description "bitcoind"

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

script
user=bitcoinuser
home=/home/$user
cmd=/usr/bin/bitcoind
pidfile=$home/.bitcoin/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 --nicelevel 15 -m
end script

```

If I run `ps -aux | grep bitcoind` to get the process ID and kill it the daemon does not restart as desired. I have followed the guide and cannot see what is wrong with the set up. As a side note `sudo stop bitcoind` does not actually stop it from running.

Any help on this would be appreciated.

**Tags:** server, daemon

> **Comments:**
> **username_1**: I'm not that well versed in Linux myself, but you should be able to run Bitcoind with regular user rights. Why do you use `sudo start bitcoind`?  My Bitcoin Node on a RaspberryPi had been crashing every once in a while from overload, so I had just put a command in a cron job that tries to start it every hour. If its already running, no problem. If it wasn't it is down no more than an hour.  
> **username_0**: Starting as a normal user I get the following error `start: Rejected send message, 1 matched rules; type="method_call", sender=":1.13" (uid=1002 pid=5367 comm="start bitcoind ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")`  
> **username_1**: Sorry, I'm not familiar with the script you're using. I meant, I have installed Bitcoin with a regular account and then could start it using `bitcoind`, I didn't think that it would need to run with admin rights. But perhaps you need it because you are running it from another user account? Sorry that I'm not able to help, but I really don't know too much about Linux.  
> **username_2**: Looks like he is running bitcoind as a normal user (bitcoinuser), he only uses the `start` command as root to trigger the service to start. (I'm not familiar with the latest Ubuntu, the more common command in linux would be `service bitcoind start` ). username_1's crontab suggestion is probably easiest.  
> **username_0**: I agree. This is not working for me and I've spent far too much time working on this when a simple cron job would work. So that is what I am going to do, thanks for the suggestion username_1.  
> **username_1**: Alright, I'll put it as an answer.  

---

## 2 answers

### Answer by username_1 on 2015-11-16. Score: 1

I'm running a RaspberryPi Bitcoin node. Since I discovered that the node had sometimes crashed due to overload, I put an hourly starting command into crontab:

```
@hourly <completePath>/bitcoind -daemon -disablewallet

```

If `bitcoind` is already running, it fails to start due to not getting a lock on the data directory. Otherwise, the server will be restarted with at most one hour of downtime.

I'm sure there are more elegant solutions, but I didn't explore it much further as this worked for me.


---

### Answer by username_3 on 2016-07-30. Score: 0

Add this to your `/etc/inittab`:

```
bd:1234:respawn:sudo -u <USERNAME_TO_RUN_bitcoind> <DIRECTORY_CONTAINING_bitcoind>/bitcoind

```

Then run

```
telinit q

```

to rescan the `inittab` file.

Change everything in the <> in the above example to suite your case. Make sure the first two letters ("bd" for **b**itcoin**d** in the above example) are unique; you can make them any two letters, as long as nothing else in the `inittab` uses them.

This will make it so `bitcoind` restarts immediately after it crashes.

cf. `man inittab` for more info.


---

