inotify / incrontab

Submitted by Jeff on Fri, 30/03/2018 - 11:55
Forums

This is to automatically set  the owner permissions back to www-data whenever a file or directory is added to the Drupal and WordPress directories which we are going to monitor.

First, install and configure incrontab:

$ apt-get install incron

Then edit the allowed user to run the commands we'll specify with incrontab, which is the root user:

$ nano /etc/incron.allow
root

Save and exit.

Incrontab can only monitor one directory, not its subdirectories, so each one to be monitored needs to be stated explicitly.

Note: This only monitors new files, we can also monitor modified files with IN_MODIFY:

 $ incrontab -e
/var/www IN_CREATE /bin/chown -R www-data:www-data /var/www/ /var/www/html/drupal/web/modules/contrib IN_CREATE /usr/local/tools/www-drupal-fix.sh
/var/www/html/iweek IN_CREATE /bin/chown -R www-data:www-data
/var/www/ /var/www/html/iweek/wp-admin IN_CREATE
/bin/chown -R www-data:www-data /var/www/
/var/www/html/iweek/wp-content IN_CREATE /bin/chown -R www-data:www-data /var/www/
/var/www/html/iweek/wp-content/plugins IN_CREATE /bin/chown -R www-data:www-data /var/www/
/home/ispa/wordpress IN_CREATE /bin/chown -R www-data:www-data /home/ispa/wordpress/
/home/ispa/wordpress/wp-admin IN_CREATE /bin/chown -R www-data:www-data /home/ispa/wordpress/
/home/ispa/wordpress/wp-content IN_CREATE /bin/chown -R www-data:www-data /home/ispa/wordpress/
/home/ispa/wordpress/wp-content/plugins IN_CREATE /bin/chown -R www-data:www-data /home/ispa/wordpress/

Save and exit.

Note on above. WordPress config is complicated by lots of custom html and php in strange directories.

Drupal requires 2 commands in the /usr/local/tools/www-drupal-fix.sh:

#!/bin/bash
/bin/chown -R www-data:www-data /var/www/
/bin/chmod g+w -R /var/www/html/drupal/modules/


 

 

FF Tags
Category