aboutsummaryrefslogtreecommitdiff
path: root/init.d/bootmisc
blob: 96024eba1b1fa69b46a391eb03a2c56dbbb61faa (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
	use hostname
	need localmount
	before logger
	after clock sysctl
}

start() {
	# Put a nologin file in /etc to prevent people from logging
	# in before system startup is complete.
	if [ "${DELAYLOGIN}" = "yes" ] ; then
		echo "System bootup in progress - please wait" \
			> /etc/nologin
		cp /etc/nologin /etc/nologin.boot
	fi

    if [ -e /etc/sysctl.conf -a ! -x /etc/init.d/sysctl ] ; then
		if [ "${RC_SYS}" != "VPS" ] ; then
			ebegin "Configuring kernel parameters"
			sysctl -p /etc/sysctl.conf >/dev/null
			eend $?
		fi
	fi
	
	if ! echo 2>/dev/null >/var/run/.test.$$ ; then
		ewarn "Skipping /var and /tmp initialization (ro root?)"
		return 0
	fi
	rm -f /var/run/.test.$$

	if [ "${RC_UNAME}" = "Linux" ] ; then
		# Setup login records
		printf "" >/var/run/utmp
		[ -e /var/log/wtmp ] || printf "" >/var/log/wtmp
		chgrp utmp /var/run/utmp /var/log/wtmp
		chmod 0664 /var/run/utmp /var/log/wtmp
	fi

	ebegin "Updating environment"
	# Use our version, not portage version.
	/sbin/env-update --fork-ldconfig
	eend $?

	# Take care of random stuff [ /var/lock | /var/run | pam ]
	ebegin "Cleaning" /var/lock, /var/run
	rm -rf /var/run/console.lock /var/run/console/*

	# Clean up any stale locks.
	find /var/lock -type f -print0 | xargs -0 rm -f --
		
	# Clean up /var/run and create /var/run/utmp so we can login.
	for x in $(find /var/run ! -type d ! -name utmp ! -name innd.pid \
		! -name random-seed ! -name ld-elf.so.hints ! -name ld.so.hints); do
		[ ! -f "${x}" ] && continue
		# Do not remove pidfiles of already running daemons
		case "${x}" in
			*.pid)
				start-stop-daemon --test --quiet --stop --pidfile "${x}"
				[ $? -eq 0 ] && continue
				;;
		esac
		rm -f "${x}"
	done

	# Reset pam_console permissions if we are actually using it
	if [ -x /sbin/pam_console_apply ] && ! [ -c /dev/.devfsd ] ; then
		if grep -v -e '^[[:space:]]*#' /etc/pam.d/* | grep -q 'pam_console.so' ; then
			pam_console_apply -r
		fi
	fi

	# Create the .keep to stop portage from removing /var/lock
	printf "" >/var/lock/.keep
	eend 0

	# Clean up /tmp directory
	if [ -d /tmp ] ; then
		cd /tmp
		if [ "${WIPE_TMP}" = "yes" ] ; then
			ebegin "Wiping /tmp directory"
			local startopts="-x . -depth"
			[ "${RC_UNAME}" = "Linux" ] && startopts=". -xdev -depth"

			# Faster than find
			rm -rf [b-ikm-pr-zA-Z]*

			find ${startopts} ! -name . \
				! -path ./lost+found \
				! -path "./lost+found/*" \
				! -path ./quota.user \
				! -path "./quota.user/*" \
				! -path ./aquota.user \
				! -path "./aquota.user/*" \
				! -path ./quota.group \
				! -path "./quota.group/*" \
				! -path ./aquota.group \
				! -path "./aquota.group/*" \
				! -path ./journal \
				! -path "./journal/*" \
				-delete
			eend 0
		else
			ebegin "Cleaning /tmp directory"
			rm -rf /tmp/.X*-lock /tmp/esrv* /tmp/kio* /tmp/jpsock.* \
				/tmp/.fam* /tmp/.esd* /tmp/orbit-* /tmp/ssh-* \
				/tmp/ksocket-* /tmp/.*-unix
			eend 0
		fi

		# Make sure our X11 stuff have the correct permissions
		# Omit the chown as bootmisc is run before network is up
		# and users may be using lame LDAP auth #139411
		rm -rf /tmp/.ICE-unix /tmp/.X11-unix 
		mkdir -p /tmp/.ICE-unix /tmp/.X11-unix
		chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix
		[ -x /sbin/restorecon ] && restorecon /tmp/.ICE-unix /tmp/.X11-unix
	fi

	# Create an 'after-boot' dmesg log
	if [ "${RC_SYS}" != "VPS" ] ; then
		dmesg > /var/log/dmesg
		chmod 640 /var/log/dmesg
	fi

	# Check for /etc/resolv.conf, and create if missing
	[ -e /etc/resolv.conf ] || printf "" >/etc/resolv.conf
}

stop() {
	# Reset pam_console permissions if we are actually using it
	if [ -x /sbin/pam_console_apply ] && ! [ -c /dev/.devfsd ] ; then
		if grep -v -e '^[[:space:]]*#' /etc/pam.d/* | grep -q 'pam_console.so' ; then
		/sbin/pam_console_apply -r
	fi

	# Write a halt record if we're shutting down
	case "${RC_SOFTLEVEL}" in
		reboot|shutdown)
			[ "${RC_UNAME}" = "Linux" ] && halt -w
			;;
	esac
	
	return 0
}

# vim: set ts=4 :