Run Script at Start on Debian/Ubuntu
July 3, 2013
Updated: Dec 12, 2015
Determine Init System
Newer installs use systemd as the init system, which has a newer and more
consisten way to manage services. There was a lot of linux drama around this
change, my guess mostly due to "cheese moving" and having to learn something
new.
You can determine if your system is running systemd using: $ ps -p1
Start Daemon on System boot
The main reason I need this script is becaues BitTorrent Sync is not distributed as an Ubuntu package with necessary start scripts. Also, btsync needs to run as the user, which I often forget. First create the service file which describes how to start and information about the service.
Saved to: /etc/systemd/user/btsync.service
[Unit]
Description=BitTorrent Sync Service
[Service]
Type=forking
User=mkaz
ExecStart=/home/mkaz/bin/btsync --config /home/mkaz/.btsync.conf
[Install]
WantedBy=multi-user.target
Enable
sudo systemctl enable /etc/systemd/user/btsync.service
Start
sudo systemctl start btsync.service
That's it, it should be running now and each time you start. You can test by rebooting and confirming it works. The above is not ideal for multi-user servers, since I'm hardcoding everything to my user, adjust to your needs.
Extra
There is a lot more information available around systemd and a lot more
configuration available for example to execute a command before start, or other
dependencies.
Getting Started with systemd on Debian Jessie - a good overview with more
details on using systemdSystemd for Upstart Users - Upstart was the previous system used by Ubuntu for starting scripts, this guide shows the differences between the two
Systemd Unit Files - RedHat Administrators Guide to Systemd service files, explains differences between older SysV Init system