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

If one of you will readd the -no-console flag, I have made a tool to install it as a service running as a specific user, and can make an install package as well. But I need it to run without a console and preferabally with some hooks to the output.

Would you be interested in perhaps contributing your tool to syncthing-gtk? It already kills the console window, hence installing it as a service on Windows would be an even better feature.

I can do that. It is based on .net so it will probably not work out of the box with your setup. I will see if I have the time during the weekend to get it on github, and make sure it works with the latest version of VS Community Edition, then we can see what needs to be done from that point on.

I’m using systemd to manage syncthing on a debian server. The unit I use is /etc/systemd/system/syncthing@.service

[Unit]
Description=Syncthing service for %i
After=network.target

[Service]
User=%i
Environment=STNORESTART=yes
ExecStart=/usr/local/bin/syncthing
Restart=always

[Install]
WantedBy=multi-user.target

I can then use it, even for multiple users (providing the settings for used ports are different), by enabling the service with:

systemctl enable syncthing@USERNAME
systemctl start syncthing@USERNAME

And I have the benefit of logging any output to the system log without any more work.

In case it helps anyone, I use RBTray (http://rbtray.sourceforge.net/) to minimize windows to the notification tray, so have just done the same with syncthing, sure it isn’t pretty but gets the job done for now with little effort. and then add it to autostart on login.

I write to let you know I have not forgotten or abandoned the idea. I need to get the permission to do this from the developer that originally designed the framework. Even though I have made many modifications, much of his code is still there. Futhermore I am in the process of adding the ability to log to Event Log and use it to start executeables and dll files directly without any coding at all. I will update you once I have made some progress with the licensing.

I create a solution, with some C code. It starts the Syncthing without the console window, using the Windows API. After the Syncthing hidden execution, my program is closing and leave the Synchting running at the background.

No installation or configuration is required. Just put the program at the same folder with the Syncthing and run it.

You can checkout the source code from the project’s page at GitHub, or just download the executable from the release page.

I posted what I do here and we have 15 Windows clients and 1 CentOS 7 server.

Another option for the Windows crew:

http://www.pegtop.net/start/ This is a nice, flexible and portable little launcher I’ve been using for a few years. If you set this to start at boot, you can then autostart any program/script. Very handy.

Only thing I can’t make work is the -no-console command. Nothing happens.

1 Like

@stim my solution removes the console window.

I like to use NSSM (Non-Sucking Service Manager) for executables that aren’t service aware. You can download it here: https://nssm.cc/download

Extract a copy of NSSM.exe and drop it in the same folder with Syncthing.exe. Then open a command prompt from that folder and type this: nssm install Syncthing

Then browse for the Syncthing.exe and then set the home path with the -home option. Here is a screenshot of how mine is setup:

This seems to be working perfect so far. Even when restarting from the webui.

Edit: Duh, I see NSSM has already come up several times in this thread. Hahaha

2 Likes

You can use -no-console

I really discourage using /etc/rc.local for then running things at startup.

It is much easier, more secure and less error prone to simply add an @reboot entry to the crontab of the relevant user.

$ crontab -e Add: @reboot syncthing-versionBLA/syncthing

As simple as that :slight_smile:

On Windows (10) I would recommend to follow the Syncthing documentation. But it could be updated:

1. Hit the Windows key + X
2. select "Command Prompt (admin)" this will open a command prompt with admin rights
3. copy and paste this command and hit enter, change the path your your Syncthing executable if necessary:

REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\Program Files\Syncthing\syncthing.exe -no-console -no-browser"

This will add Syncthing to Windows Autorun for all users. Syncthing will start after login which is highly recommended. Also, the webUI works and you can restart Syncthing flawlessly from the WebUI Settings.

This is almost perfect: I do not know how to set the priority to low, which most people probably want to have.

You can edit: https://github.com/syncthing/docs/blob/master/users/autostart.rst straight from github, which will reflect in: http://docs.syncthing.net/users/autostart.html?highlight=autostart and the docs we ship with the release.

Thanks I will update the documentation, just trying to find a way to set the priority to low using that registry command.

start /low syncthing.exe -no-console -no-browser

Based on this idea of the thread for “Syncthing Windows Installer”, I create a project on github called “Syncthing Light”.

Syncthing Light is a simple package installer for install and runs Syncthing as Windows Service (without tray utility - runs hidden).

I would advise against distributing something which runs Syncthing as a privileged user. This has security implications which new users will likely not understand: see the docs pages for more details.

Why not put the config in ProgramData, rather than polluting C:?

Not allowing Syncthing to auto update seems like a pretty severe limitation, as users will not get security fixes.

1 Like

It looks like Syncthing auto upgrades should work, although the whole running-as-SYSTEM thing is still an exceedingly dangerous idea.