summaryrefslogtreecommitdiff
path: root/rc.single
blob: f986a2ac0fdd70de53759eb6b8ff88c94c970452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
#
# /etc/rc.single: Single-user startup script.
#

. /etc/rc.conf
. /etc/rc.d/functions

run_hook single_start

if [ "$PREVLEVEL" != "N" ]; then

	# Find daemons NOT in the DAEMONS array. Shut these down first
	if [ -d /var/run/daemons ]; then
		for daemon in $(/bin/ls -1t /var/run/daemons); do
		  if ! in_array $daemon ${DAEMONS[@]}; then
				stop_daemon $daemon
		  fi
		done
	fi
	# Shutdown daemons in reverse order
	let i=${#DAEMONS[@]}-1
	while [ $i -ge 0 ]; do
		if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
			ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
		fi
		let i=i-1
	done

	# Terminate all processes
	stat_busy "Sending SIGTERM To Processes"
	run_hook single_prekillall
	/sbin/killall5 -15 &> /dev/null
	/bin/sleep 5
	stat_done

	stat_busy "Sending SIGKILL To Processes"
	/sbin/killall5 -9 &> /dev/null
	/bin/sleep 1
	stat_done

	run_hook single_postkillall

	stat_busy "Starting UDev Daemon"
	/sbin/udevd --daemon
	stat_done

	run_hook single_udevlaunched

	# Trigger udev uevents
	if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
	  stat_busy "Triggering UDev uevents"
	  /sbin/udevadm control --property=STARTUP=1
	  /sbin/udevadm trigger --action=add
	  stat_done
	fi

	# Wait for udev uevents
	if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
		stat_busy "Waiting for UDev uevents to be processed"
		/sbin/udevadm settle
		/sbin/udevadm control --property=STARTUP=
		stat_done
	fi

	run_hook single_udevsettled

	# try syslog-NG first, then fall back to good ol' syslogd
	if [ -x /etc/rc.d/syslog-ng ]; then
		/etc/rc.d/syslog-ng start
	elif [ -x /etc/rc.d/syslogd ]; then
		/etc/rc.d/syslogd start
		[ -x /etc/rc.d/klogd ] && /etc/rc.d/klogd start
	fi
fi

run_hook single_end

if [ "$RUNLEVEL" = "1" ]; then
	printsep
	printhl "Entering single-user mode..."
	# make sure /dev/initctl is in place
	/bin/kill -HUP 1
	exec /sbin/init -t1 S
fi

# End of file
# vim: set ts=2 noet: