Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
795ed0feaa | ||
|
|
c6456ba7d3 | ||
|
|
a101cfe1c0 | ||
|
|
843c8721f1 | ||
|
|
7de71fa1cd |
9
Makefile
9
Makefile
@@ -8,9 +8,9 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
DEPENDS = dash,kmod,procps-ng,sysvinit
|
DEPENDS = dash,grep,kmod,perl,procps-ng,sed,sysvinit
|
||||||
ARCH = x86_64
|
ARCH = x86_64
|
||||||
URL =
|
URL = http://snaplinux.org
|
||||||
REPO = core
|
REPO = core
|
||||||
BRIEF = Base scripts for sysvinit
|
BRIEF = Base scripts for sysvinit
|
||||||
DESC = This package supplies the core required init scripts for startup
|
DESC = This package supplies the core required init scripts for startup
|
||||||
@@ -18,7 +18,7 @@ DESC = This package supplies the core required init scripts for startup
|
|||||||
ARCHIVE := ''
|
ARCHIVE := ''
|
||||||
SRCDIR := $(PWD)/SRC/initscripts
|
SRCDIR := $(PWD)/SRC/initscripts
|
||||||
PATCHDIR := $(PWD)/SRC/patches
|
PATCHDIR := $(PWD)/SRC/patches
|
||||||
VERSION := 1.6-0
|
VERSION := 1.11-0
|
||||||
|
|
||||||
include /usr/share/snap/Makefile.snaplinux
|
include /usr/share/snap/Makefile.snaplinux
|
||||||
|
|
||||||
@@ -35,5 +35,6 @@ clean:
|
|||||||
@rm -rvf $(ROOT) \
|
@rm -rvf $(ROOT) \
|
||||||
$(SNAPINFO) \
|
$(SNAPINFO) \
|
||||||
$(MANIFEST) \
|
$(MANIFEST) \
|
||||||
$(FILES)
|
$(FILES) \
|
||||||
|
$(CONFIG)
|
||||||
|
|
||||||
|
|||||||
16
SNAP/usher
16
SNAP/usher
@@ -8,22 +8,6 @@ case $1 in
|
|||||||
;;
|
;;
|
||||||
postinst)
|
postinst)
|
||||||
update-rc required
|
update-rc required
|
||||||
|
|
||||||
if [ ! -f /etc/fstab ]; then
|
|
||||||
cp /usr/share/initscripts/fstab /etc/fstab
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f /etc/modules.conf ]; then
|
|
||||||
cp /usr/share/initscripts/modules.conf /etc/modules.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f /etc/default/halt ]; then
|
|
||||||
cp /usr/share/initscripts/halt.default /etc/default/halt
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f /etc/default/rcS ]; then
|
|
||||||
cp /usr/share/initscripts/rcS.default /etc/default/rcS
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
prerm)
|
prerm)
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -1,34 +1,19 @@
|
|||||||
dirs:
|
dirs:
|
||||||
install -d -m 755 $(DESTDIR)/etc/default
|
install -d -m 755 $(DESTDIR)/etc/init.d
|
||||||
install -d -m 755 $(DESTDIR)/etc/{rc{{0..6},S},init}.d
|
install -d -m 755 $(DESTDIR)/etc/modprobe.d
|
||||||
install -d -m 755 $(DESTDIR)/lib/lsb
|
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)/usr/share/man/man8
|
||||||
install -d -m 755 $(DESTDIR)/usr/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:
|
files:
|
||||||
install -m 755 init.d/checkfs $(DESTDIR)/etc/init.d/checkfs
|
for f in init.d/*; do \
|
||||||
install -m 755 init.d/cleanfs $(DESTDIR)/etc/init.d/cleanfs
|
install -m 755 $$f $(DESTDIR)/etc/init.d; \
|
||||||
install -m 755 init.d/halt $(DESTDIR)/etc/init.d/halt
|
done
|
||||||
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/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
|
|
||||||
install -m 755 init-functions $(DESTDIR)/lib/lsb/init-functions
|
install -m 755 init-functions $(DESTDIR)/lib/lsb/init-functions
|
||||||
install -m 644 fstab \
|
|
||||||
$(DESTDIR)/usr/share/initscripts/fstab
|
|
||||||
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)/usr/sbin
|
install -m 755 update-rc $(DESTDIR)/usr/sbin
|
||||||
|
install -m 755 service $(DESTDIR)/usr/sbin
|
||||||
|
|
||||||
install: dirs files
|
install: dirs files
|
||||||
|
|||||||
87
SRC/initscripts/init-functions
Normal file → Executable file
87
SRC/initscripts/init-functions
Normal file → Executable file
@@ -13,6 +13,7 @@ if [ -r /proc/1/environ ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
[ -n "$chkcontainer" ] && export $chkcontainer
|
[ -n "$chkcontainer" ] && export $chkcontainer
|
||||||
|
[ -z "$NAME" ] && NAME=${0##*/}
|
||||||
|
|
||||||
COL52="\\033[52G"
|
COL52="\\033[52G"
|
||||||
|
|
||||||
@@ -31,13 +32,13 @@ killproc() {
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
pathname="$1"
|
pathname="$1"
|
||||||
signal="$2"
|
[ -n "$2" ] && signal="$2"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -r "$pidfile" ] && pids=$(pidofproc -p "$pidfile" "$pathname")
|
[ -r "$pidfile" ] && pids=$(pidofproc -p "$pidfile" "$pathname") || return 0
|
||||||
[ -z "$pids" ] && pids=$(pidofproc "$pathname")
|
[ -z "$pids" ] && pids=$(pidofproc "$pathname")
|
||||||
[ -z "$pids" ] && [ -n "$signal" ] && return 1
|
[ -z "$pids" ] && [ -n "$signal" ] && return 1
|
||||||
[ -z "$pids" ] && return 0
|
[ -z "$pids" ] && return 0
|
||||||
@@ -67,6 +68,18 @@ log_init_msg() {
|
|||||||
echo -n "$1"
|
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() {
|
log_failure_msg() {
|
||||||
echo "$COL52[ FAIL ]"
|
echo "$COL52[ FAIL ]"
|
||||||
|
|
||||||
@@ -104,7 +117,11 @@ pidofproc() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -r "$pidfile" ] && pids=$(head -1 $pidfile) || pids=$(pidof $pathname)
|
if [ -r "$pidfile" ]; then
|
||||||
|
pids=$(head -1 $pidfile|sed 's/ \+//g')
|
||||||
|
else
|
||||||
|
pids=$(pidof "$pathname")
|
||||||
|
fi
|
||||||
|
|
||||||
for pid in $pids; do
|
for pid in $pids; do
|
||||||
kill -0 "$pid" 2>/dev/null && pidlist="$pidlist $pid "
|
kill -0 "$pid" 2>/dev/null && pidlist="$pidlist $pid "
|
||||||
@@ -154,3 +171,67 @@ start_daemon() {
|
|||||||
nice -n "$nicelevel" "$pathname"
|
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
|
||||||
|
|
||||||
|
# Here we use LSB as a reference for the return values:
|
||||||
|
#
|
||||||
|
# 0 program is running or service is OK
|
||||||
|
# 1 program is dead and /var/run pid file exists
|
||||||
|
# 2 program is dead and /var/lock lock file exists
|
||||||
|
# 3 program is not running
|
||||||
|
# 4 program or service status is unknown
|
||||||
|
# 5-99 reserved for future LSB use
|
||||||
|
# 100-149 reserved for distribution use
|
||||||
|
# 150-199 reserved for application use
|
||||||
|
# 200-254 reserved
|
||||||
|
#
|
||||||
|
# As you can see however, for now we just support 0, 1, 3 and 4
|
||||||
|
# May do something for 2 at some point, but the other status
|
||||||
|
# codes should not be used here - they're only here for reference
|
||||||
|
|
||||||
|
if [ -n "$pidfile" ]; then
|
||||||
|
if [ -r "$pidfile" ]; then
|
||||||
|
pid=$(pidofproc -p "$pidfile" "$pathname")
|
||||||
|
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
echo "$NAME running with PID: $pid" && return 0
|
||||||
|
else
|
||||||
|
echo "$NAME is not running" && return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Cannot read pid file ($pidfile)"
|
||||||
|
|
||||||
|
pid=$(pidofproc "$pathname")
|
||||||
|
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
echo "$NAME running with PID: $pid"
|
||||||
|
else
|
||||||
|
echo "$NAME is not running"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 4
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
pid=$(pidofproc "$pathname")
|
||||||
|
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
echo "$NAME running with PID: $pid" && return 0
|
||||||
|
else
|
||||||
|
echo "$NAME is not runing" && return 3
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: checkfs
|
# Provides: checkfs
|
||||||
# Required-Start: udev swap $time hostname
|
# Required-Start: checkroot hostname swap $time udev
|
||||||
# Required-Stop:
|
# Required-Stop:
|
||||||
# Should-Start:
|
# Should-Start:
|
||||||
# Should-Stop:
|
# Should-Stop:
|
||||||
@@ -17,32 +17,17 @@
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
if [ -f /fastboot ] || grep -qwi 'fastboot' /proc/cmdline; then
|
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
|
log_success_msg
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
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'
|
force='-f'
|
||||||
else
|
else
|
||||||
checking='Checking file systems'
|
log_init_msg 'Checking file systems'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$FSCKFIX" in
|
case "$FSCKFIX" in
|
||||||
@@ -50,44 +35,31 @@ case "$1" in
|
|||||||
fix='-y'
|
fix='-y'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
fix='-a'
|
fix='-p'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$VERBOSE" in
|
case "$VERBOSE" in
|
||||||
1|y|yes)
|
1|y|yes)
|
||||||
echo
|
echo
|
||||||
echo "$checking"
|
fsck $force $fix -A -C -T -R
|
||||||
fsck $force $fix -A -C -T
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_init_msg "$checking"
|
fsck $force $fix -A -T -R >/dev/null
|
||||||
fsck $force $fix -A -T >/dev/null
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
status=$?
|
status=$?
|
||||||
|
|
||||||
case "$VERBOSE" in
|
if [ $status = 0 ]; then
|
||||||
1|y|yes)
|
|
||||||
echo
|
|
||||||
if [ $status == 0 ]; then
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
log_init_msg "Filesystem issues detected"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ $status == 0 ]; then
|
|
||||||
log_success_msg
|
log_success_msg
|
||||||
elif [ $status != 1 ]; then
|
elif [ $status = 1 ]; then
|
||||||
log_warning_msg
|
log_warning_msg
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "WARNING: File system errors were detected and repaired."
|
echo "WARNING: File system errors were detected and repaired."
|
||||||
echo
|
echo
|
||||||
elif [ $status == 2 -o $status == 3 ]; then
|
elif [ $status = 2 -o $status = 3 ]; then
|
||||||
log_warning_msg
|
log_warning_msg
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@@ -95,7 +67,7 @@ case "$1" in
|
|||||||
echo "The repairs require the system to be rebooted."
|
echo "The repairs require the system to be rebooted."
|
||||||
echo
|
echo
|
||||||
echo "Press enter to reboot"
|
echo "Press enter to reboot"
|
||||||
read
|
read reboot
|
||||||
reboot -f
|
reboot -f
|
||||||
elif [ $status -gt 3 -a $status -lt 16 ]; then
|
elif [ $status -gt 3 -a $status -lt 16 ]; then
|
||||||
log_failure_msg
|
log_failure_msg
|
||||||
@@ -105,7 +77,7 @@ case "$1" in
|
|||||||
echo "repaired automatically."
|
echo "repaired automatically."
|
||||||
echo
|
echo
|
||||||
echo "Press enter to halt"
|
echo "Press enter to halt"
|
||||||
read
|
read halt
|
||||||
/etc/init.d/halt stop
|
/etc/init.d/halt stop
|
||||||
else
|
else
|
||||||
log_failure_msg
|
log_failure_msg
|
||||||
@@ -113,7 +85,9 @@ case "$1" in
|
|||||||
echo
|
echo
|
||||||
echo "fsck exited with unexpected status: $status"
|
echo "fsck exited with unexpected status: $status"
|
||||||
echo
|
echo
|
||||||
exit $status
|
echo "Press enter to halt"
|
||||||
|
read halt
|
||||||
|
/etc/init.d/halt stop
|
||||||
fi
|
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
|
||||||
@@ -24,6 +24,16 @@ clean() {
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
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"
|
log_init_msg "Cleaning temporary files"
|
||||||
|
|
||||||
for dir in $CLEANDIRS; do
|
for dir in $CLEANDIRS; do
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ case "$1" in
|
|||||||
poweroff='-p'
|
poweroff='-p'
|
||||||
netdown='-i'
|
netdown='-i'
|
||||||
|
|
||||||
if [ "$HALT" == "halt" ]; then
|
if [ "$HALT" = "halt" ]; then
|
||||||
poweroff=''
|
poweroff=''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$NETDOWN" == "no" ]; then
|
if [ "$NETDOWN" = "no" ]; then
|
||||||
netdown=''
|
netdown=''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: hwclock
|
# Provides: hwclock
|
||||||
# Required-Start: $local_fs
|
# Required-Start: mountvirtfs
|
||||||
# Required-Stop:
|
# Required-Stop: $local_fs
|
||||||
# Should-Start: modules
|
# Should-Start: modules
|
||||||
# Should-Stop: $syslog
|
# Should-Stop: $syslog
|
||||||
# Default-Start: S
|
# Default-Start: S
|
||||||
# Default-Stop: 0 6
|
# Default-Stop: 0 6
|
||||||
|
# X-Start-Before: checkroot
|
||||||
# Short-Description: Synchronize the system and hardware clocks
|
# Short-Description: Synchronize the system and hardware clocks
|
||||||
# Description: During boot sync the hardware clock to the
|
# Description: During boot sync the hardware clock to the
|
||||||
# system clock if udev is not running. During
|
# system clock if udev is not running. During
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: $local_fs
|
# Provides: $local_fs
|
||||||
# Required-Start: udev checkfs
|
# Required-Start: udev checkfs checkroot
|
||||||
# Should-Start:
|
# Should-Start:
|
||||||
# Required-Stop: swap
|
# Required-Stop: swap
|
||||||
# Should-Stop:
|
# Should-Stop:
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
# Default-Stop: 0 6
|
# Default-Stop: 0 6
|
||||||
# Short-Description: Mounts/unmounts local filesystems
|
# Short-Description: Mounts/unmounts local filesystems
|
||||||
# Description: Remounts root filesystem read/write and mounts all
|
# Description: Remounts root filesystem read/write and mounts all
|
||||||
# remaining local filesystems defined in /etc/fstab or
|
# remaining local filesystems defined in /etc/fstab
|
||||||
# in ZFS. Remounts root filesystem read-only and unmounts
|
# During stop remounts root filesystem read-only and
|
||||||
# remaining filesystems on stop.
|
# unmounts remaining filesystems.
|
||||||
# X-Required: true
|
# X-Required: true
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
@@ -21,41 +21,14 @@
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
log_init_msg "Remounting root file system in read-write mode"
|
log_init_msg "Mounting local file systems"
|
||||||
mount -o remount,rw / >/dev/null && log_success_msg || log_failure_msg
|
|
||||||
|
|
||||||
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 /forcefsk"
|
|
||||||
rm /forcefsck && log_success_msg || log_failure_msg
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x /sbin/zpool ]; then
|
|
||||||
if zpool list rpool 2>&1 > /dev/null; then
|
|
||||||
log_init_msg "Mounting ZFS file systems"
|
|
||||||
zfs mount -a && log_success_msg || log_failure_msg
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_init_msg "Mounting remaining file systems"
|
|
||||||
mount -a -O no_netdev >/dev/null && log_success_msg || log_failure_msg
|
mount -a -O no_netdev >/dev/null && log_success_msg || log_failure_msg
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
log_init_msg "Unmounting all file systems"
|
log_init_msg "Unmounting local file systems"
|
||||||
umount -a -d -r -t notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts \
|
umount -a -d -r -t notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts \
|
||||||
>/dev/null && log_success_msg || log_failure_msg
|
>/dev/null && log_success_msg || log_failure_msg
|
||||||
|
|
||||||
if [ -x /sbin/zpool ]; then
|
|
||||||
if zpool list rpool 2>&1 > /dev/null; then
|
|
||||||
log_init_msg "Unmounting ZFS file systems"
|
|
||||||
zfs umount -a && log_success_msg || log_failure_msg
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
mount -o remount,ro /
|
mount -o remount,ro /
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
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
|
# Provides: mountvirtfs
|
||||||
# Required-Start:
|
# Required-Start:
|
||||||
# Required-Stop:
|
# Required-Stop:
|
||||||
# Should-Start:
|
# Should-Start: udev
|
||||||
# Should-Stop:
|
# Should-Stop:
|
||||||
# Default-Start: S
|
# Default-Start: S
|
||||||
# Default-Stop:
|
# Default-Stop:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
stop)
|
stop)
|
||||||
log_init_msg "Restarting system"
|
echo "Restarting system"
|
||||||
reboot -d -f -i
|
reboot -d -f -i
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: swap
|
# Provides: swap
|
||||||
# Required-Start: udev
|
# Required-Start: udev
|
||||||
# Required-Stop:
|
# Required-Stop: mountfs
|
||||||
# Should-Start: modules
|
# Should-Start: modules
|
||||||
# Should-Stop:
|
# Should-Stop:
|
||||||
# Default-Start: S
|
# Default-Start: S
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ case "$1" in
|
|||||||
sysctl -q -p && log_success_msg || log_failed_msg
|
sysctl -q -p && log_success_msg || log_failed_msg
|
||||||
;;
|
;;
|
||||||
status)
|
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\+=.*//'`
|
param=`echo -n $line|sed 's/\s\+=.*//'`
|
||||||
realval=`sysctl $param|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 Data::Dumper;
|
||||||
|
|
||||||
|
use constant COMMANDS => qw( disable enable required status );
|
||||||
use constant INITDIR => '/etc/init.d';
|
use constant INITDIR => '/etc/init.d';
|
||||||
use constant RUNLEVELS => qw( S 1 2 3 4 5 6 0 );
|
use constant RUNLEVELS => qw( S 1 2 3 4 5 6 0 );
|
||||||
use constant SVCKEYS => qw( Provides Required-Start Required-Stop Should-Start
|
use constant SVCKEYS => qw(
|
||||||
Should-Stop Default-Start Default-Stop Short-Description Description );
|
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 {
|
use constant VERBOSE => eval {
|
||||||
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||||
if ( $ARGV[$i] eq '-v' || $ARGV[$i] eq '--verbose' ) {
|
if ( $ARGV[$i] eq '-v' || $ARGV[$i] eq '--verbose' ) {
|
||||||
@@ -21,25 +33,56 @@ use constant VERBOSE => eval {
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
};
|
};
|
||||||
|
|
||||||
sub chkstatus {
|
sub enable {
|
||||||
my $svcname = shift;
|
my $service = shift || error( -1, "enable(): service not provided" );
|
||||||
my $status = {};
|
my $services = shift || error( -1, "enable(): services not provided" );
|
||||||
|
|
||||||
foreach my $rlvl ( RUNLEVELS ) {
|
if ( $service->{'enabled'} ) {
|
||||||
my $dir = "/etc/rc$rlvl.d";
|
return;
|
||||||
|
|
||||||
opendir( DIR, $dir );
|
|
||||||
|
|
||||||
while ( readdir( DIR ) ) {
|
|
||||||
if ( $_ =~ /^([KS])(\d+)$svcname$/ ) {
|
|
||||||
$status->{$rlvl} = $1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
sub error {
|
||||||
@@ -47,12 +90,13 @@ sub error {
|
|||||||
my $errstr = shift;
|
my $errstr = shift;
|
||||||
my $level = 1;
|
my $level = 1;
|
||||||
my @stack = ();
|
my @stack = ();
|
||||||
|
( my $self = ( caller() )[1] ) =~ s/.*\///;
|
||||||
|
|
||||||
chomp( $errstr );
|
chomp( $errstr );
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
print STDERR ( caller() )[1] .":\n $errstr at line "
|
print STDERR "$self:\n $errstr at line "
|
||||||
. ( caller() )[2] . "\n";
|
. ( caller() )[2] . "\n";
|
||||||
|
|
||||||
if ( VERBOSE ) {
|
if ( VERBOSE ) {
|
||||||
@@ -73,67 +117,118 @@ sub error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub kdepends {
|
sub getsvcrlvls {
|
||||||
my $services = shift;
|
my $service = shift ||
|
||||||
my $service = shift;
|
error( -1, "getsvcrlvls(): service not provided\n" );
|
||||||
my $kdepends = shift || [];
|
|
||||||
my $stack = shift || [];
|
|
||||||
|
|
||||||
if ( @$stack > 99 ) {
|
foreach my $rlvl ( RUNLEVELS ) {
|
||||||
return;
|
my $dir = "/etc/rc$rlvl.d";
|
||||||
}
|
|
||||||
|
|
||||||
push( @$stack, $service->{'name'} );
|
opendir( my $dh, $dir ) ||
|
||||||
|
error( int( $! ), "getsvcrlvls(): opendir(): $!" );
|
||||||
|
|
||||||
foreach my $svcname ( sort( keys( %{$services} ) ) ) {
|
while ( readdir( $dh ) ) {
|
||||||
my $provides = $services->{$svcname}{'Provides'};
|
if ( ! -l "$dir/$_" ) {
|
||||||
|
|
||||||
if ( $stack->[0] && grep( $_ eq $svcname, @$stack ) ) {
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $required ( @{$service->{'Required-Stop'}} ) {
|
my $link = readlink( "$dir/$_" ) ||
|
||||||
if ( grep( $_ eq $required, @$provides ) ) {
|
error( int( $! ),
|
||||||
kdepends( $services, $services->{$svcname},
|
"getsvcrlvls(): readlink(): $!" );
|
||||||
$kdepends, $stack );
|
( my $name = $link ) =~ s/.*\///;
|
||||||
|
|
||||||
if ( ! grep( $_ eq $svcname, @$kdepends ) ) {
|
if ( $name eq $service->{'name'} &&
|
||||||
unshift( @$kdepends, $svcname );
|
$_ =~ /^([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 ) ) {
|
closedir( $dh );
|
||||||
unshift( @$kdepends, $svcname );
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 $file = shift;
|
||||||
my $begin = 0;
|
my $begin = 0;
|
||||||
my $prev;
|
my $prev;
|
||||||
my $service = {
|
my $lsb = {
|
||||||
'Provides' => [],
|
'Provides' => [],
|
||||||
'Required-Start' => [],
|
'Required-Start' => [],
|
||||||
'Required-Stop' => [],
|
'Required-Stop' => [],
|
||||||
'Should-Start' => [],
|
'Should-Start' => [],
|
||||||
'Should-Stop' => [],
|
'Should-Stop' => [],
|
||||||
|
'X-Start-Before' => [],
|
||||||
|
'X-Stop-After' => [],
|
||||||
'Default-Start' => [],
|
'Default-Start' => [],
|
||||||
'Default-Stop' => [],
|
'Default-Stop' => [],
|
||||||
'Short-Description' => '',
|
'Short-Description' => '',
|
||||||
'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> ) {
|
while ( <FILE> ) {
|
||||||
chomp();
|
chomp();
|
||||||
@@ -151,26 +246,28 @@ sub readinfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $_ =~ /^#\s*((Short\-|)Description):\s*(.*)/ ) {
|
if ( $_ =~ /^#\s*((Short\-|)Description):\s*(.*)/ ) {
|
||||||
$service->{$1} = $3;
|
$lsb->{$1} = $3;
|
||||||
$prev = $1;
|
$prev = $1;
|
||||||
}
|
}
|
||||||
elsif ( $_ =~ /^#\s*(\S+):\s*(.*)/ ) {
|
elsif ( $_ =~ /^#\s*(\S+):\s*(.*)/ ) {
|
||||||
$service->{$1} = [];
|
$lsb->{$1} = [];
|
||||||
$prev = $1;
|
$prev = $1;
|
||||||
|
|
||||||
push( @{$service->{$1}}, split( /\s+/, $2 ) );
|
push( @{$lsb->{$1}}, split( /\s+/, $2 ) );
|
||||||
}
|
}
|
||||||
elsif ( $prev && $prev =~ /Description/ && $_ =~ /^#\s*(.*)/ ) {
|
elsif ( $prev && $prev =~ /Description/ &&
|
||||||
$service->{$prev} .= " $1";
|
$_ =~ /^#\s*(.*)/ ) {
|
||||||
|
$lsb->{$prev} .= " $1";
|
||||||
}
|
}
|
||||||
elsif ( $prev && $_ =~ /^#\s*(.*)/ ) {
|
elsif ( $prev && $_ =~ /^#\s*(.*)/ ) {
|
||||||
push( @{$service->{$prev}}, split( /\s+/, $1 ) );
|
push( @{$lsb->{$prev}}, split( /\s+/, $1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close( FILE );
|
close( FILE );
|
||||||
|
}
|
||||||
|
|
||||||
return( $service );
|
return( $lsb );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub readsvcs {
|
sub readsvcs {
|
||||||
@@ -185,7 +282,7 @@ sub readsvcs {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$services->{$svcname} = readinfo( INITDIR . "/$svcname" );
|
$services->{$svcname} = readlsb( INITDIR . "/$svcname" );
|
||||||
|
|
||||||
if ( ! @{$services->{$svcname}{'Provides'}} ) {
|
if ( ! @{$services->{$svcname}{'Provides'}} ) {
|
||||||
delete( $services->{$svcname} );
|
delete( $services->{$svcname} );
|
||||||
@@ -194,7 +291,7 @@ sub readsvcs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$services->{$svcname}{'name'} = $svcname;
|
$services->{$svcname}{'name'} = $svcname;
|
||||||
$services->{$svcname}{'status'} = chkstatus( $svcname );
|
getsvcrlvls( $services->{$svcname} );
|
||||||
}
|
}
|
||||||
|
|
||||||
close( DIR );
|
close( DIR );
|
||||||
@@ -202,156 +299,228 @@ sub readsvcs {
|
|||||||
return( $services );
|
return( $services );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub sdepends {
|
sub sorder {
|
||||||
my $services = shift;
|
my $service = shift || error( -1, "sorder(): service missing" );
|
||||||
my $service = shift;
|
my $services = shift || error( -1, "sorder(): services missing" );
|
||||||
my $sdepends = shift || [];
|
my $sorder = shift || [];
|
||||||
my $stack = shift || [];
|
my $stack = shift || [];
|
||||||
|
|
||||||
if ( $stack->[0] && grep( $_ eq $service->{'name'}, @$stack )
|
if ( ! keys( %{$services->{$service}{'rlvls'}} ) ) {
|
||||||
|| @$stack > 99 ) {
|
|
||||||
return;
|
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} ) ) ) {
|
if ( ! @$sorder ) {
|
||||||
my $provides = $services->{$svcname}{'Provides'};
|
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;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $required ( @{$service->{'Required-Start'}} ) {
|
foreach my $svc ( sort( keys( %{$services} ) ) ) {
|
||||||
if ( grep( $_ eq $required, @$provides ) ) {
|
if ( ref( $services->{$svc}{'Provides'} )
|
||||||
sdepends( $services, $services->{$svcname},
|
eq 'ARRAY' && grep( $_ eq $required,
|
||||||
$sdepends, $stack );
|
@{$services->{$svc}{'Provides'}} ) && ! grep(
|
||||||
|
$_->{'name'} eq $svc, @$sorder ) ) {
|
||||||
|
if ( VERBOSE ) {
|
||||||
|
print " $service requires"
|
||||||
|
. " service $svc\n";
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! grep( $_ eq $svcname, @$sdepends ) ) {
|
sorder( $svc, $services,
|
||||||
push( @$sdepends, $svcname );
|
$sorder, $stack );
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach my $required ( @{$service->{'Should-Start'}} ) {
|
|
||||||
if ( grep( $_ eq $required, @$provides ) ) {
|
|
||||||
sdepends( $services, $services->{$svcname},
|
|
||||||
$sdepends, $stack );
|
|
||||||
|
|
||||||
if ( ! grep( $_ eq $svcname, @$sdepends ) ) {
|
next MAINLOOP;
|
||||||
push( @$sdepends, $svcname );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 $services = readsvcs();
|
||||||
my $kserv = [];
|
my $ksvcs = [];
|
||||||
my $sserv = [];
|
my $ssvcs = [];
|
||||||
|
|
||||||
if ( $command !~ /disable|enable|required/ ) {
|
if ( ! grep( $_ eq $command, &COMMANDS ) ) {
|
||||||
error( -1, "$command: invalid command" );
|
error( -1, "$command: invalid command" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $command eq 'disable' ) {
|
if ( $command eq 'enable' || $command eq 'disable' ) {
|
||||||
foreach ( @ARGV ) {
|
foreach ( @ARGV ) {
|
||||||
if ( $services->{$_}{'X-Required'} ) {
|
if ( $command eq 'enable' ) {
|
||||||
print STDERR "Not disabling required service '$_'\n";
|
enable( $services->{$_}, $services );
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'disable' ) {
|
||||||
|
if ( $services->{$_}{'X-Required'} &&
|
||||||
|
$command eq 'disable' ) {
|
||||||
|
print STDERR "Not disabling required"
|
||||||
|
. " service '$_'\n";
|
||||||
|
|
||||||
next;
|
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 ) {
|
foreach my $svc ( sort( keys( %$services ) ) ) {
|
||||||
my $dir = "/etc/rc$rlvl.d";
|
korder( $svc, $services, $ksvcs );
|
||||||
my $startcnt = 0;
|
sorder( $svc, $services, $ssvcs );
|
||||||
my $stopcnt = 0;
|
|
||||||
my $cnt = 0;
|
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 ) {
|
if ( VERBOSE ) {
|
||||||
print "[Runlevel $rlvl]\n";
|
print "\n[RUNLEVEL $rlvl]\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
opendir( DIR, $dir ) ||
|
opendir( my $rc, $rcdir ) || error( int( $! ),
|
||||||
error( int( $! ), "opendir(): $dir: $!" );
|
"opendir(): $rcdir: $!" );
|
||||||
|
|
||||||
foreach ( sort( readdir( DIR ) ) ) {
|
while ( readdir( $rc ) ) {
|
||||||
if ( $_ =~ /^(K|S)\d{2}/ ) {
|
if ( -l "$rcdir/$_" ) {
|
||||||
unlink( "$dir/$_" ) ||
|
my $target = readlink( "$rcdir/$_" ) || error(
|
||||||
error( int( $! ), "unlink(): $dir/$_: $!" );
|
int( $! ), "readlink(): $rcdir/$_: $!" );
|
||||||
|
( my $service = $target ) =~ s/.*\///;
|
||||||
|
|
||||||
|
if ( $services->{$service} ) {
|
||||||
|
unlink( "$rcdir/$_" ) || error( int( $! ),
|
||||||
|
"unlink(): $rcdir/$_: $!" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close( DIR );
|
closedir( $rc );
|
||||||
|
|
||||||
foreach my $kdepend ( @$kserv ) {
|
for ( my $i = 0; $i <= $#$ksvcs; $i++ ) {
|
||||||
if ( grep( $_ eq $rlvl,
|
if ( ! $ksvcs->[$i]{'rlvls'}{$rlvl} ) {
|
||||||
@{$services->{$kdepend}{'Default-Stop'}} ) ) {
|
next;
|
||||||
my $link = sprintf( "K%02d%s", $stopcnt, $kdepend );
|
}
|
||||||
symlink( "../init.d/$kdepend", "$dir/$link" ) ||
|
|
||||||
error( int( $! ), "symlink(): $dir/$link: $!" );
|
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 ) {
|
if ( VERBOSE ) {
|
||||||
print "$dir/$link -> ../init.d/$kdepend\n";
|
print "$link\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$stopcnt++;
|
$kcnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach my $sdepend ( @$sserv ) {
|
|
||||||
if ( grep( $_ eq $rlvl,
|
for ( my $i = 0; $i <= $#$ssvcs; $i++ ) {
|
||||||
@{$services->{$sdepend}{'Default-Start'}} ) ) {
|
if ( ! $ssvcs->[$i]{'rlvls'}{$rlvl} ) {
|
||||||
my $link = sprintf( "S%02d%s", $startcnt, $sdepend );
|
next;
|
||||||
symlink( "../init.d/$sdepend", "$dir/$link" ) ||
|
}
|
||||||
error( int( $! ), "symlink(): $dir/$link: $!" );
|
|
||||||
|
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 ) {
|
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