Start syncthing in background without shell window / as a Windows service

While exploring the Syncthing Wiki I came across the following which seems to promise what is asked for here: Syncthing Tray. I will give it a try…

2 Likes

Another option, which is what I did for my wife’s computer, is to use nssm to make a little service.

1 Like

Great tool, thanks for mentioning it! They should merge it with Syncthing at some point …

Are there any updates on this? I could do testing (windows 7) since I need something like this.

I would also be interested in testing this. I would also like to test and report back

Hi, I had a lot of difficulties to create a service but I managed to do it with nssm. I made the following:

  • create a directory with syncthing.exe and nssm.exe ([http://nssm.cc/download][1]) for example in C:\Program Files\SyncThing

  • create a file name install.bat and type into it with notepad:

    nssm install SyncThing “%CD%\syncthing.exe” -home “”"%CD%\config""" Pause

  • [optional] If you want to keep your parameter, copy the directory %AppData%/Syncthing into the directory you have selected in the first step /config (ex: C:\Program Files\SyncThing\config)

  • restart your computer and visit http://127.0.0.1:8080/

  • To uninstall: nssm remove SyncThing [1]: http://nssm.cc/download

3 Likes

:thumbsup: for now I just followed your recommendations and what should I say works well

I followed this approach, because it seemed much cleaner than the scheduled task method. For 1 pc this worked fine, but for the other 2, although the program is running and communicates with the other nodes, the web gui just hangs, waiting for 127.0.0.1:8080 to respond. Any ideas welcome. All pcs w7 pro, 2 are 64bit, 1 is 32.

This sounds for me more like a firewall problem, have you tried to turn off you firewalls and check then the web gui?

It seems more like a https/tls security issue. I had gui authorisation on, but tls off. I could access the gui by changing the security to “tls on” in config.xml , and then fighting my way through the Chrome warnings about dodgy security. Then I deleted gui authorisation and turned off https in settings and everything worked afterwards. Even after a restart.

This sounds indeed not like a firewall problem. The only thing I can thought of is that’s maybe not possible to use BASIC AUTH without SSL. But this is just a wild guess.

Thanks SouSouleBarbu. Extending your work I have written the following PowerShell script to download & install Syncthing as a service using nssm (and chocolatey). Its a bit rough & not tested that much. But I thought I would share in case it helps someone.

# Download SyncThing. Use nssm to install as a service.

# Download SyncThing
$URL = 'https://github.com/syncthing/syncthing/releases/download/v0.10.3/syncthing-windows-amd64-v0.10.3.zip'
Write-Host "Downloading SyncThing `r`n"
$FileName = $URL.Split('/')[-1] 
$ScriptFolder = Split-Path $MyInvocation.MyCommand.Path 
$DestinationPath = "$ScriptFolder\$FileName"
if ($PSVersionTable.PSVersion.Major -gt 2) {
	Invoke-WebRequest $URL -OutFile $DestinationPath
}
else {
	Write-Host "Downloading $FileName..."
	$Client = New-Object "System.Net.WebClient"
	$Client.DownloadFile($URL,$DestinationPath)
}

# Install Chocolatey
iex ((new-object net.webclient).DownloadString("https://chocolatey.org/install.ps1"));

# Install 7-zip
cinst 7zip
cinst 7zip.commandline

# Install nssm
cinst nssm

# Unzip SyncThing executable
$7Zexe = "$env:ProgramFiles\7-Zip\7z.exe"
if (-not (test-path $7Zexe)) {Write-Error "$7Zexe is missing!"; exit}
& $7Zexe e -y $DestinationPath

# Put SyncThing executable in Program Files
$SyncthingBaseName = "syncthing"
$ServiceName = $SyncthingBaseName
$Service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if($Service) {
	if($Service.Status -ne 'Stopped') {nssm stop $ServiceName}
	Start-Sleep -Seconds 2
	nssm remove $ServiceName confirm
	Start-Sleep -Seconds 2
}

$Folder = "$env:ProgramFiles\$SyncthingBaseName"
New-Item -ItemType Directory $Folder -ErrorAction SilentlyContinue
$ExecutableName = "$SyncthingBaseName.exe"
Copy-Item "$ScriptFolder\$ExecutableName" "$Folder\" -Force

# Install as service
$ConfigurationFolder = "$env:ProgramData\$SyncthingBaseName"
New-Item -ItemType Directory $ConfigurationFolder -ErrorAction SilentlyContinue

$LogFile = "$ConfigurationFolder\$SyncthingBaseName.log"
nssm install $ServiceName "$Folder\$ExecutableName" -home $ConfigurationFolder -no-browser -logfile $LogFile
Start-Sleep -Seconds 2
nssm start $ServiceName

# Open Web GUI
Start-Sleep -Seconds 15
start 'http://localhost:8080'

An easy way to run the above is save it in a file called InstallSyncThingAsService.ps1. Then create a batch file in the same folder with the following contents, save it, & run it as administrator.

cd /D %~dp0
powershell -executionpolicy unrestricted -command ".\InstallSyncThingAsService.ps1"
1 Like

Having a lot of trouble with this.

Win7 Pro 64 and 32 bit versions/nssm/syncthing v10.2 and higher:

If I accept the upgrade, the system stalls and won’t restart. The service is “paused”. If I stop and restart it, or even uninstall and reinstall it, it goes into this “paused” state. And now I have lost the config in the process. What is the recommended way of running Syncthing as a service in Windows, and can it be packaged for installation in this way? Seems like a good product otherwise.

Marmite.

Rather than integration this platform-specific functionality into windows, wouldn’t it be better to run it as a service using window’s equivalent of systemd/launchd/rc.d?

Exactly what’s the issue when trying to run it as a native system service? (I appologize for my ignorance, but some quick searching failed to yield if this fails, or why).

I belive Pulse can lose a lot of users if this is not included in an installer for Windows… Most Windows users won’t want to go through this procedure.

You can compile the software not to show the console window, but it’s up to you. There is SyncthingTray which already does this, so I don’t see why this should be a responsibility of this piece of software.

Whoever writes an installer for Windows can make sure the Window does not show up.

If syncthing is not distributed to Windows users as an installer package which makes it run automatically at startup, without a console, it will never gain any traction in that market. I am relatively computer literate compared to most windows users, and I gave up trying to use nssm to register syncthing because it failed after 10.2. I would like to use syncthing, but for now I am a BTSync user because it installs easily and works (mostly).

If syncthing can be packaged as above it would be one step ahead of BTSync which requires a user to log on before it will start up, which looks like being a feature only available in the (not yet released) paid for version.

1 Like

I think someone is working on the packaging from what I saw on github… Perhaps that will install it as a service…

For now, as I’ve said, you can use SyncthingTray which hides the Window. If you want it to run before logon, install it as a service, google around how to do it.

I don’t think our goal is to gain traction in the market, by the end of the day, as far as I am aware nobody is getting paid working on this so not sure how much of the work I do is about gaining traction, it’s probably more about enjoying what I do, and sadly packaging is not one of the top things I personally enjoy, at least for now given there are so many other things which I would like implemented.

If somebody gets paid to do the packaging, great! If somebody does the packaging just because they want the product to improve, also great! If this does gain traction, and more developers join to help us out on something else than the packaging, also great!

2 Likes

OK, keep up the good work.

And if somebody who isn’t a developer manages to get the product to work properly, also great!

1 Like

The product does not provide a feature to install itself as a service, hence I am not convinced anything ‘doesn’t work properly’ from the products perspective? If you want to run syncthing as a service, for now, it is up to the user to do that, especially when they understand what services are… Or follow any guides on this post…

I am pretty sure that it will happen eventually…

The reason why I think it’s not done by Syncthing itself at the moment is because it’s currently cross-compiled to Windows most likely on a Linux machine. And am not aware of a way to cross-package it to all platforms/distributions.

I know packages are maintained for multiple Linux distributions, given there is an official source of packages, which has all the init scripts and everything out of the box.

Since there is no such thing on Windows, I guess that’s the reason why you are here, looking for ways to make it do what you want.

Given it could fairly easily be done by SyncthingTray, perhaps you should make a feature request there? Or perhaps even contribute, given it’s written in C#… Or are you having some other issues ?