user7114: I've got a bunch of other services set up to boot automatically when my Ubuntu server starts (services like wicd-daemon and VPN), but I can't figure out how to set up the bitcoin daemon (bitcoind) to start automatically when the system boots up. (This is on a headless system with no GUI or attached monitor.)
I'm trying to learn how to integrate bitcoin with Python so I can write bitcoin-enabled services, but I want the system to automatically start bitcoind when the system boots so that I don't have to do it manually. (It's a pain in the butt to have to download a whole bunch of block-chain at once. It eats away at uptime.)
If this question has already been asked, please direct me to the answer. I searched but couldn't find it. Otherwise, please help me figure this out!
Thanks so much.

user4708: This seems to be your answer: https://bitcointalk.org/index.php?topic=25518.0

user11015: I've never run it before. You said that bitcoind is a daemon, so here how to configure a daemon to run at startup : 
Normally a daemon has its init script in /etc/init.d/ directory.
sudo /etc/init.d/bitcoind start

If the daemon needs to be initialized at startup, then it will be linked in /etc/rc0.d/ or /etc/rc1.d/ or ... /etc/rc6.d/ ... etc
0 -> 6 are runlevels :
0 - Halt
1 - Single User Mode
2 - Multiuser
3 - Full Multiuser Mode
4 - unused
5 - Full Multiuser Mode with x11
6 - Reboot

you can also add the script that your daemon runs in 
/etc/rc.local

If it is a python script you can write to that file :
python /directory/to/init/script/bitcoind.py

Another alternative is to execute update-rc.d :
sudo update-rc.d bitcoind defaults

defaults , will tells update-rc.d to run a default configuration, when it comes to runlevel . You can change your runlevel, this is an exampl : 
update-rc.d bitcoind start 20 2 3 4 5 . stop 20 0 1 6

run man update-rc.d , there are other examples .
To remove it from startup, run :
sudo update-rc.d bitcoind remove


user60004: I finally end up with this setting for my raspberry
nano /etc/systemd/system/bitcoind.service

content of the file bitcoind.service
[Unit]
Description=bitcoin
After=network.target

[Service]
Type=forking
User=pi
Group=pi

Environment=BITCOIN_PID=/home/pi/.bitcoin/bitcoin.pid
Environment=BITCOIN_HOME=/home/pi/.bitcoin

ExecStart=/usr/local/bin/bitcoind
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

Reload systemctl daemon
systemctl daemon-reload

Enabled new bitcoind service
systemctl enable bitcoind

Commands to start or stop the service
systemctl stop bitcoind
systemctl start bitcoind

Show service status
systemctl status bitcoind.service  

More info in https://github.com/bitcoin/bitcoin/tree/master/contrib/init 
thanks for the help Janus Troelsen
Update
Don't put arguments since I have considered that there is a configuration in 
/home/pi/.bitcoin/bitcoin.conf


user21052: There's an upstart script for Ubuntu in the Bitcoin Core source tree.  Using that is the most correct way.
However, I just login as the user account I want to run Bitcoin Core daemon, start a terminal (if I'm in the GUI), and run the following command to edit my crontab:
crontab -e

Then I add the following line:
@reboot bitcoind -daemon

Save the file and exit.  Now every time the computer boots up, Bitcoin Core daemon will be started.  On shutdown, init/upstart/systemd/whatever will send it a SIGTERM signal, which bitcoind will catch and interpret as the command to start a safe shutdown.

user11084: EDIT: Caveat emptor on Ubuntu distributions from 14.10 and forward - init was chosen over upstart and is being phased in the future. I don't know when that will be done nor what impact it will have on upstart scripts.
Extract from the page RentFree refers to; note that it assumes that you have created a user called bitcoinuser for the sake of security:

For those running ubuntu, you may be familiar with upstart, a replacement for sysvinit style booting (/etc/init.d/*).
Configuration files for upstart are stored under /etc/init/*.conf. I've written the following one for bitcoind:
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=bitcoinuser
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 --startas $cmd -b -m
end script

Put the above configuration in /etc/init/bitcoind.conf, then run sudo initctl reload-configuration. To start bitcoind, run sudo start bitcoind. To stop bitcoind, run sudo stop bitcoind.
You'll probably want to change the user, cmd and pidfile to something that matches your configuration, or you can use the following as a template:
/home/bitcoinuser
/home/bitcoinuser/bitcoind.pid
/home/bitcoinuser/bin/bitcoind


Though one user suggests the following correction to the configuration:

home=/home/$user
cmd=/usr/bin/bitcoind
pidfile=$home/.bitcoin/bitcoind.pid


and another suggests setting nice for the process so it doesn't hog the CPU

exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile --startas $cmd -b --nicelevel 15 -m



7114: <p>I've got a bunch of other services set up to boot automatically when my Ubuntu server starts (services like wicd-daemon and VPN), but I can't figure out how to set up the bitcoin daemon (bitcoind) to start automatically when the system boots up. (This is on a headless system with no GUI or attached monitor.)</p>

<p>I'm trying to learn how to integrate bitcoin with Python so I can write bitcoin-enabled services, but I want the system to automatically start bitcoind when the system boots so that I don't have to do it manually. (It's a pain in the butt to have to download a whole bunch of block-chain at once. It eats away at uptime.)</p>

<p>If this question has already been asked, please direct me to the answer. I searched but couldn't find it. Otherwise, please help me figure this out!</p>

<p>Thanks so much.</p>
 4708: <p>This seems to be your answer: <a href="https://bitcointalk.org/index.php?topic=25518.0" rel="nofollow">https://bitcointalk.org/index.php?topic=25518.0</a></p>
 11015: <p>I've never run it before. You said that bitcoind is a daemon, so here how to configure a daemon to run at startup : </p>

<p>Normally a daemon has its init script in <code>/etc/init.d/</code> directory.</p>

<pre><code>sudo /etc/init.d/bitcoind start
</code></pre>

<p>If the daemon needs to be initialized at startup, then it will be linked in <code>/etc/rc0.d/</code> or <code>/etc/rc1.d/</code> or ... <code>/etc/rc6.d/</code> ... etc</p>

<p>0 -> 6 are runlevels :</p>

<pre><code>0 - Halt
1 - Single User Mode
2 - Multiuser
3 - Full Multiuser Mode
4 - unused
5 - Full Multiuser Mode with x11
6 - Reboot
</code></pre>

<p>you can also add the script that your daemon runs in </p>

<pre><code>/etc/rc.local
</code></pre>

<p>If it is a python script you can write to that file :</p>

<pre><code>python /directory/to/init/script/bitcoind.py
</code></pre>

<p>Another alternative is to execute <code>update-rc.d</code> :</p>

<pre><code>sudo update-rc.d bitcoind defaults
</code></pre>

<p><code>defaults</code> , will tells <code>update-rc.d</code> to run a default configuration, when it comes to runlevel . You can change your runlevel, this is an exampl : </p>

<pre><code>update-rc.d bitcoind start 20 2 3 4 5 . stop 20 0 1 6
</code></pre>

<p>run <code>man update-rc.d</code> , there are other examples .</p>

<p>To remove it from startup, run :</p>

<pre><code>sudo update-rc.d bitcoind remove
</code></pre>
 60004: <p>I finally end up with this setting for my raspberry</p>

<pre><code>nano /etc/systemd/system/bitcoind.service
</code></pre>

<p>content of the file <code>bitcoind.service</code></p>

<pre><code>[Unit]
Description=bitcoin
After=network.target

[Service]
Type=forking
User=pi
Group=pi

Environment=BITCOIN_PID=/home/pi/.bitcoin/bitcoin.pid
Environment=BITCOIN_HOME=/home/pi/.bitcoin

ExecStart=/usr/local/bin/bitcoind
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target
</code></pre>

<p>Reload systemctl daemon</p>

<pre><code>systemctl daemon-reload
</code></pre>

<p>Enabled new bitcoind service</p>

<pre><code>systemctl enable bitcoind
</code></pre>

<p>Commands to start or stop the service</p>

<pre><code>systemctl stop bitcoind
systemctl start bitcoind
</code></pre>

<p>Show service status</p>

<pre><code>systemctl status bitcoind.service  
</code></pre>

<p>More info in <a href="https://github.com/bitcoin/bitcoin/tree/master/contrib/init" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/tree/master/contrib/init</a> </p>

<p>thanks for the help Janus Troelsen</p>

<p><strong>Update</strong></p>

<p>Don't put arguments since I have considered that there is a configuration in </p>

<pre><code>/home/pi/.bitcoin/bitcoin.conf
</code></pre>
 21052: <p>There's an <a href="https://github.com/bitcoin/bitcoin/blob/2d782ab2ce30bf106e34cd3288c9082ac04022f9/contrib/init/bitcoind.conf" rel="noreferrer">upstart script for Ubuntu</a> in the Bitcoin Core source tree.  Using that is the most correct way.</p>

<p>However, I just login as the user account I want to run Bitcoin Core daemon, start a terminal (if I'm in the GUI), and run the following command to edit my crontab:</p>

<pre><code>crontab -e
</code></pre>

<p>Then I add the following line:</p>

<pre><code>@reboot bitcoind -daemon
</code></pre>

<p>Save the file and exit.  Now every time the computer boots up, Bitcoin Core daemon will be started.  On shutdown, init/upstart/systemd/whatever will send it a SIGTERM signal, which bitcoind will catch and interpret as the command to start a safe shutdown.</p>
 11084: <p><strong>EDIT</strong>: Caveat emptor on Ubuntu distributions from 14.10 and forward - <a href="http://www.markshuttleworth.com/archives/1316" rel="noreferrer"><code>init</code> was chosen over <code>upstart</code> and is being phased in the future</a>. I don't know when that will be done nor what impact it will have on upstart scripts.</p>
<p><a href="https://bitcointalk.org/index.php?topic=25518.0" rel="noreferrer">Extract from the page RentFree refers to</a>; note that it assumes that you have created a user called <code>bitcoinuser</code> for the sake of security:</p>
<blockquote>
<p>For those running ubuntu, you may be familiar with <a href="http://upstart.ubuntu.com/" rel="noreferrer">upstart</a>, a replacement for <code>sysvinit</code> style booting (<code>/etc/init.d/*</code>).</p>
<p>Configuration files for upstart are stored under <code>/etc/init/*.conf</code>. I've written the following one for bitcoind:</p>
<pre><code>description &quot;bitcoind&quot;

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

script
user=bitcoinuser
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 &amp;&amp; ! -d &quot;/proc/$(cat $pidfile)&quot; ]] &amp;&amp; rm $pidfile
[[ -e $pidfile &amp;&amp; &quot;$(cat /proc/$(cat $pidfile)/cmdline)&quot; != $cmd* ]] &amp;&amp; rm $pidfile
exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile --startas $cmd -b -m
end script
</code></pre>
<p>Put the above configuration in <code>/etc/init/bitcoind.conf</code>, then run <code>sudo initctl reload-configuration</code>. To start <code>bitcoind</code>, run <code>sudo start bitcoind</code>. To stop <code>bitcoind</code>, run <code>sudo stop bitcoind</code>.</p>
<p>You'll probably want to change the <strong>user</strong>, <strong>cmd</strong> and <strong>pidfile</strong> to something that matches your configuration, or you can use the following as a template:</p>
<pre><code>/home/bitcoinuser
/home/bitcoinuser/bitcoind.pid
/home/bitcoinuser/bin/bitcoind
</code></pre>
</blockquote>
<p>Though one user suggests the following correction to the configuration:</p>
<blockquote>
<pre><code>home=/home/$user
cmd=/usr/bin/bitcoind
pidfile=$home/.bitcoin/bitcoind.pid
</code></pre>
</blockquote>
<p>and another suggests setting <code>nice</code> for the process so it doesn't hog the CPU</p>
<blockquote>
<pre><code>exec start-stop-daemon --start -c $user --chdir $home --pidfile $pidfile --startas $cmd -b --nicelevel 15 -m
</code></pre>
</blockquote>
