Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6456ba7d3 | ||
|
|
a101cfe1c0 | ||
|
|
843c8721f1 | ||
|
|
7de71fa1cd | ||
|
|
97906ebe04 | ||
|
|
8d4cb9e335 | ||
|
|
aa612e0add | ||
|
|
008c9f186a | ||
|
|
f977ad5793 | ||
|
|
c635cf014c | ||
|
|
17afdf7765 |
4
CONFIG/etc/fstab
Normal file
4
CONFIG/etc/fstab
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# /etc/fstab - file system mount definitions
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <fsck>
|
||||
12
Makefile
12
Makefile
@@ -8,16 +8,17 @@
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
DEPENDS = bash,iftools,kmod,procps-ng,sysvinit
|
||||
DEPENDS = dash,grep,kmod,perl,procps-ng,sed,sysvinit
|
||||
ARCH = x86_64
|
||||
URL =
|
||||
URL = http://snaplinux.org
|
||||
REPO = core
|
||||
BRIEF = Base scripts for sysvinit
|
||||
DESC = This package supplies the base system init scripts for sysvinit
|
||||
DESC = This package supplies the core required init scripts for startup
|
||||
|
||||
ARCHIVE := ''
|
||||
SRCDIR := $(PWD)/SRC/initscripts
|
||||
PATCHDIR := $(PWD)/SRC/patches
|
||||
VERSION := 1.0-0
|
||||
VERSION := 1.10-0
|
||||
|
||||
include /usr/share/snap/Makefile.snaplinux
|
||||
|
||||
@@ -34,5 +35,6 @@ clean:
|
||||
@rm -rvf $(ROOT) \
|
||||
$(SNAPINFO) \
|
||||
$(MANIFEST) \
|
||||
$(FILES)
|
||||
$(FILES) \
|
||||
$(CONFIG)
|
||||
|
||||
|
||||
21
SNAP/usher
21
SNAP/usher
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
@@ -7,26 +7,7 @@ case $1 in
|
||||
exit 0
|
||||
;;
|
||||
postinst)
|
||||
if [[ ${TARGET} ]]; then
|
||||
chroot ${TARGET} 'update-rc required'
|
||||
else
|
||||
update-rc required
|
||||
fi
|
||||
|
||||
if [ ! -f ${TARGET}/etc/modules.conf ]; then
|
||||
cp ${TARGET}/usr/share/initscripts/modules.conf \
|
||||
${TARGET}/etc/modules.conf
|
||||
fi
|
||||
|
||||
if [ ! -f ${TARGET}/etc/default/halt ]; then
|
||||
cp ${TARGET}/usr/share/initscripts/halt.default \
|
||||
${TARGET}/etc/default/halt
|
||||
fi
|
||||
|
||||
if [ ! -f ${TARGET}/etc/default/rcS ]; then
|
||||
cp ${TARGET}/usr/share/initscripts/rcS.default \
|
||||
${TARGET}/etc/default/rcS
|
||||
fi
|
||||
;;
|
||||
prerm)
|
||||
exit 0
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
dirs:
|
||||
install -d -m 755 $(DESTDIR)/etc/default
|
||||
install -d -m 755 $(DESTDIR)/etc/{rc{{0..6},S},init}.d
|
||||
install -d -m 755 $(DESTDIR)/etc/init.d
|
||||
install -d -m 755 $(DESTDIR)/etc/modprobe.d
|
||||
install -d -m 755 $(DESTDIR)/lib/lsb
|
||||
install -d -m 755 $(DESTDIR)/usr/share/initscripts
|
||||
install -d -m 755 $(DESTDIR)/usr/share/man/man8
|
||||
install -d -m 755 $(DESTDIR)/sbin
|
||||
install -d -m 755 $(DESTDIR)/usr/sbin
|
||||
for rl in S 0 1 2 3 4 5 6; do \
|
||||
install -d -m 755 $(DESTDIR)/etc/rc$$rl.d; \
|
||||
done
|
||||
|
||||
files:
|
||||
install -m 755 init.d/checkfs $(DESTDIR)/etc/init.d/checkfs
|
||||
install -m 755 init.d/cleanfs $(DESTDIR)/etc/init.d/cleanfs
|
||||
install -m 755 init.d/halt $(DESTDIR)/etc/init.d/halt
|
||||
install -m 755 init.d/hostname $(DESTDIR)/etc/init.d/hostname
|
||||
install -m 755 init.d/hwclock $(DESTDIR)/etc/init.d/hwclock
|
||||
install -m 755 init.d/localnet $(DESTDIR)/etc/init.d/localnet
|
||||
install -m 755 init.d/modules $(DESTDIR)/etc/init.d/modules
|
||||
install -m 755 init.d/mountfs $(DESTDIR)/etc/init.d/mountfs
|
||||
install -m 755 init.d/mountvirtfs $(DESTDIR)/etc/init.d/mountvirtfs
|
||||
install -m 755 init.d/rc $(DESTDIR)/etc/init.d/rc
|
||||
install -m 755 init.d/reboot $(DESTDIR)/etc/init.d/reboot
|
||||
install -m 755 init.d/sendsignals $(DESTDIR)/etc/init.d/sendsignals
|
||||
install -m 755 init.d/swap $(DESTDIR)/etc/init.d/swap
|
||||
install -m 755 init.d/sysctl $(DESTDIR)/etc/init.d/sysctl
|
||||
for f in init.d/*; do \
|
||||
install -m 755 $$f $(DESTDIR)/etc/init.d; \
|
||||
done
|
||||
install -m 755 init-functions $(DESTDIR)/lib/lsb/init-functions
|
||||
install -m 644 halt.default \
|
||||
$(DESTDIR)/usr/share/initscripts/halt.default
|
||||
install -m 644 modules.conf \
|
||||
$(DESTDIR)/usr/share/initscripts/modules.conf
|
||||
install -m 644 rcS.default \
|
||||
$(DESTDIR)/usr/share/initscripts/rcS.default
|
||||
install -m 755 update-rc $(DESTDIR)/sbin
|
||||
install -m 755 update-rc $(DESTDIR)/usr/sbin
|
||||
install -m 755 service $(DESTDIR)/usr/sbin
|
||||
|
||||
install: dirs files
|
||||
|
||||
75
SRC/initscripts/init-functions
Normal file → Executable file
75
SRC/initscripts/init-functions
Normal file → Executable file
@@ -1,4 +1,19 @@
|
||||
#!/bin/sh
|
||||
# /lib/lsb/init-functions - shell functions and variables for init scripts
|
||||
|
||||
#
|
||||
# This sets some environment variables that init scripts can use
|
||||
# to determine if we're running in a container
|
||||
#
|
||||
# Most likely just checking for the presence of $container would
|
||||
# be enough
|
||||
#
|
||||
|
||||
if [ -r /proc/1/environ ]; then
|
||||
chkcontainer=$(sed 's/\x0/\n/g' < /proc/1/environ|grep -ia '^container\|^LXC')
|
||||
fi
|
||||
|
||||
[ -n "$chkcontainer" ] && export $chkcontainer
|
||||
[ -z "$NAME" ] && NAME=${0##*/}
|
||||
|
||||
COL52="\\033[52G"
|
||||
|
||||
@@ -17,13 +32,13 @@ killproc() {
|
||||
;;
|
||||
*)
|
||||
pathname="$1"
|
||||
signal="$2"
|
||||
[ -n "$2" ] && signal="$2"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -r "$pidfile" ] && pids=$(pidofproc -p "$pidfile" "$pathname")
|
||||
[ -r "$pidfile" ] && pids=$(pidofproc -p "$pidfile" "$pathname") || return 0
|
||||
[ -z "$pids" ] && pids=$(pidofproc "$pathname")
|
||||
[ -z "$pids" ] && [ -n "$signal" ] && return 1
|
||||
[ -z "$pids" ] && return 0
|
||||
@@ -53,20 +68,32 @@ log_init_msg() {
|
||||
echo -n "$1"
|
||||
}
|
||||
|
||||
log_begin_msg() {
|
||||
log_init_msg "$1"
|
||||
}
|
||||
|
||||
log_end_msg() {
|
||||
if [ "$1" = "0" ]; then
|
||||
log_success_msg
|
||||
else
|
||||
log_failure_msg
|
||||
fi
|
||||
}
|
||||
|
||||
log_failure_msg() {
|
||||
echo -e "$COL52[ FAIL ]"
|
||||
echo "$COL52[ FAIL ]"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log_success_msg() {
|
||||
echo -e "$COL52[ OK ]"
|
||||
echo "$COL52[ OK ]"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log_warning_msg() {
|
||||
echo -e "$COL52[ WARN ]"
|
||||
echo "$COL52[ WARN ]"
|
||||
|
||||
return
|
||||
}
|
||||
@@ -90,7 +117,13 @@ pidofproc() {
|
||||
esac
|
||||
done
|
||||
|
||||
[ -r "$pidfile" ] && pids=$(head -1 $pidfile) || pids=$(pidof $pathname)
|
||||
if [ -n "$pidfile" ] && [ ! -r "$pidfile" ]; then
|
||||
return 1
|
||||
elif [ -n "$pidfile" ]; then
|
||||
pids=$(head -1 $pidfile|sed 's/ \+//g')
|
||||
else
|
||||
pids=$(pidof "$pathname")
|
||||
fi
|
||||
|
||||
for pid in $pids; do
|
||||
kill -0 "$pid" 2>/dev/null && pidlist="$pidlist $pid "
|
||||
@@ -140,3 +173,31 @@ start_daemon() {
|
||||
nice -n "$nicelevel" "$pathname"
|
||||
}
|
||||
|
||||
status_of_proc() {
|
||||
local name pidfile pathname pids pidlist
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-p)
|
||||
pidfile="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
pathname="$1"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$pidfile" ]; then
|
||||
pid=$(pidofproc -p "$pidfile" "$pathname");
|
||||
else
|
||||
pid=$(pidofproc "$pathname")
|
||||
fi
|
||||
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "$NAME is not runing" && return 1
|
||||
else
|
||||
echo "$NAME running with PID: $pid"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: checkfs
|
||||
# Required-Start: udev swap $time hostname hwclock
|
||||
# Required-Start: checkroot hostname swap $time udev
|
||||
# Required-Stop:
|
||||
# Should-Start:
|
||||
# Should-Stop:
|
||||
@@ -12,36 +12,22 @@
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if [ -f /fastboot ] || grep -qwi 'fastboot' /proc/cmdline; then
|
||||
log_init_msg "Fastboot enabled - skipping file system checks"
|
||||
log_init_msg "Fastboot enabled - skipping fsck"
|
||||
log_success_msg
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log_init_msg "Mounting root file system in read-only mode"
|
||||
mount -n -o remount,ro / >/dev/null
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
log_failure_msg
|
||||
echo
|
||||
echo "Failed to mount root filesystem in read-only mode."
|
||||
echo
|
||||
echo "Press Enter to halt"
|
||||
read
|
||||
/etc/init.d/halt stop
|
||||
else
|
||||
log_success_msg
|
||||
fi
|
||||
|
||||
if [ -f /forcefsck ] || grep -qwi 'forcefsck' /proc/cmdline; then
|
||||
checking='Checking file systems with force'
|
||||
log_init_msg "Checking file systems with force"
|
||||
force='-f'
|
||||
else
|
||||
checking='Checking file systems'
|
||||
log_init_msg 'Checking file systems'
|
||||
fi
|
||||
|
||||
case "$FSCKFIX" in
|
||||
@@ -49,44 +35,31 @@ case "$1" in
|
||||
fix='-y'
|
||||
;;
|
||||
*)
|
||||
fix='-a'
|
||||
fix='-p'
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$VERBOSE" in
|
||||
1|y|yes)
|
||||
echo
|
||||
echo "$checking"
|
||||
fsck $force $fix -A -C -T
|
||||
fsck $force $fix -A -C -T -R
|
||||
;;
|
||||
*)
|
||||
log_init_msg "$checking"
|
||||
fsck $force $fix -A -T >/dev/null
|
||||
fsck $force $fix -A -T -R >/dev/null
|
||||
;;
|
||||
esac
|
||||
|
||||
status=$?
|
||||
|
||||
case "$VERBOSE" in
|
||||
1|y|yes)
|
||||
echo
|
||||
if [ $status == 0 ]; then
|
||||
exit 0
|
||||
else
|
||||
log_init_msg "Filesystem issues detected"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $status == 0 ]; then
|
||||
if [ $status = 0 ]; then
|
||||
log_success_msg
|
||||
elif [ $status != 1 ]; then
|
||||
elif [ $status = 1 ]; then
|
||||
log_warning_msg
|
||||
|
||||
echo
|
||||
echo "WARNING: File system errors were detected and repaired."
|
||||
echo
|
||||
elif [ $status == 2 -o $status == 3 ]; then
|
||||
elif [ $status = 2 -o $status = 3 ]; then
|
||||
log_warning_msg
|
||||
|
||||
echo
|
||||
@@ -94,7 +67,7 @@ case "$1" in
|
||||
echo "The repairs require the system to be rebooted."
|
||||
echo
|
||||
echo "Press enter to reboot"
|
||||
read
|
||||
read reboot
|
||||
reboot -f
|
||||
elif [ $status -gt 3 -a $status -lt 16 ]; then
|
||||
log_failure_msg
|
||||
@@ -104,7 +77,7 @@ case "$1" in
|
||||
echo "repaired automatically."
|
||||
echo
|
||||
echo "Press enter to halt"
|
||||
read
|
||||
read halt
|
||||
/etc/init.d/halt stop
|
||||
else
|
||||
log_failure_msg
|
||||
@@ -112,7 +85,9 @@ case "$1" in
|
||||
echo
|
||||
echo "fsck exited with unexpected status: $status"
|
||||
echo
|
||||
exit $status
|
||||
echo "Press enter to halt"
|
||||
read halt
|
||||
/etc/init.d/halt stop
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
|
||||
136
SRC/initscripts/init.d/checkroot
Executable file
136
SRC/initscripts/init.d/checkroot
Executable file
@@ -0,0 +1,136 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: checkroot
|
||||
# Required-Start: hostname mountvirtfs
|
||||
# Required-Stop:
|
||||
# Should-Start:
|
||||
# Should-Stop:
|
||||
# Default-Start: S
|
||||
# Default-Stop:
|
||||
# Short-Description: Check root filesystem for errors
|
||||
# X-Required: true
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if [ -f /fastboot ] || grep -qwi 'fastboot' /proc/cmdline; then
|
||||
log_init_msg "Fastboot enabled - skipping root fsck"
|
||||
log_success_msg
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -f /forcefsck ] || grep -qwi 'forcefsck' /proc/cmdline; then
|
||||
log_init_msg "Checking root file system with force"
|
||||
force='-f'
|
||||
else
|
||||
log_init_msg "Checking root file system"
|
||||
fi
|
||||
|
||||
rootdev="/dev/$(lsblk -l -o NAME,MOUNTPOINT|grep '\/$'|sed 's/ .*//')"
|
||||
mount -n -o remount,ro $rootdev / >/dev/null
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
log_failure_msg
|
||||
echo
|
||||
echo "Failed to mount root filesystem read-only."
|
||||
echo
|
||||
echo "Press Enter to halt"
|
||||
read
|
||||
/etc/init.d/halt stop
|
||||
fi
|
||||
|
||||
case "$FSCKFIX" in
|
||||
1|y|yes)
|
||||
fix='-y'
|
||||
;;
|
||||
*)
|
||||
fix='-p'
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$VERBOSE" in
|
||||
1|y|yes)
|
||||
echo
|
||||
fsck $force $fix -C -T $rootdev
|
||||
;;
|
||||
*)
|
||||
fsck $force $fix -T $rootdev >/dev/null
|
||||
;;
|
||||
esac
|
||||
|
||||
status=$?
|
||||
|
||||
if [ $status = 0 ]; then
|
||||
mount -n -o remount,rw $rootdev / >/dev/null
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
log_failure_msg
|
||||
echo
|
||||
echo "Failed to mount root filesystem read-write."
|
||||
echo
|
||||
echo "Press Enter to halt"
|
||||
read
|
||||
/etc/init.d/halt stop
|
||||
else
|
||||
log_success_msg
|
||||
fi
|
||||
elif [ $status = 1 ]; then
|
||||
mount -n -o remount,rw $rootdev / >/dev/null
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
log_failure_msg
|
||||
echo
|
||||
echo "Failed to mount root filesystem read-write."
|
||||
echo
|
||||
echo "Press Enter to halt"
|
||||
read
|
||||
/etc/init.d/halt stop
|
||||
else
|
||||
log_warning_msg
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "WARNING: Root file system errors were detected and repaired."
|
||||
echo
|
||||
elif [ $status = 2 -o $status = 3 ]; then
|
||||
log_warning_msg
|
||||
|
||||
echo
|
||||
echo "WARNING: Root file system errors were detected and repaired."
|
||||
echo "The repairs require the system to be rebooted."
|
||||
echo
|
||||
echo "Press enter to reboot"
|
||||
read reboot
|
||||
reboot -f
|
||||
elif [ $status -gt 3 -a $status -lt 16 ]; then
|
||||
log_failure_msg
|
||||
|
||||
echo
|
||||
echo "Root file system errors were detected, but could not be"
|
||||
echo "repaired automatically."
|
||||
echo
|
||||
echo "Press enter to halt"
|
||||
read halt
|
||||
/etc/init.d/halt stop
|
||||
else
|
||||
log_failure_msg
|
||||
|
||||
echo
|
||||
echo "fsck exited with unexpected status: $status"
|
||||
echo
|
||||
echo "Press enter to halt"
|
||||
read halt
|
||||
/etc/init.d/halt stop
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [start]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
[ -z "$CLEANDIRS" ] && exit 0
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
clean() {
|
||||
[ -d $1 ] || return 1
|
||||
@@ -23,6 +24,16 @@ clean() {
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if [ -f /fastboot ]; then
|
||||
log_init_msg "Clearing /fastboot"
|
||||
rm /fastboot && log_success_msg || log_failure_msg
|
||||
fi
|
||||
|
||||
if [ -f /forcefsck ]; then
|
||||
log_init_msg "Clearing /forcefsck"
|
||||
rm /forcefsck && log_success_msg || log_failure_msg
|
||||
fi
|
||||
|
||||
log_init_msg "Cleaning temporary files"
|
||||
|
||||
for dir in $CLEANDIRS; do
|
||||
|
||||
@@ -19,11 +19,11 @@ case "$1" in
|
||||
poweroff='-p'
|
||||
netdown='-i'
|
||||
|
||||
if [ "$HALT" == "halt" ]; then
|
||||
if [ "$HALT" = "halt" ]; then
|
||||
poweroff=''
|
||||
fi
|
||||
|
||||
if [ "$NETDOWN" == "no" ]; then
|
||||
if [ "$NETDOWN" = "no" ]; then
|
||||
netdown=''
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: hostname
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop: $local_fs
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Should-Start:
|
||||
# Should-Stop
|
||||
# Default-Start: S
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: hwclock
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Required-Start: mountvirtfs
|
||||
# Required-Stop: $local_fs
|
||||
# Should-Start: modules
|
||||
# Should-Stop: $syslog
|
||||
# Default-Start: S
|
||||
# Default-Stop: 0 6
|
||||
# X-Start-Before: checkroot
|
||||
# Short-Description: Synchronize the system and hardware clocks
|
||||
# Description: During boot sync the hardware clock to the
|
||||
# system clock if udev is not running. During
|
||||
@@ -15,6 +16,8 @@
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
[ -r /etc/default/rcS ] && . /etc/default/rcS
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$UTC" in
|
||||
0|n|no)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: localnet
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop: $local_fs
|
||||
# Should-Start: $syslog
|
||||
# Should-Stop: $syslog
|
||||
# Default-Start: S
|
||||
# Default-Stop: 0 6
|
||||
# Short-Description: Start and configure loopback interface
|
||||
# X-Required: true
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_init_msg "Bringing up loopback interface"
|
||||
ifup lo && log_success_msg || log_failure_msg
|
||||
;;
|
||||
stop)
|
||||
log_init_msg "Bringing down loopback interface"
|
||||
ifdown lo && log_success_msg || log_failure_msg
|
||||
;;
|
||||
|
||||
reload|restart)
|
||||
log_init_msg "Restarting loopback interface"
|
||||
ifreload lo && log_success_msg || log_failure_msg
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 [start|stop|reload|restart]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
@@ -15,6 +15,7 @@ CONF=/etc/modules.conf
|
||||
|
||||
[ -r $CONF ] || exit 0
|
||||
[ -e /proc/modules ] || exit 0
|
||||
[ -z $container ] || exit 0
|
||||
egrep -qv '^(\s*#|$)' $CONF || exit 0
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
@@ -1,81 +1,35 @@
|
||||
#!/bin/sh
|
||||
########################################################################
|
||||
# Begin mountfs
|
||||
#
|
||||
# Description : File System Mount Script
|
||||
#
|
||||
# Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
||||
# DJ Lucas - dj@linuxfromscratch.org
|
||||
# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
||||
#
|
||||
# Version : LFS 7.0
|
||||
#
|
||||
########################################################################
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: $local_fs
|
||||
# Required-Start: udev checkfs
|
||||
# Required-Start: udev checkfs checkroot
|
||||
# Should-Start:
|
||||
# Required-Stop: swap
|
||||
# Should-Stop:
|
||||
# Default-Start: S
|
||||
# Default-Stop: 0 6
|
||||
# Short-Description: Mounts/unmounts local filesystems defined in /etc/fstab.
|
||||
# Short-Description: Mounts/unmounts local filesystems
|
||||
# Description: Remounts root filesystem read/write and mounts all
|
||||
# remaining local filesystems defined in /etc/fstab on
|
||||
# start. Remounts root filesystem read-only and unmounts
|
||||
# remaining filesystems on stop.
|
||||
# X-LFS-Provided-By: LFS
|
||||
# remaining local filesystems defined in /etc/fstab
|
||||
# During stop remounts root filesystem read-only and
|
||||
# unmounts remaining filesystems.
|
||||
# X-Required: true
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
#
|
||||
# needs work!!
|
||||
# probably need to split up
|
||||
# separate scripts for / and
|
||||
# network filesystems
|
||||
#
|
||||
# Ok, so network filesystems
|
||||
# init scripts should be included
|
||||
# as part of the package. This
|
||||
# script should only be for
|
||||
# standard local filesystems
|
||||
#
|
||||
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_init_msg "Remounting root file system in read-write mode"
|
||||
mount -o remount,rw / >/dev/null && log_success_msg || log_failure_msg
|
||||
|
||||
# Remove fsck-related file system watermarks.
|
||||
rm -f /fastboot /forcefsck
|
||||
|
||||
# Make sure /dev/pts exists
|
||||
# mkdir -p /dev/pts
|
||||
|
||||
# This will mount all filesystems that do not have _netdev in
|
||||
# their option list. _netdev denotes a network filesystem.
|
||||
|
||||
log_init_msg "Mounting remaining file systems"
|
||||
log_init_msg "Mounting local file systems"
|
||||
mount -a -O no_netdev >/dev/null && log_success_msg || log_failure_msg
|
||||
exit $failed
|
||||
;;
|
||||
stop)
|
||||
# Don't unmount virtual file systems like /run
|
||||
log_init_msg "Unmounting all file systems"
|
||||
umount -a -d -r -t notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts >/dev/null && \
|
||||
log_success_msg || log_failure_msg
|
||||
log_init_msg "Unmounting local file systems"
|
||||
umount -a -d -r -t notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts \
|
||||
>/dev/null && log_success_msg || log_failure_msg
|
||||
|
||||
# Make sure / is mounted read only (umount bug)
|
||||
mount -o remount,ro /
|
||||
|
||||
# Make all LVM volume groups unavailable, if appropriate
|
||||
# This fails if swap or / are on an LVM partition
|
||||
#if [ -x /sbin/vgchange ]; then /sbin/vgchange -an > /dev/null; fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [start|stop]"
|
||||
|
||||
34
SRC/initscripts/init.d/mountnetfs
Executable file
34
SRC/initscripts/init.d/mountnetfs
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: $remote_fs
|
||||
# Required-Start: $local_fs $network $portmap
|
||||
# Should-Start:
|
||||
# Required-Stop:
|
||||
# Should-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Mounts remote filesystems
|
||||
# Description: Mounts only those filesystems labelled _netdev in
|
||||
# /etc/fstab. umountfs should handle the unmounting
|
||||
# X-Required: true
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_init_msg "Mounting remote file systems"
|
||||
mount -a -O _netdev >/dev/null && log_success_msg || log_failure_msg
|
||||
;;
|
||||
stop)
|
||||
# No-op
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [start|stop]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
@@ -3,7 +3,7 @@
|
||||
# Provides: mountvirtfs
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Should-Start:
|
||||
# Should-Start: udev
|
||||
# Should-Stop:
|
||||
# Default-Start: S
|
||||
# Default-Stop:
|
||||
@@ -80,14 +80,6 @@ mountrun () {
|
||||
/run || return 1
|
||||
fi
|
||||
|
||||
mkdir -p /run/lock /run/shm || return 1
|
||||
chmod 1777 /run/shm || return 1
|
||||
|
||||
if grep -q '^utmp:' /etc/group; then
|
||||
chmod 664 /run/utmp
|
||||
chgrp utmp /run/utmp
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -105,12 +97,21 @@ case "$1" in
|
||||
start|restart)
|
||||
log_init_msg "Mounting virtual file systems"
|
||||
|
||||
if [ -z $container ]; then
|
||||
for dir in dev pts proc run sys; do
|
||||
mount$dir || error=1
|
||||
done
|
||||
fi
|
||||
|
||||
mkdir -p /run/lock /run/shm || error=1
|
||||
chmod 1777 /run/shm || error=1
|
||||
ln -sfn /run/shm /dev/shm
|
||||
|
||||
if grep -q '^utmp:' /etc/group; then
|
||||
chmod 664 /run/utmp >> /run/utmp
|
||||
chgrp utmp /run/utmp
|
||||
fi
|
||||
|
||||
[ -z $error ] && log_success_msg || log_failure_msg
|
||||
;;
|
||||
status)
|
||||
|
||||
@@ -22,11 +22,11 @@ print_snap() {
|
||||
|
||||
case "$1" in
|
||||
S|1|2|3|4|5|6|0)
|
||||
if [ "$RUNLEVEL" == "S" ]; then
|
||||
if [ "$RUNLEVEL" = "S" ]; then
|
||||
set -a
|
||||
[ -r /etc/default/rcS ] && . /etc/default/rcS
|
||||
set +a
|
||||
dmesg -n "${LOGLEVEL:-7}"
|
||||
[ -z $container ] && dmesg -n "${LOGLEVEL:-7}"
|
||||
print_snap
|
||||
fi
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
case "$1" in
|
||||
stop)
|
||||
log_init_msg "Restarting system"
|
||||
echo "Restarting system"
|
||||
reboot -d -f -i
|
||||
;;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
### BEGIN INIT INFO
|
||||
# Provides: swap
|
||||
# Required-Start: udev
|
||||
# Required-Stop:
|
||||
# Required-Stop: mountfs
|
||||
# Should-Start: modules
|
||||
# Should-Stop:
|
||||
# Default-Start: S
|
||||
@@ -12,6 +12,8 @@
|
||||
### END INIT INFO
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
[ -r /etc/fstab ] || exit 0
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
CONF=/etc/sysctl.conf
|
||||
[ -r $CONF ] || exit 0
|
||||
[ -z $container ] || exit 0
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
@@ -22,7 +23,7 @@ case "$1" in
|
||||
sysctl -q -p && log_success_msg || log_failed_msg
|
||||
;;
|
||||
status)
|
||||
grep -v '^#' $CONF | while IFS= read -r line; do
|
||||
grep -v '^#\|^$' $CONF | while IFS= read -r line; do
|
||||
param=`echo -n $line|sed 's/\s\+=.*//'`
|
||||
realval=`sysctl $param|sed 's/.*=\s\+//'`
|
||||
|
||||
|
||||
11
SRC/initscripts/service
Executable file
11
SRC/initscripts/service
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# A simple wrapper for /etc/init.d scripts
|
||||
|
||||
SERVICEDIR="/etc/init.d"
|
||||
SERVICE=${1}
|
||||
|
||||
[ -x "${SERVICEDIR}/${SERVICE}" ] && exec "${SERVICEDIR}/${SERVICE}" $2
|
||||
|
||||
echo "${SERVICE}: unrecognized service"
|
||||
exit 1
|
||||
@@ -5,10 +5,22 @@ use strict;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
use constant COMMANDS => qw( disable enable required status );
|
||||
use constant INITDIR => '/etc/init.d';
|
||||
use constant RUNLEVELS => qw( S 1 2 3 4 5 6 0 );
|
||||
use constant SVCKEYS => qw( Provides Required-Start Required-Stop Should-Start
|
||||
Should-Stop Default-Start Default-Stop Short-Description Description );
|
||||
use constant SVCKEYS => qw(
|
||||
Provides
|
||||
Required-Start
|
||||
Required-Stop
|
||||
Should-Start
|
||||
Should-Stop
|
||||
X-Start-Before
|
||||
X-Start-After
|
||||
Default-Start
|
||||
Default-Stop
|
||||
Short-Description
|
||||
Description
|
||||
);
|
||||
use constant VERBOSE => eval {
|
||||
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||
if ( $ARGV[$i] eq '-v' || $ARGV[$i] eq '--verbose' ) {
|
||||
@@ -21,25 +33,56 @@ use constant VERBOSE => eval {
|
||||
return( 0 );
|
||||
};
|
||||
|
||||
sub chkstatus {
|
||||
my $svcname = shift;
|
||||
my $status = {};
|
||||
sub enable {
|
||||
my $service = shift || error( -1, "enable(): service not provided" );
|
||||
my $services = shift || error( -1, "enable(): services not provided" );
|
||||
|
||||
foreach my $rlvl ( RUNLEVELS ) {
|
||||
my $dir = "/etc/rc$rlvl.d";
|
||||
|
||||
opendir( DIR, $dir );
|
||||
|
||||
while ( readdir( DIR ) ) {
|
||||
if ( $_ =~ /^([KS])(\d+)$svcname$/ ) {
|
||||
$status->{$rlvl} = $1;
|
||||
}
|
||||
if ( $service->{'enabled'} ) {
|
||||
return;
|
||||
}
|
||||
|
||||
close( DIR );
|
||||
if ( VERBOSE ) {
|
||||
print "Enabling $service->{'name'}\n";
|
||||
}
|
||||
|
||||
return( $status );
|
||||
foreach my $rlvl ( @{$service->{'Default-Stop'}} ) {
|
||||
$service->{'rlvls'}{$rlvl} = 'K';
|
||||
}
|
||||
foreach my $rlvl ( @{$service->{'Default-Start'}} ) {
|
||||
$service->{'rlvls'}{$rlvl} = 'S';
|
||||
}
|
||||
|
||||
$service->{'enabled'} = 1;
|
||||
|
||||
if ( ! $service->{'Required-Start'} ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach my $svc ( keys( %{$services} ) ) {
|
||||
if ( grep( $_ eq $svc, @{$service->{'Required-Start'}} ) &&
|
||||
! $services->{$svc}{'enabled'} ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service->{'name'} requires $svc\n";
|
||||
}
|
||||
|
||||
enable( $services->{$svc}, $services );
|
||||
}
|
||||
elsif ( ref( $services->{$svc}{'Provides'} ) eq 'ARRAY' &&
|
||||
! $services->{$svc}{'enabled'} ) {
|
||||
foreach my $provides (
|
||||
@{$services->{$svc}{'Provides'}} ) {
|
||||
if ( grep( $_ eq $provides,
|
||||
@{$service->{'Required-Start'}} ) ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service->{'name'}"
|
||||
. " requires $svc\n";
|
||||
}
|
||||
|
||||
enable( $services->{$svc}, $services );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub error {
|
||||
@@ -47,12 +90,13 @@ sub error {
|
||||
my $errstr = shift;
|
||||
my $level = 1;
|
||||
my @stack = ();
|
||||
( my $self = ( caller() )[1] ) =~ s/.*\///;
|
||||
|
||||
chomp( $errstr );
|
||||
|
||||
print "\n";
|
||||
|
||||
print STDERR ( caller() )[1] .":\n $errstr at line "
|
||||
print STDERR "$self:\n $errstr at line "
|
||||
. ( caller() )[2] . "\n";
|
||||
|
||||
if ( VERBOSE ) {
|
||||
@@ -73,67 +117,118 @@ sub error {
|
||||
}
|
||||
}
|
||||
|
||||
sub kdepends {
|
||||
my $services = shift;
|
||||
my $service = shift;
|
||||
my $kdepends = shift || [];
|
||||
my $stack = shift || [];
|
||||
sub getsvcrlvls {
|
||||
my $service = shift ||
|
||||
error( -1, "getsvcrlvls(): service not provided\n" );
|
||||
|
||||
if ( @$stack > 99 ) {
|
||||
return;
|
||||
}
|
||||
foreach my $rlvl ( RUNLEVELS ) {
|
||||
my $dir = "/etc/rc$rlvl.d";
|
||||
|
||||
push( @$stack, $service->{'name'} );
|
||||
opendir( my $dh, $dir ) ||
|
||||
error( int( $! ), "getsvcrlvls(): opendir(): $!" );
|
||||
|
||||
foreach my $svcname ( sort( keys( %{$services} ) ) ) {
|
||||
my $provides = $services->{$svcname}{'Provides'};
|
||||
|
||||
if ( $stack->[0] && grep( $_ eq $svcname, @$stack ) ) {
|
||||
while ( readdir( $dh ) ) {
|
||||
if ( ! -l "$dir/$_" ) {
|
||||
next;
|
||||
}
|
||||
|
||||
foreach my $required ( @{$service->{'Required-Stop'}} ) {
|
||||
if ( grep( $_ eq $required, @$provides ) ) {
|
||||
kdepends( $services, $services->{$svcname},
|
||||
$kdepends, $stack );
|
||||
my $link = readlink( "$dir/$_" ) ||
|
||||
error( int( $! ),
|
||||
"getsvcrlvls(): readlink(): $!" );
|
||||
( my $name = $link ) =~ s/.*\///;
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$kdepends ) ) {
|
||||
unshift( @$kdepends, $svcname );
|
||||
if ( $name eq $service->{'name'} &&
|
||||
$_ =~ /^([KS])(\d+)$service->{'name'}$/ ) {
|
||||
$service->{'rlvls'}{$rlvl} = $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach my $required ( @{$service->{'Should-Stop'}} ) {
|
||||
if ( grep( $_ eq $required, @$provides ) ) {
|
||||
kdepends( $services, $services->{$svcname},
|
||||
$kdepends );
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$kdepends ) ) {
|
||||
unshift( @$kdepends, $svcname );
|
||||
closedir( $dh );
|
||||
}
|
||||
}
|
||||
|
||||
sub korder {
|
||||
my $service = shift || error( -1, "korder(): service missing" );
|
||||
my $services = shift || error( -1, "korder(): services missing" );
|
||||
my $korder = shift || [];
|
||||
my $stack = shift || [];
|
||||
|
||||
if ( ( $stack->[0] && grep( $_ eq $service, @$stack ) ) ||
|
||||
( $korder->[0] && grep( $_->{'name'} eq $service, @$korder ) ) ||
|
||||
@$stack > 99 ) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
push( @$stack, $service );
|
||||
}
|
||||
|
||||
foreach my $svc ( sort( keys( %{$services} ) ) ) {
|
||||
if ( $service eq 'halt' || $service eq 'reboot' ) {
|
||||
korder( $svc, $services, $korder, $stack );
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
if ( ( $services->{$svc}{'X-Stop-After'} && grep( $_ eq
|
||||
$service, @{$services->{$svc}{'X-Stop-After'}} ) ) ||
|
||||
( $services->{$svc}{'Required-Stop'} && grep( $_ eq $service,
|
||||
@{$services->{$svc}{'Required-Stop'}} ) ) ||
|
||||
( $services->{$svc}{'Should-Stop'} && grep( $_ eq $service,
|
||||
@{$services->{$svc}{'Should-Stop'}} ) ) ) {
|
||||
korder( $svc, $services, $korder, $stack );
|
||||
}
|
||||
|
||||
if ( $services->{$service}{'Provides'} ) {
|
||||
foreach my $provides (
|
||||
@{$services->{$service}{'Provides'}} ) {
|
||||
if ( ( $services->{$svc}{'Required-Stop'} &&
|
||||
grep( $_ eq $provides,
|
||||
@{$services->{$svc}{'Required-Stop'}} ) ) ||
|
||||
( $services->{$svc}{'Should-Stop'} &&
|
||||
grep( $_ eq $provides,
|
||||
@{$services->{$svc}{'Should-Stop'}} ) ) ) {
|
||||
korder( $svc, $services, $korder,
|
||||
$stack );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return( $kdepends );
|
||||
push( @$korder, $services->{$service} );
|
||||
}
|
||||
|
||||
sub readinfo {
|
||||
sub readlsb {
|
||||
my $file = shift;
|
||||
my $begin = 0;
|
||||
my $prev;
|
||||
my $service = {
|
||||
my $lsb = {
|
||||
'Provides' => [],
|
||||
'Required-Start' => [],
|
||||
'Required-Stop' => [],
|
||||
'Should-Start' => [],
|
||||
'Should-Stop' => [],
|
||||
'X-Start-Before' => [],
|
||||
'X-Stop-After' => [],
|
||||
'Default-Start' => [],
|
||||
'Default-Stop' => [],
|
||||
'Short-Description' => '',
|
||||
'Description' => ''
|
||||
};
|
||||
my @splitpath = split( '/', $file );
|
||||
my $override;
|
||||
my @files;
|
||||
|
||||
open( FILE, "<$file" ) || error( int( $! ), "open(): $file: $!" );
|
||||
$splitpath[-1] = '.' . $splitpath[-1];
|
||||
$override = join( '/', @splitpath );
|
||||
|
||||
push( @files, $file );
|
||||
|
||||
if ( -f $override ) {
|
||||
push( @files, $override );
|
||||
}
|
||||
|
||||
foreach ( @files ) {
|
||||
open( FILE, "<$_" ) || error( int( $! ), "open(): $_: $!" );
|
||||
|
||||
while ( <FILE> ) {
|
||||
chomp();
|
||||
@@ -151,26 +246,28 @@ sub readinfo {
|
||||
}
|
||||
|
||||
if ( $_ =~ /^#\s*((Short\-|)Description):\s*(.*)/ ) {
|
||||
$service->{$1} = $3;
|
||||
$lsb->{$1} = $3;
|
||||
$prev = $1;
|
||||
}
|
||||
elsif ( $_ =~ /^#\s*(\S+):\s*(.*)/ ) {
|
||||
$service->{$1} = [];
|
||||
$lsb->{$1} = [];
|
||||
$prev = $1;
|
||||
|
||||
push( @{$service->{$1}}, split( /\s+/, $2 ) );
|
||||
push( @{$lsb->{$1}}, split( /\s+/, $2 ) );
|
||||
}
|
||||
elsif ( $prev && $prev =~ /Description/ && $_ =~ /^#\s*(.*)/ ) {
|
||||
$service->{$prev} .= " $1";
|
||||
elsif ( $prev && $prev =~ /Description/ &&
|
||||
$_ =~ /^#\s*(.*)/ ) {
|
||||
$lsb->{$prev} .= " $1";
|
||||
}
|
||||
elsif ( $prev && $_ =~ /^#\s*(.*)/ ) {
|
||||
push( @{$service->{$prev}}, split( /\s+/, $1 ) );
|
||||
push( @{$lsb->{$prev}}, split( /\s+/, $1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
close( FILE );
|
||||
}
|
||||
|
||||
return( $service );
|
||||
return( $lsb );
|
||||
}
|
||||
|
||||
sub readsvcs {
|
||||
@@ -180,20 +277,21 @@ sub readsvcs {
|
||||
error( int( $! ), "opendir(): " . INITDIR . ": $!" );
|
||||
|
||||
foreach my $svcname ( sort( readdir( DIR ) ) ) {
|
||||
if ( ! -X INITDIR . "/$svcname" ) {
|
||||
if ( ! -f INITDIR . "/$svcname" ||
|
||||
! -X INITDIR . "/$svcname" ) {
|
||||
next;
|
||||
}
|
||||
|
||||
$services->{$svcname} = readinfo( INITDIR . "/$svcname" );
|
||||
$services->{$svcname} = readlsb( INITDIR . "/$svcname" );
|
||||
|
||||
if ( ! @{$services->{$svcname}{'Provides'}} ) {
|
||||
undef( $services->{$svcname} );
|
||||
delete( $services->{$svcname} );
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
$services->{$svcname}{'name'} = $svcname;
|
||||
$services->{$svcname}{'status'} = chkstatus( $svcname );
|
||||
getsvcrlvls( $services->{$svcname} );
|
||||
}
|
||||
|
||||
close( DIR );
|
||||
@@ -201,155 +299,228 @@ sub readsvcs {
|
||||
return( $services );
|
||||
}
|
||||
|
||||
sub sdepends {
|
||||
my $services = shift;
|
||||
my $service = shift;
|
||||
my $sdepends = shift || [];
|
||||
sub sorder {
|
||||
my $service = shift || error( -1, "sorder(): service missing" );
|
||||
my $services = shift || error( -1, "sorder(): services missing" );
|
||||
my $sorder = shift || [];
|
||||
my $stack = shift || [];
|
||||
|
||||
if ( @$stack > 99 ) {
|
||||
if ( ! keys( %{$services->{$service}{'rlvls'}} ) ) {
|
||||
return;
|
||||
}
|
||||
elsif ( ( $stack->[0] && grep( $_ eq $service, @$stack ) ) ||
|
||||
( $sorder->[0] && grep( $_->{'name'} eq $service, @$sorder ) ) ||
|
||||
@$stack > 99 ) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if ( VERBOSE ) {
|
||||
print "Checking start order for $service\n";
|
||||
}
|
||||
|
||||
push( @$stack, $service->{'name'} );
|
||||
push( @$stack, $service );
|
||||
}
|
||||
|
||||
foreach my $svcname ( sort( keys( %{$services} ) ) ) {
|
||||
my $provides = $services->{$svcname}{'Provides'};
|
||||
if ( ! @$sorder ) {
|
||||
push( @$sorder, $services->{'hostname'} );
|
||||
}
|
||||
|
||||
foreach my $svc ( sort( keys( %{$services} ) ) ) {
|
||||
if ( $services->{$svc}{'X-Start-Before'} && grep(
|
||||
$_ eq $service, @{$services->{$svc}{'X-Start-Before'}} ) ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $svc should be before $service\n";
|
||||
}
|
||||
|
||||
sorder( $svc, $services, $sorder, $stack );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ref( $services->{$service}{'Required-Start'} ) eq 'ARRAY' ) {
|
||||
MAINLOOP: foreach my $required (
|
||||
@{$services->{$service}{'Required-Start'}} ) {
|
||||
if ( $services->{$required} && ! grep(
|
||||
$_->{'name'} eq $required, @$sorder ) ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service requires service"
|
||||
. " $required\n";
|
||||
}
|
||||
|
||||
sorder( $services->{$required}{'name'},
|
||||
$services, $sorder, $stack );
|
||||
|
||||
if ( $stack->[0] && grep( $_ eq $svcname, @$stack ) ) {
|
||||
next;
|
||||
}
|
||||
|
||||
foreach my $required ( @{$service->{'Required-Start'}} ) {
|
||||
if ( grep( $_ eq $required, @$provides ) ) {
|
||||
sdepends( $services, $services->{$svcname},
|
||||
$sdepends, $stack );
|
||||
foreach my $svc ( sort( keys( %{$services} ) ) ) {
|
||||
if ( ref( $services->{$svc}{'Provides'} )
|
||||
eq 'ARRAY' && grep( $_ eq $required,
|
||||
@{$services->{$svc}{'Provides'}} ) && ! grep(
|
||||
$_->{'name'} eq $svc, @$sorder ) ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service requires"
|
||||
. " service $svc\n";
|
||||
}
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$sdepends ) ) {
|
||||
push( @$sdepends, $svcname );
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach my $required ( @{$service->{'Should-Start'}} ) {
|
||||
if ( grep( $_ eq $required, @$provides ) ) {
|
||||
sdepends( $services, $services->{$svcname},
|
||||
$sdepends, $stack );
|
||||
sorder( $svc, $services,
|
||||
$sorder, $stack );
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$sdepends ) ) {
|
||||
push( @$sdepends, $svcname );
|
||||
next MAINLOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return( $sdepends );
|
||||
if ( ref( $services->{$service}{'Should-Start'} ) eq 'ARRAY' ) {
|
||||
MAINLOOP: foreach my $should (
|
||||
@{$services->{$service}{'Should-Start'}} ) {
|
||||
if ( $services->{$should} ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service should start"
|
||||
. " $should first\n";
|
||||
}
|
||||
|
||||
my $command = shift( @ARGV );
|
||||
sorder( $services->{$should}{'name'},
|
||||
$services, $sorder, $stack );
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
foreach my $svc ( sort( keys( %{$services} ) ) ) {
|
||||
if ( ref( $services->{$svc}{'Provides'} )
|
||||
eq 'ARRAY' && grep( $_ eq $should,
|
||||
@{$services->{$svc}{'Provides'}} ) ) {
|
||||
if ( VERBOSE ) {
|
||||
print " $service requires"
|
||||
. " service $svc\n";
|
||||
}
|
||||
|
||||
sorder( $svc, $services,
|
||||
$sorder, $stack );
|
||||
|
||||
next MAINLOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push( @$sorder, $services->{$service} );
|
||||
pop( @$stack );
|
||||
|
||||
if ( VERBOSE ) {
|
||||
print "Service $service added to start order\n";
|
||||
}
|
||||
}
|
||||
|
||||
my $command = shift( @ARGV ) || error( -1, "No command supplied" );
|
||||
my $services = readsvcs();
|
||||
my $kserv = [];
|
||||
my $sserv = [];
|
||||
my $ksvcs = [];
|
||||
my $ssvcs = [];
|
||||
|
||||
if ( $command !~ /disable|enable|required/ ) {
|
||||
if ( ! grep( $_ eq $command, &COMMANDS ) ) {
|
||||
error( -1, "$command: invalid command" );
|
||||
}
|
||||
|
||||
if ( $command eq 'disable' ) {
|
||||
if ( $command eq 'enable' || $command eq 'disable' ) {
|
||||
foreach ( @ARGV ) {
|
||||
if ( $services->{$_}{'X-Required'} ) {
|
||||
print STDERR "Not disabling required service '$_'\n";
|
||||
if ( $command eq 'enable' ) {
|
||||
enable( $services->{$_}, $services );
|
||||
}
|
||||
elsif ( $command eq 'disable' ) {
|
||||
if ( $services->{$_}{'X-Required'} &&
|
||||
$command eq 'disable' ) {
|
||||
print STDERR "Not disabling required"
|
||||
. " service '$_'\n";
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
undef( $services->{$_} );
|
||||
foreach my $rlvl ( keys(
|
||||
%{$services->{$_}{'rlvls'}} ) ) {
|
||||
delete( $services->{$_}{'rlvls'}{$rlvl} );
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $svcname ( sort( keys( %$services ) ) ) {
|
||||
if ( keys( %{$services->{$svcname}{'status'}} ) ||
|
||||
$services->{$svcname}{'X-Required'} ) {
|
||||
push( @ARGV, $svcname );
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $svcname ( sort( @ARGV ) ) {
|
||||
my $service = $services->{$svcname};
|
||||
|
||||
if ( ! $service ) {
|
||||
error( -1, "$svcname: invalid service name" );
|
||||
}
|
||||
|
||||
sdepends( $services, $services->{$svcname}, $sserv );
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$sserv ) ) {
|
||||
push( @$sserv, $svcname );
|
||||
}
|
||||
|
||||
kdepends( $services, $services->{$svcname}, $kserv );
|
||||
|
||||
if ( ! grep( $_ eq $svcname, @$kserv ) ) {
|
||||
if ( $svcname !~ /halt|reboot/ ) {
|
||||
unshift( @$kserv, $svcname );
|
||||
}
|
||||
else {
|
||||
push( @$kserv, $svcname );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $rlvl ( RUNLEVELS ) {
|
||||
my $dir = "/etc/rc$rlvl.d";
|
||||
my $startcnt = 0;
|
||||
my $stopcnt = 0;
|
||||
my $cnt = 0;
|
||||
foreach my $svc ( sort( keys( %$services ) ) ) {
|
||||
korder( $svc, $services, $ksvcs );
|
||||
sorder( $svc, $services, $ssvcs );
|
||||
|
||||
if ( $services->{$svc}{'X-Required'} &&
|
||||
! $services->{$svc}{'enabled'}) {
|
||||
enable( $services->{$svc}, $services );
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $rlvl ( &RUNLEVELS ) {
|
||||
my $rcdir = "/etc/rc$rlvl.d";
|
||||
my $kcnt = 0;
|
||||
my $scnt = 0;
|
||||
|
||||
if ( VERBOSE ) {
|
||||
print "[Runlevel $rlvl]\n";
|
||||
print "\n[RUNLEVEL $rlvl]\n";
|
||||
}
|
||||
|
||||
opendir( DIR, $dir ) ||
|
||||
error( int( $! ), "opendir(): $dir: $!" );
|
||||
opendir( my $rc, $rcdir ) || error( int( $! ),
|
||||
"opendir(): $rcdir: $!" );
|
||||
|
||||
foreach ( sort( readdir( DIR ) ) ) {
|
||||
if ( $_ =~ /^(K|S)\d{2}/ ) {
|
||||
unlink( "$dir/$_" ) ||
|
||||
error( int( $! ), "unlink(): $dir/$_: $!" );
|
||||
while ( readdir( $rc ) ) {
|
||||
if ( -l "$rcdir/$_" ) {
|
||||
my $target = readlink( "$rcdir/$_" ) || error(
|
||||
int( $! ), "readlink(): $rcdir/$_: $!" );
|
||||
( my $service = $target ) =~ s/.*\///;
|
||||
|
||||
if ( $services->{$service} ) {
|
||||
unlink( "$rcdir/$_" ) || error( int( $! ),
|
||||
"unlink(): $rcdir/$_: $!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close( DIR );
|
||||
closedir( $rc );
|
||||
|
||||
foreach my $kdepend ( @$kserv ) {
|
||||
if ( grep( $_ eq $rlvl,
|
||||
@{$services->{$kdepend}{'Default-Stop'}} ) ) {
|
||||
my $link = sprintf( "K%02d%s", $stopcnt, $kdepend );
|
||||
symlink( "../init.d/$kdepend", "$dir/$link" ) ||
|
||||
error( int( $! ), "symlink(): $dir/$link: $!" );
|
||||
for ( my $i = 0; $i <= $#$ksvcs; $i++ ) {
|
||||
if ( ! $ksvcs->[$i]{'rlvls'}{$rlvl} ) {
|
||||
next;
|
||||
}
|
||||
|
||||
if( grep( $_ eq $rlvl, @{$ksvcs->[$i]{'Default-Stop'}} ) ) {
|
||||
my $script = "../init.d/$ksvcs->[$i]{'name'}";
|
||||
my $link = sprintf( "%s/%s%02d%s", $rcdir,
|
||||
$ksvcs->[$i]{'rlvls'}{$rlvl},
|
||||
$kcnt, $ksvcs->[$i]{'name'} );
|
||||
|
||||
symlink( $script, $link ) || error( int( $! ),
|
||||
"symlink(): $link: $!" );
|
||||
|
||||
if ( VERBOSE ) {
|
||||
print "$dir/$link -> ../init.d/$kdepend\n";
|
||||
print "$link\n";
|
||||
}
|
||||
|
||||
$stopcnt++;
|
||||
$kcnt++;
|
||||
}
|
||||
}
|
||||
foreach my $sdepend ( @$sserv ) {
|
||||
if ( grep( $_ eq $rlvl,
|
||||
@{$services->{$sdepend}{'Default-Start'}} ) ) {
|
||||
my $link = sprintf( "S%02d%s", $startcnt, $sdepend );
|
||||
symlink( "../init.d/$sdepend", "$dir/$link" ) ||
|
||||
error( int( $! ), "symlink(): $dir/$link: $!" );
|
||||
|
||||
for ( my $i = 0; $i <= $#$ssvcs; $i++ ) {
|
||||
if ( ! $ssvcs->[$i]{'rlvls'}{$rlvl} ) {
|
||||
next;
|
||||
}
|
||||
|
||||
if ( grep( $_ eq $rlvl, @{$ssvcs->[$i]{'Default-Start'}} ) ) {
|
||||
my $script = "../init.d/$ssvcs->[$i]{'name'}";
|
||||
my $link = sprintf( "%s/%s%02d%s", $rcdir,
|
||||
$ssvcs->[$i]{'rlvls'}{$rlvl},
|
||||
$scnt, $ssvcs->[$i]{'name'} );
|
||||
|
||||
symlink( $script, $link ) || error( int( $! ),
|
||||
"symlink(): $link: $!" );
|
||||
|
||||
if ( VERBOSE ) {
|
||||
print "$dir/$link -> ../init.d/$sdepend\n";
|
||||
print "$link\n";
|
||||
}
|
||||
|
||||
$startcnt++;
|
||||
$scnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( VERBOSE ) {
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user