openrc/init.d/bootmisc

152 lines
4.4 KiB
Plaintext
Raw Normal View History

#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Copyright 2007 Roy Marples
# All rights reserved
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
depend() {
use hostname
need localmount
before logger
after clock sysctl
}
cleanup_tmp_dir() {
local dir=$1
mkdir -p "${dir}"
cd "${dir}"
2007-10-27 15:23:56 +05:30
if [ "${WIPE_TMP}" = "yes" ]; then
ebegin "Wiping ${dir} 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 ${dir} directory"
rm -rf "${dir}"/.X*-lock "${dir}"/esrv* "${dir}"/kio* \
"${dir}"/jpsock.* "${dir}"/.fam* "${dir}"/.esd* \
2007-10-23 15:35:47 +05:30
"${dir}"/orbit-* "${dir}"/ssh-* "${dir}"/ksocket-* \
"${dir}"/.*-unix
eend 0
fi
}
start() {
# Put a nologin file in /etc to prevent people from logging
# in before system startup is complete.
2007-10-27 15:23:56 +05:30
if [ "${DELAYLOGIN}" = "yes" ]; then
echo "System bootup in progress - please wait" > /etc/nologin
cp /etc/nologin /etc/nologin.boot
fi
2007-10-27 15:23:56 +05:30
if ! mkdir /.test.$$ 2>/dev/null; then
ewarn "Skipping /var and /tmp initialization (ro root?)"
return 0
fi
rmdir /.test.$$
# Ensure that our basic dirs exist
2007-11-20 17:50:50 +05:30
for x in /var/log /var/run /tmp; do
2007-10-27 15:23:56 +05:30
if ! [ -d "${x}" ]; then
2007-11-20 17:50:50 +05:30
if ! mkdir -p "${x}"; then
eend 1 "failed to create needed directory ${x}"
return 1
fi
fi
done
ebegin "Creating user login records"
2007-08-23 15:55:09 +05:30
printf "" >/var/run/utmp
[ -e /var/log/wtmp ] || printf "" >/var/log/wtmp
chmod 0644 /var/run/utmp /var/log/wtmp
eend 0
2007-11-20 17:50:50 +05:30
ebegin "Cleaning /var/run"
2007-07-26 02:28:23 +05:30
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
eend 0
# Clean up /tmp directories
2007-11-20 17:50:50 +05:30
local tmp=
2007-10-27 15:23:56 +05:30
for tmp in ${WIPE_TMP_DIRS-/tmp}; do
cleanup_tmp_dir "${tmp}"
done
chmod +t /tmp /var/tmp
# 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
# Create an 'after-boot' dmesg log
2007-10-27 15:23:56 +05:30
if [ "${RC_SYS}" != "VPS" ]; then
2007-04-26 19:52:54 +05:30
dmesg > /var/log/dmesg
chmod 640 /var/log/dmesg
2007-04-26 19:52:54 +05:30
fi
# Check for /etc/resolv.conf, and create if missing
[ -e /etc/resolv.conf ] || printf "" >/etc/resolv.conf
}
stop() {
# Write a halt record if we're shutting down
case "${RC_SOFTLEVEL}" in
2007-10-27 15:23:56 +05:30
reboot|shutdown) [ "${RC_UNAME}" = "Linux" ] && halt -w;;
esac
return 0
}
# vim: set ts=4 :