I want to run some application specific cleanup code when Apache is restarted. First, I followed the steps from https://stackoverflow.com/questions/2992938/is-it-possible-to-launch-a-php-script-at-apache-startup. I changed /etc/init.d/apache2 on a local Ubuntu 16.04.1 LTS virtual machine with Apache/2.4.18, adding some code under start and it worked perfectly. But when I tried to follow the exact same steps on the Ubuntu 16.04.2 LTS with Apache/2.4.23 hosted on AWS, it was almost like my changes are being ignored. I've put in a number of "echo" statements to understand what is going on, but I am not seeing any sign the code is being run.
This is what I changed in /etc/init.d/apache2
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
RET_STATUS=$?
case "$RET_STATUS" in
0|1)
log_success_msg
[ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was already running"
;;
2)
log_failure_msg
print_error_msg
exit 1
;;
esac
# Restart the reports that would have died when the server is restarted
echo Restarting reports
echo `date +%Y-%m-%d:%H:%M:%S` Starting report:restart_running_reports >> /var/www/application/storage/logs/restart_running_reports.log
php /var/www/application/artisan report:restart_running_reports
;;
- Is there some sort of way to log what is going on in /etc/init.d/apache2 to see if it is even making it to that switch statement? Where do the log_daemon_msg end up?
- Is there some other way to run scripts when Apache is started/restarted?