resolved – /etc/rc.local not executed on boot in linux
When you find your scripts in /etc/rc.local not executed along with system boots, then one possibility is that the previous subsys script takes too long to execute, as /etc/rc.local is usually the last one to execute, i.e. S99local. To prove which is the culprit subsys that gets stuck, you can edit /etc/rc.d/rc(which is from /etc/inittab):
[root@host1 tmp] vi /etc/rc.d/rc # Now run the START scripts. for i in /etc/rc$runlevel.d/S* ; do check_runlevel "$i" || continue # Check if the subsystem is already up. subsys=${i#/etc/rc$runlevel.d/S??} [ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \ && continue # If we're in confirmation mode, get user confirmation if [ -f /var/run/confirm ]; then confirm $subsys test $? = 1 && continue fi update_boot_stage "$subsys" # Bring the subsystem up. if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then export LC_ALL=C exec $i start fi if LC_ALL=C egrep -q "^..*init.d/functions" $i \ || [ "$subsys" = "single" -o "$subsys" = "local" ]; then echo $i>>/var/tmp/process.txt $i start echo $i>>/var/tmp/process_end.txt else echo $i>>/var/tmp/process_self.txt action $"Starting $subsys: " $i start echo $i>>/var/tmp/process_self_end.txt fi done
Then you can reboot the system, and check files /var/tmp/{process.txt,process_end.txt,process_self.txt,process_self_end.txt}. In one of the host, I found below entries:
[root@host1 tmp]# tail process.txt
/etc/rc3.d/S85gpm
/etc/rc3.d/S90crond
/etc/rc3.d/S90xfs
/etc/rc3.d/S91vncserver
/etc/rc3.d/S95anacron
/etc/rc3.d/S95atd
/etc/rc3.d/S95emagent_public
/etc/rc3.d/S97rhnsd
/etc/rc3.d/S98avahi-daemon
/etc/rc3.d/S98gcstartup
[root@host1 tmp]# tail process_end.txt
/etc/rc3.d/S85gpm
/etc/rc3.d/S90crond
/etc/rc3.d/S90xfs
/etc/rc3.d/S91vncserver
/etc/rc3.d/S95anacron
/etc/rc3.d/S95atd
/etc/rc3.d/S95emagent_public
/etc/rc3.d/S97rhnsd
/etc/rc3.d/S98avahi-daemon
So from here, we can see /etc/rc3.d/S98gcstartup tried start, but it took too long to finish. To make sure scripts in /etc/rc.local get executed and also the stuck script /etc/rc3.d/S98gcstartup get executed also, we can do this:
[root@host1 tmp]# mv /etc/rc3.d/S98gcstartup /etc/rc3.d/s98gcstartup
[root@host1 tmp]# vi /etc/rc.local
#!/bin/sh
touch /var/lock/subsys/local
#put your scripts here - begin
#put your scripts here - end
#put the stuck script here and make sure it's the last line
/etc/rc3.d/s98gcstartup start
After this, reboot the host and check whether scripts in /etc/rc.local got executed.