Stop Rclone on Shutdown

What is the problem you are having with rclone?

I have recently migrated to Linux (Arch with KDE). I have created a couple of cronjobs for rclone 'copy'.
Most of the time, I might have to reboot or shut down the system and during these times, the rclone service takes a long time to stop. The following line(s) show up during shutdown or reboot:

"...waiting for rclone(pid).."

What I want is that the rclone service should stop as soon as the system sends a shutdown or reboot signal or not take too much time (current case - it takes more than 2 minutes, which is not normal).

Can I have guidance on the issue? Should I add some entries to the cron .sh files or the crontab -e list?
Any help is appreciated.

Run the command 'rclone version' and share the full output of the command.

rclone v1.62.2

  • os/version: arch "rolling" (64 bit)
  • os/kernel: 6.3.5-zen2-1-zen (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.20.4
  • go/linking: dynamic
  • go/tags: none

Which cloud storage system are you using? (eg Google Drive)


The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone copy

It is rather issue about your particular OS and crontab - good thing is that Arch has fantastic documentation and community.

IMHO you will get much better control using systemd instead of crontab.

you can also double check if there is no some issue/bug with rclone. Run your task in terminal and CTRL-C - normally it should stop immediately.

Thanks for the reply. There are no errors.
In fact, the corn job runs smoothly. I only need the rclone service to stop immediately on shutdown and reboot.

Can you elaborate?

Sure. What I am saying that at least for copy rclone has no issues to stop immediately. Why your crontab behaves differently? I have no clue.

IMHO you will get much better control using systemd instead of crontab.

Can you elaborate on this?

You can control for example how process is terminated. Your crontab process during shutdown receives SIGTERM and does not terminate quickly,

With systemd you can specify how to stop it e.g. by sending SIGKILL where service stop is requested.

ExecStop=/bin/kill -9 $MAINPID

This seems innovative. Considering that I am new to Linux, can you provide help on how to move the rclone jobs from crontab to systemd and, at the same time, conserve the crontab functionality (to run every two hours/every day/week or run during boot and so on).

Are you also new to google? Or you need assistant?:slight_smile:

1 Like

Thanks for this. I have set everything up in Linux until now without creating a single forum post. I always try to do everything myself and come here only when I am stuck :slight_smile:

1 Like

Happy that it worked. Did it help with shutdown time?

Yes, it did help!

1 Like

you could share your solution - maybe others can use it:)

I have already marked what worked for me as the solution. I went from cron to systemd. Hope that helps :wink:

1 Like

ExecStop=/bin/kill -9 $MAINPID

Just clearing something up, should I make any changes to this line before adding it to the service file?

check if kill is in this path /bin/kill. It should be but could be in /sbin instead... I am not sure it is the same for all systems.

Also maybe to make it looking nicer:

ExecStop=/bin/kill -s SIGKILL $MAINPID

One thing I would do is to test as well with:

ExecStop=/bin/kill -s SIGTERM $MAINPID

SIGKILL is non-catchable, non-ignorable kill when SIGTERM is software termination signal. If system shutdown works with SIGTERM there is no need to use SIGKILL

Other thing is that if running your rclone job using systemd does not delay shutdown/reboot there might be not need at all to send termination signal on Stop... If things work without maybe it is enough.

Something is not right. Now during the shutdown, it shows the following:
"A stop service is running for 'Rclone service name'"

It takes 1min 30s and, the countdown is shown as well.

When using a network mount, before unmounting, you want to stop all IO/processes to that mount point.

I do that by making sure any service dependent on rclone stops before I shut down rclone.

You see a long timeout as your mount cannot unmount because there is IO/processes using it

Killing it can lead to data loss or odd situations.