Compare commits
11 Commits
20180505.2
...
20180505.3
Author | SHA1 | Date | |
---|---|---|---|
990661bfd9 | |||
bf732c4905 | |||
24306e68c1 | |||
9ae595db4f | |||
1eaaac7428 | |||
c9e84492fb | |||
9e4fd67db6 | |||
d47df45f50 | |||
0665f7630b | |||
9a9003b255 | |||
![]() |
a67af1e82b |
7
1.in
7
1.in
@@ -8,9 +8,6 @@ PATH=/usr/bin:/usr/sbin
|
||||
# Prints distro name and URL
|
||||
print_welcome
|
||||
|
||||
# log all console messages
|
||||
bootlogd_start
|
||||
|
||||
run_hook sysinit_start
|
||||
|
||||
for sysinit in @RCDIR@/sysinit.d/*; do
|
||||
@@ -20,8 +17,12 @@ done
|
||||
# Remove leftover files
|
||||
# remove_leftover
|
||||
|
||||
cleanup_sysinit
|
||||
|
||||
run_hook sysinit_end
|
||||
|
||||
install -m100 /dev/null @RUNDIR@/stopit
|
||||
|
||||
status "Initialization complete"
|
||||
|
||||
bootlogd_stop
|
||||
|
6
2.in
6
2.in
@@ -2,14 +2,12 @@
|
||||
|
||||
PATH=/usr/bin:/usr/sbin
|
||||
|
||||
. @RCDIR@/functions
|
||||
|
||||
status "Running stage 2"
|
||||
[ -x @RCDIR@/rc.local ] && . @RCDIR@/rc.local
|
||||
|
||||
runlevel=default
|
||||
for arg in $(cat /proc/cmdline); do
|
||||
if [ -d @RUNITDIR@/runsvdir/"$arg" ]; then
|
||||
status "Runlevel detected: '$arg' (via kernel cmdline)"
|
||||
echo "Runlevel detected: '$arg' (via kernel cmdline)"
|
||||
runlevel="$arg"
|
||||
fi
|
||||
done
|
||||
|
58
Makefile
58
Makefile
@@ -9,7 +9,6 @@ SVDIR = $(RUNITDIR)/sv
|
||||
RUNSVDIR = $(RUNITDIR)/runsvdir
|
||||
SERVICEDIR = /etc/service
|
||||
RUNDIR = /run/runit
|
||||
RCBINDIR = $(PREFIX)/lib/rc/bin
|
||||
RCDIR = $(SYSCONFDIR)/rc
|
||||
|
||||
TMPFILES = tmpfile.conf
|
||||
@@ -18,7 +17,6 @@ BIN = zzz pause modules-load
|
||||
|
||||
STAGES = 1 2 3 ctrlaltdel
|
||||
|
||||
RCBIN = rc/halt rc/shutdown
|
||||
RC = rc/rc.local rc/rc.shutdown rc/functions rc/rc.conf
|
||||
|
||||
LN = ln -sf
|
||||
@@ -30,7 +28,6 @@ CHMODAW = chmod a-w
|
||||
CHMODX = chmod +x
|
||||
|
||||
HASRC = yes
|
||||
HASSYSV = no
|
||||
|
||||
EDIT = sed \
|
||||
-e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
|
||||
@@ -53,25 +50,23 @@ ifeq ($(HASRC),yes)
|
||||
all: all-rc
|
||||
endif
|
||||
|
||||
all-runit: $(STAGES)
|
||||
all-runit:
|
||||
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
|
||||
|
||||
all-rc: $(RC) rc/shutdown
|
||||
$(CC) $(CFLAGS) rc/halt.c -o rc/halt $(LDFLAGS)
|
||||
all-rc: $(RC) $(STAGES)
|
||||
|
||||
install-runit:
|
||||
install -d $(DESTDIR)$(RUNITDIR)
|
||||
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
|
||||
install -d $(DESTDIR)$(RUNSVDIR)
|
||||
mkdir -p $(DESTDIR)$(RUNSVDIR)/default
|
||||
mkdir -p $(DESTDIR)$(SVDIR)/sulogin
|
||||
$(LN) $(RUNSVDIR)/default $(DESTDIR)$(RUNSVDIR)/current
|
||||
$(CP) sv/sulogin $(DESTDIR)$(SVDIR)/
|
||||
$(CP) runsvdir/single $(DESTDIR)$(RUNSVDIR)/
|
||||
|
||||
$(LN) $(RUNDIR)/reboot $(DESTDIR)$(RUNITDIR)/
|
||||
$(LN) $(RUNDIR)/stopit $(DESTDIR)$(RUNITDIR)/
|
||||
|
||||
install -d $(DESTDIR)$(SVDIR)
|
||||
$(CP) sv/* $(DESTDIR)$(SVDIR)/
|
||||
|
||||
install -d $(DESTDIR)$(RUNSVDIR)
|
||||
$(CP) runsvdir/* $(DESTDIR)$(RUNSVDIR)/
|
||||
|
||||
install -d $(DESTDIR)$(BINDIR)
|
||||
install -m755 $(BIN) $(DESTDIR)$(BINDIR)
|
||||
|
||||
@@ -85,6 +80,9 @@ install-runit:
|
||||
install -m644 modules-load.8 $(DESTDIR)$(MANDIR)/man8
|
||||
|
||||
install-rc:
|
||||
install -d $(DESTDIR)$(RUNITDIR)
|
||||
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
|
||||
|
||||
install -d $(DESTDIR)$(RCDIR)
|
||||
install -d $(DESTDIR)$(RCDIR)/sysinit.d
|
||||
install -d $(DESTDIR)$(RCDIR)/shutdown.d
|
||||
@@ -92,41 +90,27 @@ install-rc:
|
||||
install -m644 rc/sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d
|
||||
install -m644 rc/shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d
|
||||
install -m644 rc/crypt.awk $(DESTDIR)$(RCDIR)
|
||||
install -d $(DESTDIR)$(RUNITDIR)
|
||||
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
|
||||
|
||||
install -d $(DESTDIR)$(RCBINDIR)
|
||||
install -m644 $(RCBIN) $(DESTDIR)$(RCBINDIR)
|
||||
install-getty:
|
||||
install -d $(DESTDIR)$(SVDIR)
|
||||
$(CP) sv/agetty-* $(DESTDIR)$(SVDIR)/
|
||||
|
||||
$(LN) halt $(DESTDIR)$(RCBINDIR)/poweroff
|
||||
$(LN) halt $(DESTDIR)$(RCBINDIR)/reboot
|
||||
|
||||
install_sysv:
|
||||
install -d $(DESTDIR)$(BINDIR)
|
||||
$(LN) runit-init $(DESTDIR)$(BINDIR)/init
|
||||
$(LN) $(RCBINDIR)/halt $(DESTDIR)$(BINDIR)/halt
|
||||
$(LN) $(RCBINDIR)/shutdown $(DESTDIR)$(BINDIR)/shutdown
|
||||
$(LN) halt $(DESTDIR)$(BINDIR)/poweroff
|
||||
$(LN) halt $(DESTDIR)$(BINDIR)/reboot
|
||||
install -d $(DESTDIR)$(MANDIR)/man8
|
||||
install -m644 rc/shutdown.8 $(DESTDIR)$(MANDIR)/man8/shutdown.8
|
||||
install -m644 rc/halt.8 $(DESTDIR)$(MANDIR)/man8/halt.8
|
||||
$(LN) halt.8 $(DESTDIR)$(MANDIR)/man8/poweroff.8
|
||||
$(LN) halt.8 $(DESTDIR)$(MANDIR)/man8/reboot.8
|
||||
install -d $(DESTDIR)$(RUNSVDIR)/default
|
||||
$(CP) runsvdir/default $(DESTDIR)$(RUNSVDIR)/
|
||||
|
||||
install: install-runit
|
||||
ifeq ($(HASRC),yes)
|
||||
install: install-rc
|
||||
ifeq ($(HASSYSV),yes)
|
||||
install: install_sysv
|
||||
endif
|
||||
endif
|
||||
|
||||
clean-runit:
|
||||
-rm -f pause
|
||||
-rm -f $(STAGES)
|
||||
|
||||
clean-rc:
|
||||
-rm -f rc/halt
|
||||
-rm -f rc/shutdown $(RC)
|
||||
-rm -f $(RC)
|
||||
-rm -f $(STAGES)
|
||||
|
||||
clean: clean-runit
|
||||
ifeq ($(HASRC),yes)
|
||||
@@ -135,4 +119,4 @@ endif
|
||||
|
||||
clean:
|
||||
|
||||
.PHONY: all install clean install-runit install-rc clean-runit clean-rc all-runit all-rc install_sysv
|
||||
.PHONY: all install clean install-runit install-rc install-getty clean-runit clean-rc all-runit all-rc
|
||||
|
@@ -57,16 +57,6 @@ if (( $? != 3 )); then
|
||||
fi
|
||||
unset TERM_COLORS
|
||||
|
||||
unquote() {
|
||||
local -r quotes=$'[\'"]'
|
||||
|
||||
if [[ ${1:0:1} = $quotes && ${1:(-1)} = "${1:0:1}" ]]; then
|
||||
printf '%s' "${1:1:(-1)}"
|
||||
else
|
||||
printf '%s' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# functions:
|
||||
|
||||
deltext() {
|
||||
@@ -196,6 +186,22 @@ activate_vgs() {
|
||||
(( $? == 0 )) && stat_done || stat_fail
|
||||
}
|
||||
|
||||
load_sysctl() {
|
||||
if [ -x /usr/bin/sysctl ]; then
|
||||
for i in /run/sysctl.d/*.conf \
|
||||
/etc/sysctl.d/*.conf \
|
||||
/usr/local/lib/sysctl.d/*.conf \
|
||||
/usr/lib/sysctl.d/*.conf \
|
||||
/etc/sysctl.conf; do
|
||||
|
||||
if [ -e "$i" ]; then
|
||||
printf '* Applying %s \n' "$i"
|
||||
sysctl -p "$i"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
do_unlock_legacy() {
|
||||
# $1 = requested name
|
||||
# $2 = source device
|
||||
@@ -385,7 +391,7 @@ bootlogd_stop() {
|
||||
}
|
||||
|
||||
bootlogd_start(){
|
||||
[[ ! -f /var/log/boot ]] && touch /var/log/boot
|
||||
# [[ ! -f /var/log/boot ]] && touch /var/log/boot
|
||||
bootlogd -p /run/bootlogd.pid
|
||||
}
|
||||
|
||||
@@ -436,7 +442,7 @@ mk_sysusers(){
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup_1(){
|
||||
cleanup_sysinit(){
|
||||
install -m0664 -o root -g utmp /dev/null /run/utmp
|
||||
if [ ! -e /var/log/wtmp ]; then
|
||||
install -m0664 -o root -g utmp /dev/null /var/log/wtmp
|
||||
|
67
rc/halt.8
67
rc/halt.8
@@ -1,67 +0,0 @@
|
||||
.Dd July 29, 2014
|
||||
.Dt HALT 8
|
||||
.Os Linux
|
||||
.Sh NAME
|
||||
.Nm halt ,
|
||||
.Nm reboot ,
|
||||
.Nm poweroff
|
||||
.Nd stop the system
|
||||
.Sh SYNOPSIS
|
||||
.Nm halt
|
||||
.Op Fl n
|
||||
.Op Fl f
|
||||
.Nm reboot
|
||||
.Op Fl n
|
||||
.Op Fl f
|
||||
.Nm poweroff
|
||||
.Op Fl n
|
||||
.Op Fl f
|
||||
.Sh DESCRIPTION
|
||||
.Nm halt
|
||||
/
|
||||
.Nm reboot
|
||||
/
|
||||
.Nm poweroff
|
||||
tells
|
||||
.Xr init 8
|
||||
to bring down, reboot, or power off the system.
|
||||
Without
|
||||
.Fl f ,
|
||||
it is a shortcut for
|
||||
.Nm init 0
|
||||
/
|
||||
.Nm init 6 .
|
||||
.Bl -tag -width indent
|
||||
.It Fl n
|
||||
Don't sync before reboot or halt.
|
||||
Note that the kernel and storage drivers may still sync.
|
||||
.It Fl f
|
||||
Force halt or reboot, don't call
|
||||
.Xr init 8 .
|
||||
This is
|
||||
.Sy dangerous !
|
||||
.El
|
||||
.Sh UNSUPPORTED OPTIONS
|
||||
This version of
|
||||
.Nm
|
||||
is based on
|
||||
.Xr runit 8 ,
|
||||
the following features are
|
||||
.Sy not
|
||||
supported and silently ignored:
|
||||
.Bl -tag -width indent
|
||||
.It Fl w
|
||||
to just write the wtmp record.
|
||||
.It Fl d
|
||||
to not write the wtmp record.
|
||||
.It Fl h
|
||||
to put hard drives in standby mode.
|
||||
.It Fl i
|
||||
to shut down network interfaces.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr init 8 ,
|
||||
.Xr shutdown 8
|
||||
.Sh AUTHOR
|
||||
.An Leah Neukirchen ,
|
||||
.Mt leah@vuxu.org .
|
77
rc/halt.c
77
rc/halt.c
@@ -1,77 +0,0 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include <sys/reboot.h>
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_type;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int do_sync = 1;
|
||||
int do_force = 0;
|
||||
int opt;
|
||||
action_type action = NOOP;
|
||||
|
||||
if (strcmp(__progname, "halt") == 0)
|
||||
action = HALT;
|
||||
else if (strcmp(__progname, "reboot") == 0)
|
||||
action = REBOOT;
|
||||
else if (strcmp(__progname, "poweroff") == 0)
|
||||
action = POWEROFF;
|
||||
else
|
||||
warnx("no default behavior, needs to be called as halt/reboot/poweroff.");
|
||||
|
||||
while ((opt = getopt(argc, argv, "dfhinw")) != -1)
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
do_sync = 0;
|
||||
break;
|
||||
case 'w':
|
||||
action = NOOP;
|
||||
do_sync = 0;
|
||||
break;
|
||||
case 'd':
|
||||
case 'h':
|
||||
case 'i':
|
||||
/* silently ignored. */
|
||||
break;
|
||||
case 'f':
|
||||
do_force = 1;
|
||||
break;
|
||||
default:
|
||||
errx(1, "Usage: %s [-n] [-f]", __progname);
|
||||
}
|
||||
|
||||
if (do_sync)
|
||||
sync();
|
||||
|
||||
switch (action) {
|
||||
case HALT:
|
||||
if (do_force)
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
else
|
||||
execl("/bin/runit-init", "init", "0", (char*)0);
|
||||
err(1, "halt failed");
|
||||
break;
|
||||
case POWEROFF:
|
||||
if (do_force)
|
||||
reboot(RB_POWER_OFF);
|
||||
else
|
||||
execl("/bin/runit-init", "init", "0", (char*)0);
|
||||
err(1, "poweroff failed");
|
||||
break;
|
||||
case REBOOT:
|
||||
if (do_force)
|
||||
reboot(RB_AUTOBOOT);
|
||||
else
|
||||
execl("/bin/runit-init", "init", "6", (char*)0);
|
||||
err(1, "reboot failed");
|
||||
break;
|
||||
case NOOP:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
.Dd July 29, 2014
|
||||
.Dt SHUTDOWN 8
|
||||
.Os Linux
|
||||
.Sh NAME
|
||||
.Nm shutdown
|
||||
.Nd bring down the system
|
||||
.Sh SYNOPSIS
|
||||
.Nm shutdown
|
||||
.Op Fl rhP
|
||||
.Op Fl fF
|
||||
.Op Cm now | Cm + Ns Ar mins
|
||||
.Op Ar message ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
brings the system down in a secure way.
|
||||
All logged-in users
|
||||
are notified that the system is going down, and
|
||||
.Xr login 1
|
||||
is blocked.
|
||||
.Pp
|
||||
By default,
|
||||
.Nm
|
||||
puts the system into single user mode.
|
||||
Rebooting and halting the system can be done using the following options:
|
||||
.Bl -tag -width indent
|
||||
.It Fl c
|
||||
Cancel an ongoing shutdown.
|
||||
.It Fl f
|
||||
Enable fast booting; skip
|
||||
.Xr fsck 8
|
||||
on next boot.
|
||||
.It Fl F
|
||||
Force run of
|
||||
.Xr fsck 8
|
||||
on next boot.
|
||||
.It Fl h
|
||||
Halt the system.
|
||||
.It Fl k
|
||||
Don't really shutdown; only send the warning messages to everybody.
|
||||
.It Fl P
|
||||
Poweroff the system.
|
||||
.It Fl r
|
||||
Reboot the system.
|
||||
.It Cm now
|
||||
Shutdown without further waiting.
|
||||
.It Cm + Ns Ar mins
|
||||
Wait
|
||||
.Ar mins
|
||||
minutes before shutting down.
|
||||
.It Ar message
|
||||
Message displayed to all users, defaults to "system is going down".
|
||||
.El
|
||||
.Sh UNSUPPORTED OPTIONS
|
||||
This version of
|
||||
.Nm
|
||||
is based on
|
||||
.Xr runit 8 ,
|
||||
the following features are
|
||||
.Sy not
|
||||
supported:
|
||||
.Bl -tag -width indent
|
||||
.It Fl t Ar secs
|
||||
to wait
|
||||
.Ar secs
|
||||
seconds between SIGKILL and SIGTERM on shutdown is silently ignored.
|
||||
.It Fl a
|
||||
Use
|
||||
.Pa /etc/shutdown.allow .
|
||||
.It Fl H
|
||||
Drop into boot monitor.
|
||||
.It Fl n
|
||||
Don't call
|
||||
.Xr init 8 .
|
||||
.It Ar hh Ns : Ns Ar mm
|
||||
Absolute time specification is not implemented.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
Turn off the system:
|
||||
.Dl # shutdown -h now
|
||||
.Sh SEE ALSO
|
||||
.Xr fsck 8 ,
|
||||
.Xr halt 8 ,
|
||||
.Xr init 8 ,
|
||||
.Xr poweroff 8 ,
|
||||
.Xr reboot 8 ,
|
||||
.Xr runit 8 ,
|
||||
.Xr runsvchdir 8
|
||||
.Sh AUTHOR
|
||||
.An Leah Neukirchen ,
|
||||
.Mt leah@vuxu.org .
|
@@ -1,2 +0,0 @@
|
||||
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
|
||||
status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null
|
@@ -1,2 +1,3 @@
|
||||
status "Remounting root filesystem read-only" \
|
||||
mount -o remount,ro /
|
||||
sync
|
2
rc/shutdown.d/13-lvm2.sh
Normal file
2
rc/shutdown.d/13-lvm2.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
|
||||
status "Deactivating LVM2 groups" vgchange --sysinit -an &>/dev/null
|
@@ -1,73 +0,0 @@
|
||||
#!/bin/sh
|
||||
# shutdown - shutdown(8) lookalike for runit
|
||||
|
||||
single() {
|
||||
runsvchdir single
|
||||
}
|
||||
|
||||
abort() {
|
||||
printf '%s\n' "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
abort "Usage: ${0##*/} [-fF] [-kchPr] time [warning message]"
|
||||
}
|
||||
|
||||
action=single
|
||||
|
||||
while getopts akrhPHfFnct: opt; do
|
||||
case "$opt" in
|
||||
a|n|H) abort "'-$opt' is not implemented";;
|
||||
t) ;;
|
||||
f) touch /fastboot;;
|
||||
F) touch /forcefsck;;
|
||||
k) action=true;;
|
||||
c) action=cancel;;
|
||||
h|P) action=halt;;
|
||||
r) action=reboot;;
|
||||
[?]) usage;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
[ $# -eq 0 ] && usage
|
||||
|
||||
time=$1; shift
|
||||
message="${*:-system is going down}"
|
||||
|
||||
if [ "$action" = "cancel" ]; then
|
||||
kill "$(cat @RUNDIR@/shutdown.pid)"
|
||||
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
|
||||
rm /etc/nologin
|
||||
fi
|
||||
echo "${*:-shutdown cancelled}" | wall
|
||||
exit
|
||||
fi
|
||||
|
||||
touch @RUNDIR@/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
|
||||
echo $$ >@RUNDIR@/shutdown.pid
|
||||
|
||||
case "$time" in
|
||||
now) time=0;;
|
||||
+*) time=${time#+};;
|
||||
*:*) abort "absolute time is not implemented";;
|
||||
*) abort "invalid time";;
|
||||
esac
|
||||
|
||||
for break in 5 0; do
|
||||
[ "$time" -gt "$break" ] || continue
|
||||
[ "$break" = 0 ] && touch /etc/nologin
|
||||
|
||||
printf '%s in %s minutes\n' "$message" "$time" | wall
|
||||
printf 'shutdown: sleeping for %s minutes... ' "$(( time - break ))"
|
||||
sleep $(( (time - break) * 60 ))
|
||||
time="$break"
|
||||
printf '\n'
|
||||
|
||||
[ "$break" = 0 ] && rm /etc/nologin
|
||||
done
|
||||
|
||||
printf '%s NOW\n' "$message" | wall
|
||||
|
||||
$action
|
@@ -14,3 +14,5 @@ mountpoint -q /sys/fs/cgroup/openrc || mkdir -p /sys/fs/cgroup/openrc && mount -
|
||||
awk '$4 == 1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || { mkdir -p /sys/fs/cgroup/" $1 " && mount -t cgroup -o " $1 " cgroup /sys/fs/cgroup/" $1 " ;}" ) }' /proc/cgroups
|
||||
|
||||
findmnt / --options ro &>/dev/null || status "Mounting root read-only" mount -o remount,ro /
|
||||
|
||||
bootlogd_start
|
||||
|
1
rc/sysinit.d/22-sysctl.sh
Normal file
1
rc/sysinit.d/22-sysctl.sh
Normal file
@@ -0,0 +1 @@
|
||||
status "Loading sysctl(8) settings" load_sysctl
|
Reference in New Issue
Block a user