question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: Change recommendation for cron to systemd

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cjnazcommented, May 19, 2020

From https://www.linuxjournal.com/content/linux-filesystem-events-inotify:

Recalcitrant users should be confined to Ultrix on a VAX until they develop sufficient appreciation for modern tools and approaches, which should result in more efficient Linux systems and happier administrators.

Sweet.

0reactions
cjnazcommented, Jun 8, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found