Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following problem: I make some automated changes in my webserver config (through a web interface) and I want to restart the apache. Since none of the actions are performed by root I cannot start the server directly.

My current workaround is to have a cronjob(every minute) for root that checks if a specific file exists (/tmp/restart.txt). If the file exists, it is deleted and the apache is restarted.

This can be invoked by other users by simply touching the file

$ touch /tmp/restart.txt

My question now is: Can I avoid the cronjob and somehow create a listener that gets invoked everytime the mtime of the file changes? This would be a better solution in my opinion.

share|improve this question

2 Answers 2

We are using iwatch to monitor file changes on our servers. It uses inotify, which is included in Linux kernels >= 2.6.13 and depends on Perl, but I guess this should be available if you are running a Linux box.

iwatch -c "File %f changed >> /tmp/changed.txt" -e modify /path/to/monitor

-c specifies the command to execute, -e specifies the events to watch for (all in the documentation). The /path/to/monitor can be a directory or file.

share|improve this answer

cronjob doing this would be slightly more secure:

find /path/to/httpd.conf -newer /tmp/ars.dat -exec "/path/to/apache.rc restart;" -exec "touch -m /tmp/ars.dat;"

Putting the reference file somewhere other than tmp would probably be a good idea too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.