openrc/init.d/bootmisc.in

142 lines
3.2 KiB
Plaintext
Raw Normal View History

#!@PREFIX@/sbin/runscript
# Copyright 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
depend()
{
use hostname
need localmount
before logger
after clock sysctl
2008-03-03 02:43:21 +05:30
keyword noprefix
}
2008-04-09 04:55:48 +05:30
dir_writeable()
{
mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$
}
cleanup_tmp_dir()
{
2008-04-09 05:36:50 +05:30
local dir="$1"
2008-04-09 04:55:48 +05:30
if ! [ -d "${dir}" ]; then
mkdir -p "${dir}" || return $?
fi
dir_writeable "${dir}" || return 1
2008-04-09 05:36:50 +05:30
chmod +t "${dir}"
cd "${dir}"
2007-12-09 19:19:20 +05:30
if yesno ${wipe_tmp:-${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-Z0-9\.]*
find ${startopts} ! -name . \
2008-03-18 13:49:29 +05:30
! -path "./lost+found" \
! -path "./lost+found/*" \
2008-03-18 13:49:29 +05:30
! -path "./quota.user" \
! -path "./quota.user/*" \
2008-03-18 13:49:29 +05:30
! -path "./aquota.user" \
! -path "./aquota.user/*" \
2008-03-18 13:49:29 +05:30
! -path "./quota.group" \
! -path "./quota.group/*" \
2008-03-18 13:49:29 +05:30
! -path "./aquota.group" \
! -path "./aquota.group/*" \
2008-03-18 13:49:29 +05:30
! -path "./journal" \
! -path "./journal/*" \
2008-03-18 13:49:29 +05:30
! -path "./.private" \
! -path "./.private/*" \
-exec rm -rf {} \;
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()
{
2008-04-09 04:55:48 +05:30
local logw=false
# 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
2008-04-09 04:55:48 +05:30
if dir_writeable /var/run; then
ebegin "Creating user login records"
cp /dev/null /var/run/utmp
if dir_writeable /var/log; then
logw=true
[ -e /var/log/wtmp ] || cp /dev/null /var/log/wtmp
chmod 0644 /var/run/utmp /var/log/wtmp
fi
eend 0
ebegin "Cleaning /var/run"
for x in $(find /var/run ! -type d ! -name utmp \
2008-05-12 20:41:04 +05:30
! -name random-seed ! -name dev.db \
2008-04-09 04:55:48 +05:30
! -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}" && continue
;;
2008-04-09 04:55:48 +05:30
esac
rm -f -- "${x}"
done
eend 0
fi
# Clean up /tmp directories
2007-11-20 17:50:50 +05:30
local tmp=
for tmp in ${wipe_tmp_dirs-/tmp}; do
cleanup_tmp_dir "${tmp}"
done
2008-04-09 04:55:48 +05:30
if dir_writeable /tmp; then
# 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
if ${logw} || dir_writeable /var/log; then
# Create an 'after-boot' dmesg log
if [ "${RC_SYS}" != "VSERVER" -a "${RC_SYS}" != "OPENVZ" ]; then
dmesg > /var/log/dmesg
chmod 640 /var/log/dmesg
fi
2007-04-26 19:52:54 +05:30
fi
2008-01-11 04:52:46 +05:30
rm -f /etc/nologin
2008-04-09 05:36:50 +05:30
return 0
}
stop()
{
# Write a halt record if we're shutting down
case "${RC_RUNLEVEL}" in
2007-10-27 15:23:56 +05:30
reboot|shutdown) [ "${RC_UNAME}" = "Linux" ] && halt -w;;
esac
return 0
}