Skip to content

Instantly share code, notes, and snippets.

@devster31
Created May 4, 2015 00:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/dc2888c49d2ed522d68a to your computer and use it in GitHub Desktop.
Save devster31/dc2888c49d2ed522d68a to your computer and use it in GitHub Desktop.
systemd units for syncthing OSX and unix

Mac OS X

Using homebrew

  1. brew install syncthing
  2. Follow the info to autostart syncthing using launchctl. At the moment this is done using this command: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.syncthing.plist.

Without homebrew

Download syncthing for Mac: https://github.com/syncthing/syncthing/releases/latest.

  1. Copy the syncthing binary (the file you would open to launch syncthing) in a directory called bin in your home directory. If "bin" does not exist, create it.
  2. Edit the syncthing.plist (located in /etc/macosx-launchd) in the two places that refer to your home directory; that is, replace /Users/jb with your actual home directory location.
  3. Copy the syncthing.plist file to ~/Library/LaunchAgents. If you have trouble finding this location select the "Go" menu in Finder and choose "Go to folder..." and then type ~/Library/LaunchAgents. Copying to ~/Library/LaunchAgents will require admin password in most cases.
  4. Log out and back in again. Or, if you do not want to log out, you can run this command in terminal: launchctl load ~/Library/LaunchAgents/syncthing.plist

Note: You probably want to turn off "Start Browser" in the web GUI settings to avoid it opening a browser window on each login. Then, to access the GUI type 127.0.0.1:8384 (by default) into Safari.

Linux

Ubuntu like systems

  1. Click the dashboard (hit 'Win' button).
  2. Open 'Startup Applications'.
  3. Click 'Add'.
  4. Fill out the form:
    • Name: Syncthing
    • Command: /path/to/syncthing/binary -no-browser -home="/home/your_user/.config/syncthing"

Supervisord

Add following to your /etc/supervisord.conf.

[program:syncthing]
command = /path/to/syncthing/binary -no-browser -home="/home/some_user/.config/syncthing"
directory = /home/some_user/
autorestart = True
user = some_user

systemd

systemd is a suite of system management daemons, libraries, and utilities designed as a central management and configuration platform for the Linux computer operating system. It also offers users the ability to manage services under the user's control with a per-user systemd instance, enabling users to start, stop, enable, and disable their own units. Service files for system are provided by syncthing and can be found in etc/linux-systemd. Several distros (including arch linux) ship these service files with the syncthing package. If your distro provides a systemd service file for syncthing you can skip step 2.

How to use the system instance

Running synchting as a system service ensures that syncthing is run at startup even if the syncthing user has no active session.

  1. Create the user who should run the service, or choose an existing one.
  2. Copy the system/syncthing@.service file into the load path of the system instance.
  3. Enable and start the service. Append the syncthing user after the @:
systemctl enable syncthing@myuser.service
systemctl start syncthing@myuser.service

How to use the user instance

Running synchting as a user service ensures that syncthing is run after the syncthing user has created a session (e.g. via the graphical login screen or ssh). This could be used e.g. on a multiuser desktop computer when you want to avoid unnecessarly running syncthing instances.

  1. Create the user who should run the service, or choose an existing one.
  2. Copy the user/syncthing.service file into the load path of the user instance. To do this without root privileges you can use ~/.config/systemd/user/.
  3. Enable and start the service:
systemctl --user enable syncthing.service
systemctl --user start syncthing.service

To check if syncthing runs properly you can use the status subcommand:

systemctl status syncthing@myuser.service
systemctl --user status syncthing.service

Using the journal

Systemd logs everything into the journal. You can easily acces syncthing log messages (-e lets the pager jump to the very end):

journalctl -e -u syncthing@myuser.service
journalctl -e --user-unit=syncthing.service

Debugging

If you are asked on the bugtracker to start syncthing with specific environment variables it will not work the easy way. Systemd isolates each service and it cannot access global environment variables. The solution is to add this variables to the service file instead. Just use:

systemctl edit syncthing@myuser.service  
systemctl --user edit syncthing.service

This will create an additional configuration file automatically and you can define (or overwrite) further service parameters like e.g. Environment=STTRACE=model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment