Skip to content

Instantly share code, notes, and snippets.

@betapcode
Created January 24, 2019 09:58
Show Gist options
  • Save betapcode/fe6cce6e166b9a162462c63d2b6adb31 to your computer and use it in GitHub Desktop.
Save betapcode/fe6cce6e166b9a162462c63d2b6adb31 to your computer and use it in GitHub Desktop.
trigger a script to run after the rsyncdaemon

I can trigger a script to run after the rsyncdaemon received file changes to a certain folder?

Step 1: open file config rsync

$ vi /etc/xinetd.d/rsync
service rsync
{
        disable = no
        #flags          = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /opt/rsync_trigger.sh # change /usr/bin/rsync to /path/to/script
        server_args     = --daemon
        log_on_failure  += USERID
}

Step 2: save code php to file

$ vi reset_cached.php
<?php
opcache_reset();
?>

Step 3: Go to path to script. eg: /opt/rsync_trigger.sh

$ vi /opt/rsync_trigger.sh
#!/bin/bash
/usr/bin/rsync "$*"

/usr/bin/curl http://localhost/reset_cached.php
#or option 2
#/usr/local/bin/php /var/www/reset_cached.php
# or option 3
#/usr/local/bin/php -r 'opcache_reset();'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment