openrc/init.d/bootmisc.in

172 lines
3.8 KiB
Plaintext
Raw Normal View History

#!@PREFIX@/sbin/runscript
2009-05-01 15:11:40 +01:00
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
depend()
{
need localmount
before logger
after clock sysctl
keyword -prefix
}
2008-04-08 23:25:48 +00:00
dir_writeable()
{
mkdir "$1"/.test.$$ 2>/dev/null && rmdir "$1"/.test.$$
}
2009-04-27 07:51:18 +00:00
: ${wipe_tmp:=${WIPE_TMP:-yes}}
cleanup_tmp_dir()
{
2008-04-09 00:06:50 +00:00
local dir="$1"
2009-04-27 07:51:18 +00:00
if ! [ -d "$dir" ]; then
mkdir -p "$dir" || return $?
2008-04-08 23:25:48 +00:00
fi
2009-04-27 07:51:18 +00:00
dir_writeable "$dir" || return 1
chmod a+rwt "$dir"
2009-04-27 07:51:18 +00:00
cd "$dir"
if yesno $wipe_tmp; then
ebegin "Wiping $dir directory"
local startopts="-x . -depth"
2009-04-27 07:51:18 +00:00
[ "$RC_UNAME" = Linux ] && startopts=". -xdev -depth"
# Faster than find
rm -rf -- [^ajlq\.]*
# pam_mktemp creates a .private directory within which
# each user gets a private directory with immutable
# bit set; remove the immutable bit before trying to
# remove it.
[ -d /tmp/.private ] && chattr -R -a /tmp/.private
2009-04-27 07:51:18 +00:00
find $startopts ! -name . \
2008-03-18 08:19:29 +00:00
! -path "./lost+found" \
! -path "./lost+found/*" \
2008-03-18 08:19:29 +00:00
! -path "./quota.user" \
! -path "./quota.user/*" \
2008-03-18 08:19:29 +00:00
! -path "./aquota.user" \
! -path "./aquota.user/*" \
2008-03-18 08:19:29 +00:00
! -path "./quota.group" \
! -path "./quota.group/*" \
2008-03-18 08:19:29 +00:00
! -path "./aquota.group" \
! -path "./aquota.group/*" \
2008-03-18 08:19:29 +00:00
! -path "./journal" \
! -path "./journal/*" \
-exec rm -rf {} \;
eend 0
else
2009-04-27 07:51:18 +00:00
ebegin "Cleaning $dir directory"
rm -rf -- "$dir"/.X*-lock "$dir"/esrv* "$dir"/kio* \
"$dir"/jpsock.* "$dir"/.fam* "$dir"/.esd* \
"$dir"/orbit-* "$dir"/ssh-* "$dir"/ksocket-* \
"$dir"/.*-unix
eend 0
fi
}
2009-04-16 23:39:37 +00:00
mkutmp()
{
: >"$1"
2009-04-18 00:56:48 +00:00
# Not all systems have the utmp group
chgrp utmp "$1" 2>/dev/null
2009-04-16 23:39:37 +00:00
chmod 0664 "$1"
}
start()
{
2009-04-27 07:51:18 +00:00
# Remove any added console dirs
rm -rf "$RC_LIBEXECDIR"/console
2009-04-27 07:51:18 +00:00
local logw=false runw=false extra=
# Ensure that our basic dirs exist
[ "$RC_UNAME" = Linux ] && extra=/var/lib/misc # Satisfy Linux FHS
for x in /var/log /var/run /tmp $extra; do
2009-04-27 07:51:18 +00:00
if ! [ -d $x ]; then
if ! mkdir -p $x; then
eend 1 "failed to create needed directory $x"
return 1
fi
fi
done
2008-04-08 23:25:48 +00:00
if dir_writeable /var/run; then
ebegin "Creating user login records"
2009-04-16 23:39:37 +00:00
local xtra=
2009-04-27 07:51:18 +00:00
[ "$RC_UNAME" = NetBSD ] && xtra=x
2009-04-16 23:39:37 +00:00
for x in "" $xtra; do
2009-04-27 07:51:18 +00:00
mkutmp /var/run/utmp$x
2009-04-16 23:39:37 +00:00
done
[ -e /var/log/wtmp ] || mkutmp /var/log/wtmp
2008-04-08 23:25:48 +00:00
eend 0
ebegin "Cleaning /var/run"
for x in $(find /var/run ! -type d ! -name utmp \
2008-05-12 15:11:04 +00:00
! -name random-seed ! -name dev.db \
2008-04-08 23:25:48 +00:00
! -name ld-elf.so.hints ! -name ld.so.hints);
2008-10-01 21:12:54 +00:00
do
# Clean stale sockets
2009-04-27 07:51:18 +00:00
if [ -S "$x" ]; then
2008-10-15 08:35:21 +00:00
if type fuser >/dev/null 2>&1; then
fuser "$x" >/dev/null 2>&1 || rm -- "$x"
2008-10-15 08:35:21 +00:00
else
2009-04-27 07:51:18 +00:00
rm -- "$x"
2008-10-15 08:35:21 +00:00
fi
2008-10-01 21:12:54 +00:00
fi
2009-04-27 07:51:18 +00:00
[ ! -f "$x" ] && continue
2008-04-08 23:25:48 +00:00
# Do not remove pidfiles of already running daemons
2009-04-27 07:51:18 +00:00
case "$x" in
2008-04-08 23:25:48 +00:00
*.pid)
start-stop-daemon --test --quiet \
2009-04-27 07:51:18 +00:00
--stop --pidfile "$x" && continue
;;
2008-04-08 23:25:48 +00:00
esac
2009-04-27 07:51:18 +00:00
rm -f -- "$x"
2008-04-08 23:25:48 +00:00
done
eend 0
fi
# Clean up /tmp directories
2007-11-20 12:20:50 +00:00
local tmp=
for tmp in ${clean_tmp_dirs:-${wipe_tmp_dirs-/tmp}}; do
2009-04-27 07:51:18 +00:00
cleanup_tmp_dir "$tmp"
done
2008-04-08 23:25:48 +00:00
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
2009-04-27 07:51:18 +00:00
if [ -x /sbin/restorecon ]; then
restorecon /tmp/.ICE-unix /tmp/.X11-unix
fi
2008-04-08 23:25:48 +00:00
fi
2009-04-27 07:51:18 +00:00
if $logw || dir_writeable /var/log; then
2008-04-08 23:25:48 +00:00
# Create an 'after-boot' dmesg log
2009-04-27 07:51:18 +00:00
if [ "$RC_SYS" != VSERVER -a "$RC_SYS" != OPENVZ ]; then
2008-04-08 23:25:48 +00:00
dmesg > /var/log/dmesg
chmod 640 /var/log/dmesg
fi
2007-04-26 14:22:54 +00:00
fi
2008-01-10 23:22:46 +00:00
[ -w /etc/nologin ] && rm -f /etc/nologin
2008-04-09 00:06:50 +00:00
return 0
}
stop()
{
# Write a halt record if we're shutting down
2009-04-27 07:51:18 +00:00
if [ "$RC_RUNLEVEL" = shutdown ]; then
[ "$RC_UNAME" = Linux ] && halt -w
if [ "$RC_SYS" = OPENVZ ]; then
yesno $RC_REBOOT && printf "" >/reboot
fi
fi
return 0
}