Configuration of runlevels:
/etc/inittab
init q #Updates the inittab file without reboot! id:5:initdefault: #Start in runlevel 5 als default
Start myprocess at runlevel 3:
5:3:once:/etc/myprocess
Problems with X after update or other problems. Solution: Add to /etc/inittab
x:5:respawn:/etc/X11/prefdm -nodaemon
Show runlevel:
runlevel
Change runlevel:
init value #Value can be 1-6
Change runlevel on ubuntu:
telinit value
Shutdown:
init 6 shutdown -k +3 Please save your work now! shutdown -r now
Example: Nagios NRPE Agent
#!/bin/sh
### BEGIN INIT INFO
# Provides: nrpe
# Required-Start: $networking
# Required-Stop: $networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Nagios Remote Executor Plugin
### END INIT INFO
#####Variables#####
DIR="/usr/local/nagios/bin"
start() {
echo "start nrpe"
${DIR}/nrpe -c ${DIR}/nrpe.cfg -d -n
ps ax --width=1000 | grep "${DIR}/nrpe" | cut -d " " -f1 | head -n 1 > /tmp/nrpe_process_count.txt
}
stop() {
echo "stop nrpe"
nrpe_pid=`ps ax --width=1000 | grep "${DIR}/nrpe" | cut -d " " -f1 | head -n 1`
kill $nrpe_pid
rm /tmp/nrpe_process_count.txt
}
status() {
if [ -f /tmp/nrpe_process_count.txt ]
then
read line < /tmp/nrpe_process_count.txt
if [ $line -gt 0 ];
then
echo -n "nrpe ( pid "
ps ax --width=1000 | grep "${DIR}/nrpe" | cut -d " " -f1 | head -n 1
echo -n ") is running..."
echo
fi
else
echo "nrpe is stopped"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
#sleep 3
start
;;
status)
status
;;
*)
echo "Usage: nrpe {start|stop|restart|status}"
exit 1
esac
Example Tomcat:
Enter the Grub-Shell with “e”, go to the very end of the line “linux”, change the “ro” to “rw” and add
init=/bin/bash
press enter, then press F10 to boot your system.
Enter
init=/bin/bash
in grub-menu and boot (enter).