Is this syncthing running?

OK. Slightly complex set of circumstances here. I have a syncthing config.xml, and I’d like to know whether there is a syncthing instance running which is using this config.xml as its config.

There are many different config.xmls, and many different syncthing instances running on this machine, so “is syncthing running at all” is not enough. Also, the port is specified as 0, not as a specific port (because there are many syncthings, so they need to not collide on port numbers), so I can’t read config.xml for its listenAddress and then try connecting to it with the appropriate auth. Syncthing does not, as far as I can tell, write a pidfile or something like it. However, if I try to start syncthing with that config file again and it is already running, I get a database collide, so something knows it’s already running. I can, of course, just use that as my method: to find out whether there’s a syncthing running for this config, try starting a new one and see if it errors. But that’s a bit inelegant :slight_smile: Is there a better way?

If the config.xml is inside its config folder (home folder of Syncthing) you could maybe check the process list for syncthing -home <path of that config.xml>.

If global discovery is enabled, you can check if that ID is “currently” used.

If the GUI port also set to 0? If not, you can check if that port is listening.

As the config.xml normally has a API key, you could try to connect to the api on the ports of all running Syncthing processes ;). Or connect to the ports of all running instances and check if the presented cert is the one from the config folder.

Huh. That’s a good thought and one I had not considered, and probably the easiest way to boot. (The other tricks won’t work, I think, since the gui port is also 0, and I have no sensible way to find the ports of all running processes (lsof and whatnot are not sensible, they’re a pain :)) I’ll just look at the process list. Clever; thank you :slight_smile:

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