# grep -iR runlevel /etc/ /etc/init/rc-sysinit.conf:# Default runlevel, this may be overriden on the kernel command-line /etc/init/rc-sysinit.conf:env DEFAULT_RUNLEVEL=2
可以看到,在/etc/init/rc-sysinit.conf文件中设置的:
1 2
# Default runlevel, this may be overriden on the kernel command-line env DEFAULT_RUNLEVEL=3
# cat /etc/init.d/xscript #! /bin/sh ### BEGIN INIT INFO # Provides: start or reboot,etc... # Required-Start: # Required-Stop: # Default-Start: 2 3 # Default-Stop: 0 1 6 # Short-Description: # Description: ### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
. /lib/lsb/init-functions
# other things to do before dying... do_stop () { echo "Stop in my script and clean net.rules...." echo "" > /etc/udev/rules.d/70-persistent-net.rules }
case "$1" in start) echo "Will START Running...." cd /home/latelee chmod +x my_run.sh ./my_run.sh ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) do_stop ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac
# update-rc.d xscript defaults 99 update-rc.d: warning: default start runlevel arguments (2 3 4 5) do not match xscript Default-Start values (2 3) Adding system startup for /etc/init.d/xscript ... /etc/rc0.d/K99xscript -../init.d/xscript /etc/rc1.d/K99xscript -../init.d/xscript /etc/rc6.d/K99xscript -../init.d/xscript /etc/rc2.d/S99xscript -../init.d/xscript /etc/rc3.d/S99xscript -../init.d/xscript /etc/rc4.d/S99xscript -../init.d/xscript /etc/rc5.d/S99xscript -../init.d/xscript
重启系统:
1 2 3 4 5 6 7 8 9 10 11
root@localhost:~# reboot
Broadcast message from root@localhost (/dev/ttyS2) at 17:09 ...
The system is going down for reboot NOW! root@localhost:~# wait-for-state stop/waiting * Stop in my script and clean net.rules.... * Asking all remaining processes to terminate... [ OK ] * All processes ended within 1 seconds... [ OK ]
可以看到有Stop in my script and clean net.rules....打印,在reboot后,已经执行了我们自己写的命令了。