Cron job to create a schedule

Please excuse my ineptitude when it comes to cron jobs and linux in general.

I have syncthing setup on both my remote ubuntu server (14.04) and on a local rpi3 running openelec. Syncing is running smoothly.

What I would like to do however is setup a daily schedule during which the syncing would take place.

I have read many posts regarding this and have come to the conclusion that I should setup cron jobs on my ubuntu server that would start syncthing at a specific time and then stop it. I would apreciate if someone can explain how to do that for syncthing.

Let’s say I want it to start at 21:00 and end at 23:00.

Thank you :slight_smile:

PS: what would happen if it stops while it’s in mid-syncing. would it resume?

There is plenty of documentation on cron on the internet. The commans for starting would be full absolute path to syncthing, for stopping probably killall syncthing

1 Like

Would not killall corrupt the database?

You probably can first shutdown the server with the API then start it after waiting some time in your cron script. I found the Rest api to be working consistently.

1 Like

I suspect it still sends sigterm oppose to sigkill

1 Like

We have sigterm handlers to shutdown gracefully on a sigterm:

2 Likes

Thanks guys. Following your replies I setup a cronjob to start Syncthing using the full path, and the Rest API to "Shutdown" However, after shutting down Syncthing remains listening to the tcp port and thus wouldn’t start when the cronjob executes the command. Any input is apreciated. Cheers

Then it’s not shut down, you are doing something wrong. Just use kill instead.

1 Like

When I send the rest api POST request, the service stops and I can no longer get to the GUI. However, if I try to start syncthing it tells me that the port is being listened to. I check which service is listening to the port, it shows Syncthing. I kill the service listening to that port and I after that I can successfully start Syncthing.

Edit: This happens only when I try to start syncthing after a few hours (actually it’s cron that’s starting it). I check the cron.log and I can see that it has executed the command; however, syncthing is not running. I try to start it (/usr/bin/syncthing) and I get the error I mentioned above.

If I try to replicate the issue by sending the “shutdown” POST then I try to start syncthing shortly after, and it starts normally (no error). It seems something is happening during the few hours after sending the shutdown POST.

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