Run syncthing as Service instead of user [macOS]

Hi team,

So I’m trying to run syncthing on MacOS as a service. So that it will be synchronising even when the mac is on the login screen. This because I’m synchronising folders of 100gb, 200gb, 300gb and 600gb depending on the folder the client uses for it’s operational work.

These clients are no always manned but I’d still want them to sync even when the user is not logged in yet. For some annoying policies I had to turn off display after 25minutes and 5 more minutes later it’ll logout the user.

I tried to use the GitHub - syncthing/syncthing: Open Source Continuous File Synchronization instead of the gui, and use the plist as a LaunchDaemon instead of LaunchAgent of the system. But then syncthing is not able to launch as the SIP is holding it back.

Is there any documentation I can follow?

None that I’m aware of, and running things outside of a login session is a bit of a pain in the ass. In principle it should work if dropped in /Library/LaunchDaemons.

1 Like

As far as I know the macOS service for daemons is launchd and indeed when dropped in system wide /Library/LaunchDaemons should work. Then you need to use launchctl to manage the daemon service.

I found this on SO: https://superuser.com/questions/82955/how-to-load-system-wide-daemon-on-mac-os-x

I’m not sure how this works because you don’t want to run the syncthing daemon as root user. And create a specific syncthing user on the system and give it the correct permission. So syncthing is unable to screw up the system.

You put the plist into /Library/LaunchDaemons but edit it to say which user the script will run as

The key you need to add is UserName. For example I run a newserver as user _news

<key>UserName</key>
<string>_news</string>

launchd.plist(5) [osx man page]

Original source macos - How to load system-wide daemon on Mac OS X - Super User

1 Like

Thanks for the replies!

So to be more complete on my situation, I already had syncthing installed on clients, but due to security reasons I had to make the machines logout after X minutes.

BUT I still need to folders to be synced whenever needed.

I needed to make some changes, and thanks to @jerryjacobs also used the UserName entry. And for some reason it doesn’t like the log paths, unfortunately… Might need some more research in that, it didn’t even like the /tmp/ folder… For now this is my syncthing.plist in /Library/LaunchDaemons/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>Label</key>
		<string>net.syncthing.syncthing</string>
		
		<key>UserName</key>
		<string>myUser</strong>

		<key>ProgramArguments</key>
		<array>	<string>/Applications/Syncthing.app/Contents/Resources/syncthing/syncthing</string>
		</array>
		
		<key>KeepAlive</key>
		<true/>

		<key>LowPriorityIO</key>
		<true/>

		<key>ProcessType</key>
		<string>Background</string>
	</dict>
</plist>

Loaded it as admin:

#sudo launchctl load /Library/LaunchDaemons/syncthing.plist
#sudo launchctl start /Library/LaunchDaemons/syncthing.plist

And all the magic happens even on login screen, on the actual user itself (within personal folders), even when display is turned off.

*** Ofcourse this won’t be working for multiple local user folders

Can’t edit, but for some reason the logs now do work.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>Label</key>
		<string>net.syncthing.syncthing</string>
		
		<key>UserName</key>
		<string>myUser</strong>

		<key>ProgramArguments</key>
		<array>	<string>/Applications/Syncthing.app/Contents/Resources/syncthing/syncthing</string>
		</array>
		
		<key>KeepAlive</key>
		<true/>

		<key>LowPriorityIO</key>
		<true/>

		<key>ProcessType</key>
		<string>Background</string>

		<key>StandardErrorPath</key>
		<string>/tmp/syncthing.log</string>
		<key>StandardOutPath</key>
		<string>/tmp/syncthing-error.log</string> 
	</dict>
</plist>

I think you have swapped the error and normal log. StandardErrorPath should probably point to /tmp/syncthing-error.log

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.