Linux – Troubleshoot if /etc/init.d script would run on startup, without actually rebooting

init.dlinuxtroubleshootingUbuntu

I have this script in /etc/init.d that I want to know if it will be run when the system reboots. Is there a way to "simulate" the conditions of a reboot to see if the script will actually be invoked (and to debug it) without having to actually reboot the system?

Please note that I'm aware that you can just run the script to debug it. My point is to troubleshoot those cases when the script runs ok when run manually but, for some reason, it is not run when the system starts/reboots (for example, some run condition with another script, things with permissions, etc).

Maybe this has to do with runlevels? As I am not that familiar with them.

Thanks!

Best Answer

A common issue is environment differences. If the script does not have a bang path on the first line, then shell differences may be an issue.

The most common issue I have experienced is path expectations. init.d scripts run with a stripped down path.

These are the same issues that cron scripts have. I believe the path and environment are the same or at least quite similar. Try running a cron job as root that dumps its environment. Something like:

echo PATH=$PATH
echo
echo ENVIRONMENT
env
echo
echo Set variables
set

Then start a /bin/sh session and clear its environment to match that of the cron job before running your init job. You should be able to script the setup and run as a /bin/sh script.