Keeping Syncthing Running: Upstart


(Joel Moberg) #1

Here is one for upstart (ubuntu and others):

description "Syncthing P2P sync service"

start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env STNORESTART=yes
env HOME=/home/joelmo
setuid "joelmo"
setgid "joelmo"

exec /usr/local/bin/syncthing

respawn

This service will start when your computer starts, start directly with initctl start syncthing.


Keeping Syncthing Running: Systemd & regular /etc/init.d
Keeping Syncthing Running: Ubuntu / Upstart
Keeping Syncthing Running: Ubuntu / Upstart
(Stuart Langridge) #2

@joelmo: you’ll want to set STNORESTART in the environment if upstart is managing syncthing. Above I gave an upstart conf file which is run as the user, rather than your one which needs you to be root to run it; each user gets their own private upstart to run commands, which I prefer if you’re going to run a user-specific thing like syncthing.


(Joel Moberg) #3

If you have start on start-desktop you need some desktop installed? I want ST to start up after the system and network have booted up. I have this config at my server. Ok thanks I edited.


(Hackinjack) #4

Since RHEL based distros are almost always behind the Debian/Ubuntu in terms of component versions, you will find that this doesn’t work on RHEL or CentOS 6 variants as the current version of upstart (at time of writing) doesn’t support setuid/setgid. However it can be made to work with upstart with the following mods (just put the userid you want it run as in there). I’ve also diverted the logging output to a file as per RH convention:


# /etc/init/syncthing.conf start on (local-filesystems and net-device-up IFACE!=lo) stop on runlevel [!2345] env STNORESTART=yes env USERID='nonrootuser’ env HOME=/home/$USERID # setuid “nonrootuser” # setgid "nonrootuser" script exec 1>>/var/log/syncthing.log 2>&1 su - $USERID -c '/usr/local/bin/syncthing’ end script respawn

Hope this helps someone.


(system) #5