Suggestion: Change recommendation for cron to systemd
See original GitHub issueHi again,
I wondered why you were recommending cron
for this task. I find it could easily lead to a conflicting state if the repeating window isn’t small enough (and then there’s a lot of unnecessary syncs).
I’m mainly curious to know your reasons so feel free to close this issue.
I’ve tried to get this right using systemd
executing a script on startup that first triggers a sync and afterwards syncs on changes monitored with inotifywait
.
rclonesync_watch.service
# /home/3ter/.config/systemd/user/rclone-sync-gdrive.service
[Unit]
Description=Sync Googledrive with the local folder on startup and on change afterwards
[Service]
ExecStart=/usr/bin/perl /home/3ter/scripts/rclonesync_watch.pl
[Install]
WantedBy=default.target
rclonesync_watch.pl
#!/bin/perl
use strict;
use warnings;
use v5.30;
our $local_dir = '/home/3ter/googledrive';
our $remote_dir = 'googledrive:/';
our $rclonesync_exe = '/home/3ter/rclonesync/rclonesync.py';
our $inotify_opts =
"--event " .
join(' --event ', qw(modify attrib close_write moved_to create delete)) .
" --recursive $local_dir";
sub wait_until_file_silent
{
while (1)
{
my $rc = system( "inotifywait --timeout 5 $inotify_opts" );
# Return code 0 shows us that there was another event triggered
return if $rc;
}
}
sub watch_folder
{
if (system( "inotifywait $inotify_opts" ) == 0)
{
wait_until_file_silent();
say qx( python3 $rclonesync_exe --verbose $local_dir $remote_dir 2>&1 );
}
return;
}
say '[rclone] Watching locally.';
if (-d $local_dir)
{
say 'Sync on startup';
say qx( python3 $rclonesync_exe --verbose $local_dir $remote_dir 2>&1 );
while (1)
{
watch_folder();
}
}
else
{
say "$local_dir isn't a valid directory!";
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Cron vs systemd timers - Unix & Linux Stack Exchange
Cron is guaranteed to be in any Unix-like system, in the sense of being an installable supported piece of software. That is not...
Read more >Hunting for Persistence in Linux (Part 3): Systemd, Timers ...
How attackers use newly created and existing accounts for peristence and how to detect them.
Read more >Cron vs systemd : r/linuxadmin - Reddit
Recently I came to know about systemd timer and it seems we can also schedule daily jobs via it. Please suggest which is...
Read more >Use systemd timers instead of cronjobs - Opensource.com
I am in the process of converting my cron jobs to systemd timers. ... is derived from the systemd.timer man page with a...
Read more >Talk:Systemd/Timers - ArchWiki - Arch Linux
Under Using a crontab it states that systemd-crontab-generator AUR and systemd-cronAUR provide an alternative to the missing RANDOM_DELAY feature from cron, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From https://www.linuxjournal.com/content/linux-filesystem-events-inotify:
Sweet.
Closing this for now. My take is that rclonesync isn’t the right tool to act as a local agent and be notified and react to changes as they happen. If we had an agent it could take care of individual files that change, and not have to scan the sync tree at all.