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

Hi there!

Would it be possible to ad an option to syncthing that made it start in the background, just showing a system try icon and not opening a shell window?

In our target environment, we have the computers locked down to the point where shell windows can’t be opened (for securety reasons), and thus syncthing won’t start.

This goes kind of in the directon of this topic, but the important thing for us is not so much tray notifications but the fact that it starts even when it can’t open up a shell window.

Thanks for the great work!

2 Likes

If i understood your request, I think you can setup Syncthing to start in background at boot with user privileges. I have add this line to my /etc/rc.local:

su -l <youruser> -c /home/<youruser>/<syncthing-folder>/syncthing &

Or you can change the location of your syncthing directory (if you put in /bin is

su -l <youruser> -c /bin/syncthing & )

Can be useful? Not beautiful, very “old school”, but works for me!

1 Like

I suspect this is for Windows. There is a way to compile/modify a syncthing binary to not use a shell window. That requires some tinkering, and I’m not sure if it also makes it impossible to get at the console log in general. Would need to do some investigation.

Thanks for the suggestion, but this is indeed for windows. Should have told this in the first post.

Create a window service for syncthing. IMHO it’s not needed to change anything, it should be possible to use the current syncthing.exe to create a windows service.

See: http://stackoverflow.com/a/3582179

Other solution: use “start.exe /min” to create a minimized window.

I have tried this.

sc create syncthing_service binpath= "C:\scripts\syncthing-windows\syncthing.exe" type= own start= auto DisplayName= "SyncThing Service"

This creates a service, which shows up in my Services listing as “Stopped” When I try to start the service, however, it fails.

Is there an example of successfully running syncthing as a service in Windows?

Is syncthing “service-aware” in that it speaks and honors constructs of the Service Control Manager?

I have been trying to achieve the same and from my testing it appears that syncthing is unable to reply to service control manager with expected output and so will not start.

However, I have discovered a workaround; creating a batch file which runs the .exe and schedule a task to run it when idle with your required timescale. I currently have set mine to 1 minute (as that’s what syncthing is configured as) and works like a charm!

We are now using runAsService in order to create a syncthing background task. Important to note is that when you do that, make sure to tell syncthing where its configuration files are (via “-home” parameter), as it will not be able to access any default home folder when running as a service.

launch hidden syncthing.bat

@echo off

cd /d “%~dp0”

IF NOT EXIST “data.” MD data

tasklist /fi “imagename eq syncthing.exe” 2>NUL | find /I /N “syncthing.exe”>NUL

IF “%ERRORLEVEL%”==“0” (    echo Syncthing is running    timeout 5 >NUL ) ELSE (    set STNORESTART=yes    cmdow.exe /run /hid syncthing.exe -home=data & exit )

you can also build an EXE launcher with   Bat To Exe Converter

and add an icon file to it

right click save as icon

Very simple create 1.cmd

rem stelss bat
@echo off
 
rem create work bat
echo dir /s c:\^>log.txt>wait.cmd
 
rem Script file cooking
echo Set WshShell = CreateObject("WScript.Shell") >start.vbs
echo WshShell.Run "d:\apps\syncthing\syncthing.exe", 0, false>>start.vbs
 
rem run cooked script, dont wait exit
cscript.exe //b //nologo start.vbs
 
rem del temped files
del /f /q start.vbs
del /f /q wait.cmd
  1. place 1.cmd to you application folder (d:\apps\synthing)
  2. add link 1.cmd to autorun
  3. no window, but we see program in task manager
  4. profit!

I have tried every solution here and none of them have worked for me, can anyone help me out?

Edit:

This is what ended up working for me

http://www.joeware.net/freetools/tools/quiet/

Just drop the exe into a folder that is in your path, and then in the cmd do

quiet %path to exe I want to run quietly%

Here’s something for you guys to try.

https://nym.se/t/syncthing-windows-amd64-v0.8.19-1-g4d1d358.zip https://nym.se/t/syncthing-windows-386-v0.8.19-1-g4d1d358.zip

I added a new command line flag -no-console to the Windows build. This causes syncthing to release the console, but it is still allocated on startup so you’ll see a brief flash of console window on startup… But at least it doesn’t hang around forever. It’s probably easiest to use a shortcut to set the flag:

When doing this, there’ll be no indication at all that syncthing is running, apart from being visible in the task manager and the web gui being accessible. Obviously it’d be nice with a tray icon, etc, but that’s for another day (and perhaps another developer).

Hmm, apparently restart no longer works when running without a console (it simply exits); not sure why, so that’s something to be aware of for the moment.

Just downloaded syncthing v0.9.8 (go1.3.1 windows-amd64 default) and see the same behavior. Running with -no-console makes it to exist right away.

That was a specific build with that feature. As far as I could tell, no one cared or tested it so it didn’t go anywhere.

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.