This script looks for a file existence and it exists, it will restart apache. You can replace the following parameters to work based on your needs.
file_path --> /path/to/file that you want to watch for existence.
sudo service apache2 restart --> replace this command with the relevant restart command that you want to run.
watch_file=`ls /home/vagrant | grep test_file`
if [ ! -z $watch_file ]
echo "restarting apache....."
sudo service apache2 restart
if [ $? == 0 ]
echo "apache successfully restarted"
echo "apache restart failed"
echo "There is no test_file"
You can make it as a monitoring script by adding it to your system crontab entry.
For exmaple, to run it every minute, you can use the following syntax.
*/1 * * * * bash /path/to/watch.sh