Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ffbff7be2 | |||
998a015931 | |||
ab64a874c9 | |||
9dbb2a0cad | |||
1c2ae8f224 | |||
d0d4f3535b | |||
099f5f1b39 | |||
f47e826d30 | |||
e90ab16538 | |||
7ca5e67b69 | |||
14740a80b7 | |||
7df71e96c0 | |||
fb9eb6652f | |||
2b93e4e3cc | |||
a2f006ee82 | |||
34e1aaadd2 | |||
c4d6c1a152 | |||
946460ab11 | |||
b31f22ec08 | |||
0cdb37f0da | |||
9296835d29 | |||
eed18456fe | |||
4b768ada1a | |||
50c92dfca3 | |||
72f458b788 | |||
8414023038 | |||
fe56971e7a | |||
e06ba41113 | |||
27eb5faa3d | |||
761afcded2 | |||
a6df81b8fb | |||
1df9ca6564 |
187
Makefile
187
Makefile
@@ -6,86 +6,45 @@ LIBDIR = $(PREFIX)/lib
|
||||
|
||||
RCDIR = $(SYSCONFDIR)/rc
|
||||
RCLIBDIR = $(LIBDIR)/rc
|
||||
RCSVDIR = $(RCLIBDIR)/sv.d
|
||||
RCSVDIR = /usr/share/rc/sv.d
|
||||
RCENABLEDDIR = /etc/rc/sv.d
|
||||
RCRUNDIR = /run/sv.d
|
||||
RUNITDIR = /etc/runit
|
||||
RUNITRUNDIR = /run/runit
|
||||
|
||||
RCBIN = \
|
||||
script/rc-sysinit \
|
||||
script/rc-shutdown \
|
||||
script/rc-sv \
|
||||
script/modules-load
|
||||
script/modules-load \
|
||||
script/service
|
||||
|
||||
RCSVD = \
|
||||
sv.d/root \
|
||||
sv.d/binfmt \
|
||||
sv.d/bootlogd \
|
||||
sv.d/cleanup \
|
||||
sv.d/console-setup \
|
||||
sv.d/dmesg \
|
||||
sv.d/hostname \
|
||||
sv.d/hwclock \
|
||||
sv.d/kmod-static-nodes \
|
||||
sv.d/misc \
|
||||
sv.d/mount-all \
|
||||
sv.d/net-lo \
|
||||
sv.d/netfs \
|
||||
sv.d/random-seed \
|
||||
sv.d/remount-root \
|
||||
sv.d/swap \
|
||||
sv.d/sysctl \
|
||||
sv.d/sysusers \
|
||||
sv.d/tmpfiles-dev \
|
||||
sv.d/tmpfiles-setup \
|
||||
sv.d/udev \
|
||||
sv.d/udev-trigger \
|
||||
sv.d/udev-settle \
|
||||
sv.d/modules \
|
||||
sv.d/sysfs \
|
||||
sv.d/devfs \
|
||||
sv.d/procfs \
|
||||
sv.d/cgroups
|
||||
RCSTAGE1 = \
|
||||
stage1/00-pseudofs \
|
||||
stage1/01-cgroups \
|
||||
stage1/01-static-devnodes \
|
||||
stage1/02-modules \
|
||||
stage1/02-udev \
|
||||
stage1/03-console-setup \
|
||||
stage1/03-hwclock \
|
||||
stage1/04-rootfs \
|
||||
stage1/05-btrfs \
|
||||
stage1/06-fsck \
|
||||
stage1/07-mountfs \
|
||||
stage1/08-misc \
|
||||
stage1/11-sysctl \
|
||||
stage1/99-cleanup
|
||||
|
||||
# SYSINIT = \
|
||||
# 01-sysfs \
|
||||
# 02-procfs \
|
||||
# 03-devfs \
|
||||
# 04-cgroups \
|
||||
# 05-root \
|
||||
# 10-hostname \
|
||||
# 15-hwclock \
|
||||
# 20-kmod-static-nodes \
|
||||
# 25-tmpfiles-dev \
|
||||
# 30-udev \
|
||||
# 31-udev-trigger \
|
||||
# 32-modules \
|
||||
# 33-udev-settle \
|
||||
# 40-console-setup \
|
||||
# 45-net-lo \
|
||||
# 50-misc \
|
||||
# 55-remount-root \
|
||||
# 60-mount-all \
|
||||
# 65-swap \
|
||||
# 70-random-seed \
|
||||
# 75-tmpfiles-setup \
|
||||
# 80-sysusers \
|
||||
# 85-dmesg \
|
||||
# 90-sysctl \
|
||||
# 95-binfmt \
|
||||
# 99-cleanup
|
||||
#
|
||||
# SHUTDWON = \
|
||||
# 10-random-seed \
|
||||
# 20-cleanup \
|
||||
# 30-udev \
|
||||
# 40-misc \
|
||||
# 50-swap \
|
||||
# 60-root \
|
||||
# 70-remount-root
|
||||
RCLVM1 = stage1/05-lvm
|
||||
|
||||
# sv.d/timezone \
|
||||
# sv.d/lvm-monitoring \
|
||||
# sv.d/lvm \
|
||||
# sv.d/cryptsetup
|
||||
RCLVM3 = stage3/40-lvm
|
||||
|
||||
RCCRYPT1 = stage1/06-cryptsetup
|
||||
|
||||
RCCRYPT3 = stage3/50-cryptsetup
|
||||
|
||||
RCSTAGE3 = \
|
||||
stage3/10-misc \
|
||||
stage3/30-killall \
|
||||
stage3/40-filesystem \
|
||||
stage3/99-remount-root
|
||||
|
||||
CONF = script/rc.conf
|
||||
|
||||
@@ -102,7 +61,10 @@ EDIT = sed \
|
||||
-e "s|@RCDIR[@]|$(RCDIR)|g" \
|
||||
-e "s|@RCLIBDIR[@]|$(RCLIBDIR)|g" \
|
||||
-e "s|@RCSVDIR[@]|$(RCSVDIR)|g" \
|
||||
-e "s|@RCRUNDIR[@]|$(RCRUNDIR)|g"
|
||||
-e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
|
||||
-e "s|@RUNITRUNDIR[@]|$(RUNITRUNDIR)|g" \
|
||||
-e "s|@RCRUNDIR[@]|$(RCRUNDIR)|g" \
|
||||
-e "s|@RCENABLEDDIR[@]|$(RCENABLEDDIR)|g"
|
||||
|
||||
%: %.in Makefile
|
||||
@echo "GEN $@"
|
||||
@@ -113,7 +75,7 @@ EDIT = sed \
|
||||
|
||||
all: all-rc
|
||||
|
||||
all-rc: $(RCBIN) $(RCSVD) $(RCFUNC) $(CONF)
|
||||
all-rc: $(RCBIN) $(RCSTAGE1) $(RCSTAGE3) $(RCCRYPT1) $(RCCRYPT3) $(RCLVM1) $(RCLVM3) $(RCFUNC) $(CONF)
|
||||
|
||||
install-rc:
|
||||
|
||||
@@ -129,53 +91,48 @@ install-rc:
|
||||
install -d $(DESTDIR)$(RCSVDIR)
|
||||
install -m755 $(RCSVD) $(DESTDIR)$(RCSVDIR)
|
||||
|
||||
install -d $(DESTDIR)$(RCDIR)/sysinit
|
||||
install -d $(DESTDIR)$(RCENABLEDDIR)
|
||||
|
||||
$(LN) $(RCSVDIR)/sysfs $(DESTDIR)$(RCDIR)/sysinit/01-sysfs
|
||||
$(LN) $(RCSVDIR)/procfs $(DESTDIR)$(RCDIR)/sysinit/02-procfs
|
||||
$(LN) $(RCSVDIR)/devfs $(DESTDIR)$(RCDIR)/sysinit/03-devfs
|
||||
$(LN) $(RCSVDIR)/cgroups $(DESTDIR)$(RCDIR)/sysinit/04-cgroups
|
||||
$(LN) $(RCSVDIR)/root $(DESTDIR)$(RCDIR)/sysinit/05-root
|
||||
$(LN) $(RCSVDIR)/hostname $(DESTDIR)$(RCDIR)/sysinit/10-hostname
|
||||
$(LN) $(RCSVDIR)/hwclock $(DESTDIR)$(RCDIR)/sysinit/15-hwclock
|
||||
$(LN) $(RCSVDIR)/kmod-static-nodes $(DESTDIR)$(RCDIR)/sysinit/20-kmod-static-nodes
|
||||
$(LN) $(RCSVDIR)/tmpfiles-dev $(DESTDIR)$(RCDIR)/sysinit/25-tmpfiles-dev
|
||||
$(LN) $(RCSVDIR)/udev $(DESTDIR)$(RCDIR)/sysinit/30-udev
|
||||
$(LN) $(RCSVDIR)/udev-trigger $(DESTDIR)$(RCDIR)/sysinit/31-udev-trigger
|
||||
$(LN) $(RCSVDIR)/modules $(DESTDIR)$(RCDIR)/sysinit/32-modules
|
||||
$(LN) $(RCSVDIR)/udev-settle $(DESTDIR)$(RCDIR)/sysinit/33-udev-settle
|
||||
$(LN) $(RCSVDIR)/console-setup $(DESTDIR)$(RCDIR)/sysinit/40-console-setup
|
||||
$(LN) $(RCSVDIR)/net-lo $(DESTDIR)$(RCDIR)/sysinit/45-net-lo
|
||||
$(LN) $(RCSVDIR)/misc $(DESTDIR)$(RCDIR)/sysinit/50-misc
|
||||
$(LN) $(RCSVDIR)/remount-root $(DESTDIR)$(RCDIR)/sysinit/55-remount-root
|
||||
$(LN) $(RCSVDIR)/mount-all $(DESTDIR)$(RCDIR)/sysinit/60-mount-all
|
||||
$(LN) $(RCSVDIR)/swap $(DESTDIR)$(RCDIR)/sysinit/65-swap
|
||||
$(LN) $(RCSVDIR)/random-seed $(DESTDIR)$(RCDIR)/sysinit/70-random-seed
|
||||
$(LN) $(RCSVDIR)/tmpfiles-setup $(DESTDIR)$(RCDIR)/sysinit/75-tmpfiles-setup
|
||||
$(LN) $(RCSVDIR)/sysusers $(DESTDIR)$(RCDIR)/sysinit/80-sysusers
|
||||
$(LN) $(RCSVDIR)/dmesg $(DESTDIR)$(RCDIR)/sysinit/85-dmesg
|
||||
$(LN) $(RCSVDIR)/sysctl $(DESTDIR)$(RCDIR)/sysinit/90-sysctl
|
||||
$(LN) $(RCSVDIR)/binfmt $(DESTDIR)$(RCDIR)/sysinit/95-binfmt
|
||||
$(LN) $(RCSVDIR)/cleanup $(DESTDIR)$(RCDIR)/sysinit/99-cleanup
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage1
|
||||
install -m755 $(RCSTAGE1) $(DESTDIR)$(RCLIBDIR)/stage1/
|
||||
|
||||
install -d $(DESTDIR)$(RCDIR)/shutdown
|
||||
|
||||
$(LN) $(RCSVDIR)/random-seed $(DESTDIR)$(RCDIR)/shutdown/10-random-seed
|
||||
$(LN) $(RCSVDIR)/cleanup $(DESTDIR)$(RCDIR)/shutdown/20-cleanup
|
||||
$(LN) $(RCSVDIR)/udev $(DESTDIR)$(RCDIR)/shutdown/30-udev
|
||||
$(LN) $(RCSVDIR)/misc $(DESTDIR)$(RCDIR)/shutdown/40-misc
|
||||
$(LN) $(RCSVDIR)/swap $(DESTDIR)$(RCDIR)/shutdown/50-swap
|
||||
$(LN) $(RCSVDIR)/root $(DESTDIR)$(RCDIR)/shutdown/60-root
|
||||
$(LN) $(RCSVDIR)/remount-root $(DESTDIR)$(RCDIR)/shutdown/70-remount-root
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
install -m755 $(RCSTAGE3) $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
|
||||
install -d $(DESTDIR)$(MANDIR)/man8
|
||||
install -m644 script/modules-load.8 $(DESTDIR)$(MANDIR)/man8
|
||||
install -m644 man/modules-load.8 $(DESTDIR)$(MANDIR)/man8
|
||||
install -m644 man/service.8 $(DESTDIR)$(MANDIR)/man8
|
||||
|
||||
install-lvm:
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage1
|
||||
install -m755 $(RCCRYPT1) $(DESTDIR)$(RCLIBDIR)/stage1/
|
||||
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
install -m755 $(RCCRYPT3) $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
|
||||
install-crypt:
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage1
|
||||
install -m755 $(RCCRYPT1) $(DESTDIR)$(RCLIBDIR)/stage1/
|
||||
|
||||
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
install -m755 $(RCCRYPT3) $(DESTDIR)$(RCLIBDIR)/stage3/
|
||||
|
||||
install-services:
|
||||
install -d $(DESTDIR)$(RCSVDIR)/binfmt
|
||||
install -m755 sv.d/binfmt/up $(DESTDIR)$(RCSVDIR)/binfmt
|
||||
install -m755 sv.d/binfmt/down $(DESTDIR)$(RCSVDIR)/binfmt
|
||||
install -d $(DESTDIR)$(RCSVDIR)/netmount
|
||||
install -m755 sv.d/netmount/up $(DESTDIR)$(RCSVDIR)/netmount
|
||||
install -m755 sv.d/netmount/down $(DESTDIR)$(RCSVDIR)/netmount
|
||||
install -d $(DESTDIR)$(RCSVDIR)/staticnet
|
||||
install -m755 sv.d/staticnet/up $(DESTDIR)$(RCSVDIR)/staticnet
|
||||
install -m755 sv.d/staticnet/down $(DESTDIR)$(RCSVDIR)/staticnet
|
||||
|
||||
install: install-rc
|
||||
|
||||
clean-rc:
|
||||
-$(RM) $(RCBIN) $(RCSVD) $(RCFUNC) $(CONF)
|
||||
-$(RM) $(RCBIN) $(RCSVD) $(RCSTAGE1) $(RCSTAGE3) $(RCCRYPT1) $(RCCRYPT3) $(RCLVM1) $(RCLVM3) $(RCFUNC) $(CONF)
|
||||
|
||||
clean: clean-rc
|
||||
|
||||
.PHONY: all install clean install-rc clean-rc all-rc
|
||||
.PHONY: all install clean install-rc clean-rc all-rc install-lvm install-crypt
|
||||
|
@@ -1,2 +1,9 @@
|
||||
# runit-rc
|
||||
Artix system initialization and shutdown for runit
|
||||
|
||||
Artix Linux's implementation of stage 1, stage 3, and one-shot service
|
||||
handling.
|
||||
|
||||
Contains 3 folders:
|
||||
1. stage1: only executed during system startup by /etc/runit/1, should only contain essential files for startup
|
||||
2. stage3: only executed during system shutdown by /etc/runit/3, should only contain essential files during shutdown
|
||||
3. sv.d: executed during stage 2, user-modifiable. static network, netfs mount, binfmt, etc. can be put here, all new one-shot services will also be put here
|
||||
|
103
man/service.8
Normal file
103
man/service.8
Normal file
@@ -0,0 +1,103 @@
|
||||
.TH "SERVICE" "8" "April 2019" "Artix Linux" "service"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBservice\fR \- control and manages services in Artix
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
\fBservice <command> \.\.\.\fR
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
The \fBservice\fR program reports the current status and control the state of runsv(8) services and one\-shot services\.
|
||||
.
|
||||
.P
|
||||
\fBcommand\fR is one of up, down, status, once, pause, cont, hup, alarm, interrupt, 1, 2, term, kill, or exit, or start, stop, restart, shutdown, force\-stop, force\-reload, force\-restart, force\-sutdown\.
|
||||
.
|
||||
.SH "COMMANDS"
|
||||
.
|
||||
.TP
|
||||
\fBlist [runit|rc]\fR
|
||||
List all runit and rc services\.
|
||||
.
|
||||
.TP
|
||||
\fBenable [servicename]\fR
|
||||
Immediately start the runit or oneshot service, and start them on boot\.
|
||||
.
|
||||
.TP
|
||||
\fBdisable [servicename]\fR
|
||||
Immediately stop the runit or oneshot service, and don\'t start them on boot\.
|
||||
.
|
||||
.P
|
||||
Commands below are restricted to runit(8) services only:
|
||||
.
|
||||
.TP
|
||||
\fBstatus\fR
|
||||
Report the current status of the service, and the appendant log service if available, to standard output\.
|
||||
.
|
||||
.TP
|
||||
\fBup\fR
|
||||
If the service is not running, start it\. If the service stops, restart it\.
|
||||
.
|
||||
.TP
|
||||
\fBdown\fR
|
||||
If the service is running, send it the TERM signal, and the CONT signal\. If \./run exits, start \./finish if it exists\. After it stops, do not restart service\.
|
||||
.
|
||||
.TP
|
||||
\fBonce\fR
|
||||
If the service is not runing, start it\. Do not restart it if it stops\.
|
||||
.
|
||||
.TP
|
||||
\fBexit\fR
|
||||
If the service is running, send it the TERM signal, and the CONT signal\. Do not restart the service\. If the service is down, and no log service exists, runsv(8) exits\.
|
||||
.
|
||||
.P
|
||||
Commands below apply to both runit(8) services and rc oneshot services:
|
||||
.
|
||||
.TP
|
||||
\fBstatus\fR
|
||||
Same as above\.
|
||||
.
|
||||
.TP
|
||||
\fBstart\fR
|
||||
Same as \fBup\fR, but wait up to 7 seconds for the command to take effect\. Then report the status or timeout\. If the script \fB\./check\fR exists in the directory, \fBservice\fR runs this script to check whether the service is up and available; it is considered to be available if \fB\./check\fR exits with 0\. For rc oneshot services, commands in \fBstart()\fR (and it\'s pre\- and post\- commands) will be executed immediately\.
|
||||
.
|
||||
.TP
|
||||
\fBstop\fR
|
||||
Same as \fBdown\fR, but wait up to 7 seconds for the command to take effect\. Then report the status or timeout\. For rc oneshot services, commands in \fBstop()\fR (and it\'s pre\- and post\- commands) will be executed immediately\.
|
||||
.
|
||||
.TP
|
||||
\fBreload\fR
|
||||
Same as \fBhup\fR, and additionally report the status afterwards\. For rc oneshot services, the service will be stopped and started\.
|
||||
.
|
||||
.P
|
||||
Commands below are restricted to runit(8) services only:
|
||||
.
|
||||
.TP
|
||||
\fBrestart\fR
|
||||
Send the commands \fBterm\fR, \fBcont\fR, and \fBup\fR to the service, and wait up to 7 seconds for the service to restart\. Then report the status or timeout\. If the script \fB\./check\fR exists in the directory, \fBservice\fR runs this script to check whether the service is up and available again; it is considered to be available if \fB\./check\fR exits with 0\.
|
||||
.
|
||||
.TP
|
||||
\fBshutdown\fR
|
||||
Same as \fBexit\fR, but wait up to 7 seconds for the runsv(8) process to terminate\. Then report the status or timeout\.
|
||||
.
|
||||
.TP
|
||||
\fBforce\-stop\fR
|
||||
Same as \fBdown\fR, but wait up to 7 seconds for the service to become down\. Then report the status, and on timeout send the service the \fBkill\fR command\.
|
||||
.
|
||||
.TP
|
||||
\fBforce\-reload\fR
|
||||
Send the service the \fBterm\fR and \fBcont\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status, and on timeout send the service the \fBkill\fR command\.
|
||||
.
|
||||
.TP
|
||||
\fBforce\-restart\fR
|
||||
Send the service the \fBterm\fR, \fBcont\fR and \fBup\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status, and on timeout send the service the \fBkill\fR command\. If the script \fB\./check\fR exists in the service directory, \fBservice\fR runs this script to check whether the service is up and available again; it’s considered to be available if \fB\./check\fR exits with 0\.
|
||||
.
|
||||
.TP
|
||||
\fBforce\-shutdown\fR
|
||||
Same as \fBexit\fR, but wait up to 7 seconds for the runsv(8) process to terminate\. Then report the status, and on timeout send the service the \fBkill\fR command\.
|
||||
.
|
||||
.TP
|
||||
\fBtry\-restart\fR
|
||||
if the service is running, send it the \fBterm\fR and \fBcont\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status or timeout\.
|
||||
.
|
||||
.SH "SEE ALSO"
|
||||
sv(8), runsv(8), runit(8)
|
@@ -41,6 +41,444 @@ calc_columns () {
|
||||
fi
|
||||
}
|
||||
|
||||
runit_sv_available()
|
||||
{
|
||||
[[ -d @RUNITDIR@/sv/$1 ]]
|
||||
}
|
||||
|
||||
runit_sv_enabled()
|
||||
{
|
||||
[[ -h @RUNITRUNDIR@/service/"$1" ]]
|
||||
}
|
||||
|
||||
rc_sv_available()
|
||||
{
|
||||
[[ -x @RCSVDIR@/"$1" ]]
|
||||
}
|
||||
|
||||
rc_sv_enabled()
|
||||
{
|
||||
[[ -h @RCENABLEDDIR@/"$1" ]]
|
||||
}
|
||||
|
||||
rc_sv_up()
|
||||
{
|
||||
[[ -f @RCRUNDIR@/active/$1 ]]
|
||||
}
|
||||
|
||||
ck_service()
|
||||
{
|
||||
if runit_sv_enabled "$1"; then
|
||||
runit_sv_up "$1"
|
||||
else
|
||||
rc_sv_up "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
ck_status()
|
||||
{
|
||||
if runit_sv_enabled "$1"; then
|
||||
if runit_sv_up "$1"; then
|
||||
msg_ok "$1: up, pid: $(cat @RUNITRUNDIR@/service/$1/supervise/pid)"
|
||||
else
|
||||
msg_error "$1: down"
|
||||
fi
|
||||
elif rc_sv_enabled "$1"; then
|
||||
if rc_sv_up "$1"; then
|
||||
msg_ok "$1: rc service up"
|
||||
else
|
||||
msg_ok "$1: rc service down"
|
||||
fi
|
||||
elif runit_sv_available "$1"; then
|
||||
msg_error "$1: runit service is not enabled"
|
||||
elif rc_sv_available "$1"; then
|
||||
msg_error "$1: rc service is not enabled"
|
||||
else
|
||||
msg_error "$1 is not an existing runit or rc service"
|
||||
fi
|
||||
}
|
||||
|
||||
service_status()
|
||||
{
|
||||
if ck_service "$1"; then
|
||||
STATUS="${C_DONE} up "
|
||||
else
|
||||
STATUS="${C_FAIL}down"
|
||||
fi
|
||||
if runit_sv_enabled "$1"; then
|
||||
ENABLED_STATUS="${C_MAIN}*"
|
||||
elif rc_sv_enabled "$1"; then
|
||||
ENABLED_STATUS="${C_MAIN}*"
|
||||
else
|
||||
ENABLED_STATUS=" "
|
||||
fi
|
||||
printf "${C_OTHER}[$STATUS${C_OTHER}]${C_CLEAR} ${C_OTHER}[$ENABLED_STATUS${C_OTHER}]${C_CLEAR} $1 \n"
|
||||
}
|
||||
|
||||
runit_sv_up()
|
||||
{
|
||||
runit_sv_enabled "$1" && [[ "$(cat @RUNITRUNDIR@/service/$1/supervise/stat 2>/dev/null)" == "run" ]] && [[ -s @RUNITRUNDIR@/service/$1/supervise/pid ]]
|
||||
}
|
||||
|
||||
enable_runit_sv()
|
||||
{
|
||||
ln -sf @RUNITDIR@/sv/"$1" @RUNITRUNDIR@/service/
|
||||
# this will make sure the service is enabled if ./down exists
|
||||
runit_send_signal "u" "$1"
|
||||
ck_status "$1"
|
||||
}
|
||||
|
||||
disable_runit_sv()
|
||||
{
|
||||
rm -f @RUNITRUNDIR@/service/"$1"
|
||||
msg_ok "$1: disabled"
|
||||
}
|
||||
|
||||
enable_rc_sv()
|
||||
{
|
||||
ln -sf @RCSVDIR@/"$1" @RCENABLEDDIR@/
|
||||
@RCENABLEDDIR@/"$1"/up
|
||||
[[ $? == 0 ]] && add_daemon "$1"
|
||||
}
|
||||
|
||||
disable_rc_sv()
|
||||
{
|
||||
[ -x @RCENABLEDDIR@/"$1"/down ] && @RCENABLEDDIR@/"$1"/down
|
||||
rm -f @RCENABLEDDIR@/"$1"
|
||||
[[ $? == 0 ]] && rm_daemon "$1"
|
||||
}
|
||||
|
||||
list_rc_services() {
|
||||
echo "rc services: "
|
||||
cd @RCSVDIR@ || msg_error "error!"
|
||||
for d in *; do
|
||||
have_service "$d" && daemons+=("$d")
|
||||
service_status "$d"
|
||||
done
|
||||
}
|
||||
|
||||
list_runit_services() {
|
||||
echo "runit services: "
|
||||
cd @RUNITDIR@/sv || return
|
||||
for daemon in *; do
|
||||
service_status "$daemon"
|
||||
done
|
||||
}
|
||||
|
||||
runit_send_signal() {
|
||||
if runit_sv_enabled "$2"; then
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if [[ -e @RUNITRUNDIR@/service/$2/supervise/control ]]; then
|
||||
printf "%s" "$1" > "@RUNITRUNDIR@/service/$2/supervise/control"
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
ck_status "$2"
|
||||
return 100
|
||||
fi
|
||||
}
|
||||
|
||||
have_service()
|
||||
{
|
||||
[[ -x @RCSVDIR@/$1 ]]
|
||||
}
|
||||
|
||||
### Long functions to be run in stages
|
||||
|
||||
# Check local filesystems
|
||||
fsck_all() {
|
||||
if [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline); then
|
||||
FORCEFSCK="-f"
|
||||
elif [[ -f /fastboot ]] || in_array fastboot $(< /proc/cmdline); then
|
||||
return 0
|
||||
elif [[ -e /run/initramfs/root-fsck ]]; then
|
||||
IGNORE_MOUNTED="-M"
|
||||
fi
|
||||
|
||||
fsck -A -T -C${FSCK_FD} -a -t no${NETFS//,/,no},noopts=_netdev ${IGNORE_MOUNTED} -- ${FORCEFSCK}
|
||||
}
|
||||
|
||||
# Single-user login and/or automatic reboot after fsck (if needed)
|
||||
fsck_reboot() {
|
||||
# $1 = exit code returned by fsck
|
||||
# Ignore conditions 'FS errors corrected' and 'Cancelled by the user'
|
||||
(( ($1 | 33) == 33 )) && return 0
|
||||
if (( $1 & 2 )); then
|
||||
echo
|
||||
echo "********************** REBOOT REQUIRED *********************"
|
||||
echo "* *"
|
||||
echo "* The system will be rebooted automatically in 15 seconds. *"
|
||||
echo "* *"
|
||||
echo "************************************************************"
|
||||
echo
|
||||
sleep 15
|
||||
else
|
||||
echo
|
||||
echo "***************** FILESYSTEM CHECK FAILED ****************"
|
||||
echo "* *"
|
||||
echo "* Please repair manually and reboot. Note that the root *"
|
||||
echo "* file system is currently mounted read-only. To remount *"
|
||||
echo "* it read-write, type: mount -o remount,rw / *"
|
||||
echo "* When you exit the maintenance shell, the system will *"
|
||||
echo "* reboot automatically. *"
|
||||
echo "* *"
|
||||
echo "************************************************************"
|
||||
echo
|
||||
emergency_shell
|
||||
fi
|
||||
echo "Automatic reboot in progress..."
|
||||
umount -a
|
||||
mount -o remount,ro /
|
||||
reboot -f
|
||||
exit 0
|
||||
}
|
||||
|
||||
do_fsck(){
|
||||
if [[ -x $(type -P fsck) ]]; then
|
||||
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
|
||||
declare -r fsckret=$?
|
||||
else
|
||||
declare -r fsckret=0
|
||||
fi
|
||||
fsck_reboot $fsckret
|
||||
}
|
||||
|
||||
CGROUP_OPTS=nodev,noexec,nosuid
|
||||
HAVE_CONTROLLER1_GROUPS=${HAVE_CONTROLLER1_GROUPS:-true}
|
||||
CGROUP_MODE=${CGROUP_MODE:-hybrid}
|
||||
CGROUP_CONTROLLERS=""
|
||||
|
||||
cgroup2_find_path(){
|
||||
if grep -qw cgroup2 /proc/filesystems; then
|
||||
case "${CGROUP_MODE}" in
|
||||
hybrid) printf "/sys/fs/cgroup/unified" ;;
|
||||
unified) printf "/sys/fs/cgroup" ;;
|
||||
esac
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup1_base(){
|
||||
grep -qw cgroup /proc/filesystems || return 0
|
||||
if ! mountpoint -q /sys/fs/cgroup; then
|
||||
local opts="${CGROUP_OPTS},mode=755,size=${rc_cgroupsize:-10m}"
|
||||
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
|
||||
fi
|
||||
|
||||
if ! mountpoint -q /sys/fs/cgroup/openrc; then
|
||||
local agent="@RCLIBDIR@/cgroup-release-agent"
|
||||
mkdir /sys/fs/cgroup/openrc
|
||||
mount -n -t cgroup -o none,${CGROUP_OPTS},name=openrc,release_agent="$agent" openrc /sys/fs/cgroup/openrc
|
||||
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup1_controllers(){
|
||||
${HAVE_CONTROLLER1_GROUPS} && [ -e /proc/cgroups ] && grep -qw cgroup /proc/filesystems || return 0
|
||||
while read -r name _ _ enabled _; do
|
||||
case "${enabled}" in
|
||||
1) if mountpoint -q "/sys/fs/cgroup/${name}";then continue;fi
|
||||
local x
|
||||
for x in $CGROUP_CONTROLLERS; do
|
||||
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
|
||||
continue 2
|
||||
[ "${name}" = "${x}" ] &&
|
||||
continue 2
|
||||
done
|
||||
mkdir "/sys/fs/cgroup/${name}"
|
||||
mount -n -t cgroup -o "${CGROUP_OPTS},${name}" "${name}" "/sys/fs/cgroup/${name}"
|
||||
;;
|
||||
esac
|
||||
done < /proc/cgroups
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup2_base(){
|
||||
grep -qw cgroup2 /proc/filesystems || return 0
|
||||
local base
|
||||
base="$(cgroup2_find_path)"
|
||||
mkdir -p "${base}"
|
||||
mount -t cgroup2 none -o "${CGROUP_OPTS},nsdelegate" "${base}" 2> /dev/null ||
|
||||
mount -t cgroup2 none -o "${CGROUP_OPTS}" "${base}"
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup2_controllers(){
|
||||
grep -qw cgroup2 /proc/filesystems || return 0
|
||||
local active cgroup_path x y
|
||||
cgroup_path="$(cgroup2_find_path)"
|
||||
[ -z "${cgroup_path}" ] && return 0
|
||||
[ -e "${cgroup_path}/cgroup.controllers" ] && read -r active < "${cgroup_path}/cgroup.controllers"
|
||||
for x in ${CGROUP_CONTROLLERS}; do
|
||||
for y in ${active}; do
|
||||
[ "$x" = "$y" ] && [ -e "${cgroup_path}/cgroup.subtree_control" ] &&
|
||||
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
|
||||
done
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_hybrid(){
|
||||
cgroup1_base
|
||||
cgroup2_base
|
||||
cgroup2_controllers
|
||||
cgroup1_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_legacy(){
|
||||
cgroup1_base
|
||||
cgroup1_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_unified(){
|
||||
cgroup2_base
|
||||
cgroup2_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_cgroups(){
|
||||
case "${CGROUP_MODE}" in
|
||||
hybrid) cgroups_hybrid ;;
|
||||
legacy) cgroups_legacy ;;
|
||||
unified) cgroups_unified ;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_cgs(){
|
||||
if [ -d /sys/fs/cgroup ]; then
|
||||
mount_cgroups
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
do_unlock_device() {
|
||||
# $1 = requested name
|
||||
# $2 = source device
|
||||
# $3 = password
|
||||
# $4 = options
|
||||
local open=create a=$1 b=$2 failed=0 opts
|
||||
# Ordering of options is different if you are using LUKS vs. not.
|
||||
# Use ugly swizzling to deal with it.
|
||||
# isLuks only gives an exit code but no output to stdout or stderr.
|
||||
if cryptsetup isLuks "$2" 2>/dev/null; then
|
||||
open=luksOpen
|
||||
a=$2
|
||||
b=$1
|
||||
else
|
||||
printhl "Non-LUKS partitions are not supported at the moment."
|
||||
continue
|
||||
fi
|
||||
if [[ $4 ]]; then
|
||||
for i in ${4//,/ }; do
|
||||
case $i in
|
||||
"discard") opts+="--allow-discard" ;;
|
||||
"readonly"|"read-only") opts+="--readonly" ;;
|
||||
"tries"*) opts+="-T ${i##*=}" ;;
|
||||
"keyfile-size"*) opts+="-l ${i##*=}" ;;
|
||||
"keyfile-offset"*) opts+="--keyfile-offset ${i##*=}" ;;
|
||||
"key-slot"*) opts+="-S ${i##*=}" ;;
|
||||
"luks") ;;
|
||||
*)
|
||||
printhl "The option is not currently supported at the moment."
|
||||
printhl "Please add an issue to https://github.com/artix-linux/runit-rc"
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
case $3 in
|
||||
/dev*)
|
||||
local ckdev=${3%%:*}
|
||||
local cka=${3#*:}
|
||||
local ckb=${cka#*:}
|
||||
local cka=${cka%:*}
|
||||
local ckfile=/dev/ckfile
|
||||
local ckdir=/dev/ckdir
|
||||
case ${cka} in
|
||||
*[!0-9]*)
|
||||
# Use a file on the device
|
||||
# cka is not numeric: cka=filesystem, ckb=path
|
||||
mkdir ${ckdir}
|
||||
mount -r -t ${cka} ${ckdev} ${ckdir}
|
||||
dd if=${ckdir}/${ckb} of=${ckfile} >/dev/null 2>&1
|
||||
umount ${ckdir}
|
||||
rmdir ${ckdir};;
|
||||
*)
|
||||
# Read raw data from the block device
|
||||
# cka is numeric: cka=offset, ckb=length
|
||||
dd if=${ckdev} of=${ckfile} bs=1 skip=${cka} count=${ckb} >/dev/null 2>&1;;
|
||||
esac
|
||||
cryptsetup -d ${ckfile} $opts $open "$a" "$b" >/dev/null
|
||||
dd if=/dev/urandom of=${ckfile} bs=1 count=$(stat -c %s ${ckfile}) conv=notrunc >/dev/null 2>&1
|
||||
rm ${ckfile};;
|
||||
/*)
|
||||
cryptsetup -d "$3" $opts $open "$a" "$b" >/dev/null;;
|
||||
"none" | "")
|
||||
cryptsetup $opts $open "$a" "$b" >/dev/null;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
do_unlock() {
|
||||
local name=$1 device=$2 password=$3 options=$4
|
||||
|
||||
printf "${C_MAIN}Unlocking $1${C_CLEAR}\n"
|
||||
|
||||
if [[ ${options:0:2} =~ -. ]]; then
|
||||
do_unlock_device "$name" "$device" "$password" "$options"
|
||||
return $?
|
||||
fi
|
||||
|
||||
do_unlock_device "$name" "$device" "$password" "$options"
|
||||
failed=$?
|
||||
if (( $failed )); then
|
||||
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
do_lock() {
|
||||
#status "Detaching encrypted device ${1}"
|
||||
cryptsetup luksClose "$1" >/dev/null
|
||||
}
|
||||
|
||||
read_crypttab() {
|
||||
# $1 = function to call with the split out line from the crypttab
|
||||
local line nspo failed=0
|
||||
while read line <&3; do
|
||||
[[ $line && $line != '#'* ]] || continue
|
||||
eval nspo=("${line%#*}")
|
||||
if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then
|
||||
crypto_unlocked=1
|
||||
else
|
||||
failed=1
|
||||
fi
|
||||
done 3< /etc/crypttab
|
||||
return $failed
|
||||
}
|
||||
|
||||
### End
|
||||
|
||||
run_rc_command()
|
||||
{
|
||||
eval "$1"
|
||||
}
|
||||
|
||||
emergency_shell()
|
||||
{
|
||||
msg_error "Cannot continue due to errors above, starting emergency shell."
|
||||
msg "When ready, type exit or Control+D to continue booting."
|
||||
sulogin -p
|
||||
}
|
||||
|
||||
deltext() {
|
||||
printf "${DEL_TEXT}"
|
||||
}
|
||||
@@ -53,93 +491,29 @@ printsep() {
|
||||
printf "\n${C_SEPARATOR} ------------------------------\n"
|
||||
}
|
||||
|
||||
stat_busy() {
|
||||
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
|
||||
printf "${SAVE_POSITION}"
|
||||
deltext
|
||||
printf " ${C_OTHER}[${C_BUSY}busy${C_OTHER}]${C_CLEAR} "
|
||||
msg() {
|
||||
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
|
||||
}
|
||||
|
||||
ck_daemon() {
|
||||
[[ ! -f @RCRUNDIR@/started/$1 ]]
|
||||
msg_ok() {
|
||||
printf "${C_DONE}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
|
||||
}
|
||||
|
||||
ck_failed() {
|
||||
[[ ! -f @RCRUNDIR@/failed/$1 ]]
|
||||
msg_warn() {
|
||||
printf "${C_WARN}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
|
||||
}
|
||||
|
||||
msg_error() {
|
||||
printf "${C_FAIL}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
|
||||
}
|
||||
|
||||
add_daemon() {
|
||||
[[ -d @RCRUNDIR@/started ]] || mkdir -p @RCRUNDIR@/started
|
||||
>| @RCRUNDIR@/started/"$1"
|
||||
[[ -d @RCRUNDIR@/active ]] || mkdir -p @RCRUNDIR@/active
|
||||
touch @RCRUNDIR@/active/"$1"
|
||||
}
|
||||
|
||||
rm_daemon() {
|
||||
rm -f @RCRUNDIR@/started/"$1"
|
||||
}
|
||||
|
||||
add_failed() {
|
||||
[[ -d @RCRUNDIR@/failed ]] || mkdir -p @RCRUNDIR@/failed
|
||||
>| @RCRUNDIR@/failed/"$1"
|
||||
}
|
||||
|
||||
rm_failed() {
|
||||
rm -f @RCRUNDIR@/failed/"$1"
|
||||
}
|
||||
|
||||
ck_status() {
|
||||
if ! ck_daemon "$1"; then
|
||||
stat_started
|
||||
else
|
||||
if ! ck_failed "$1"; then
|
||||
stat_failed
|
||||
else
|
||||
stat_stopped
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
stat_done() {
|
||||
if ! ck_failed "$1"; then
|
||||
rm_failed "$1"
|
||||
fi
|
||||
deltext
|
||||
printf " ${C_OTHER}[${C_DONE}done${C_OTHER}]${C_CLEAR} \n"
|
||||
}
|
||||
|
||||
stat_fail() {
|
||||
deltext
|
||||
printf " ${C_OTHER}[${C_FAIL}fail${C_OTHER}]${C_CLEAR} \n"
|
||||
}
|
||||
|
||||
stat_die() {
|
||||
if ck_failed "$1"; then
|
||||
add_failed "$1"
|
||||
fi
|
||||
stat_fail
|
||||
exit ${2:-1}
|
||||
}
|
||||
|
||||
status() {
|
||||
local quiet
|
||||
case $1 in
|
||||
-q)
|
||||
quiet=1
|
||||
;;&
|
||||
-v)
|
||||
# NOOP: supported for backwards compat
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
stat_busy "$1"
|
||||
shift
|
||||
if (( quiet )); then
|
||||
"$@" &>/dev/null
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
local ret=$?
|
||||
(( ret == 0 )) && stat_done || stat_fail
|
||||
return $ret
|
||||
rm -f @RCRUNDIR@/active/"$1"
|
||||
}
|
||||
|
||||
# usage : in_array( $needle, $haystack )
|
||||
@@ -168,7 +542,7 @@ print_leave(){
|
||||
# avoid staircase effect
|
||||
stty onlcr
|
||||
echo " "
|
||||
printhl "Initiating shutdown\n"
|
||||
printhl "Shutting down\n"
|
||||
echo " "
|
||||
}
|
||||
|
||||
@@ -177,25 +551,39 @@ run_sysinit(){
|
||||
print_welcome
|
||||
calc_columns
|
||||
|
||||
for service in ${RC_SYSINIT[@]};do
|
||||
@RCSVDIR@/"${service#*-}" start
|
||||
for stage1 in @RCLIBDIR@/stage1/*; do
|
||||
[[ -x $stage1 && -r $stage1 ]] && . $stage1
|
||||
done
|
||||
}
|
||||
|
||||
run_shutdown(){
|
||||
print_leave
|
||||
|
||||
for service in ${RC_SHUTDOWN[@]};do
|
||||
@RCSVDIR@/"${service#*-}" stop
|
||||
for stage3 in @RCLIBDIR@/stage3/*; do
|
||||
[[ -x $stage3 && -r $stage3 ]] && . $stage3
|
||||
done
|
||||
}
|
||||
|
||||
run_oneshot_services()
|
||||
{
|
||||
for files in @RCENABLEDDIR@/*; do
|
||||
$files/up
|
||||
done
|
||||
}
|
||||
|
||||
stop_oneshot_services()
|
||||
{
|
||||
for files in @RCENABLEDDIR@/*; do
|
||||
$files/down
|
||||
done
|
||||
}
|
||||
|
||||
# if [[ $1 == "start" ]]; then
|
||||
# if [[ $STARTING ]]; then
|
||||
# echo "A daemon is starting another daemon; this is unlikely to work as intended."
|
||||
# else
|
||||
# export STARTING=1
|
||||
# fi
|
||||
# if [[ $STARTING ]]; then
|
||||
# echo "A daemon is starting another daemon; this is unlikely to work as intended."
|
||||
# else
|
||||
# export STARTING=1
|
||||
# fi
|
||||
# fi
|
||||
|
||||
calc_columns
|
||||
@@ -224,10 +612,10 @@ if [[ $USECOLOR != [nN][oO] ]]; then
|
||||
C_OTHER=${C_MAIN}$(tput setaf 4) # prefix & brackets
|
||||
C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator
|
||||
C_BUSY=${C_CLEAR}$(tput setaf 6) # busy
|
||||
C_FAIL=${C_MAIN}$(tput setaf 5) # failed
|
||||
C_DONE=${C_MAIN} # completed
|
||||
C_STOP=${C_MAIN}$(tput setaf 1) # backgrounded
|
||||
C_START=${C_MAIN}$(tput setaf 2) # started
|
||||
C_FAIL=${C_MAIN}$(tput setaf 1) # failed
|
||||
C_WARN=${C_MAIN}$(tput setaf 3) # warning
|
||||
C_DONE=${C_MAIN}$(tput setaf 2) # completed
|
||||
C_START=${C_MAIN}$(tput setaf 2) # started
|
||||
C_H1=${C_MAIN} # highlight text 1
|
||||
C_H2=${C_MAIN}$(tput setaf 6) # highlight text 2
|
||||
else
|
||||
@@ -249,6 +637,3 @@ fi
|
||||
|
||||
PREFIX_REG="::"
|
||||
PREFIX_HL=" >"
|
||||
|
||||
RC_SYSINIT=$(ls @RCDIR@/sysinit)
|
||||
RC_SHUTDOWN=$(ls @RCDIR@/shutdown)
|
||||
|
0
script/modules-load.in
Executable file → Normal file
0
script/modules-load.in
Executable file → Normal file
276
script/service.in
Normal file
276
script/service.in
Normal file
@@ -0,0 +1,276 @@
|
||||
#!/bin/bash
|
||||
# shellcheck disable=1091
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
if [ $EUID != 0 ]; then
|
||||
msg_error "You must run this program as root!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
"list")
|
||||
case "$2" in
|
||||
"rc") list_rc_services ;;
|
||||
"runit") list_runit_services ;;
|
||||
"") list_rc_services; list_runit_services ;;
|
||||
*) msg_error "$1: unknown parameters" ;;
|
||||
esac
|
||||
;;
|
||||
|
||||
"up") runit_send_signal "u" "$2" ;;
|
||||
"down") runit_send_signal "d" "$2" ;;
|
||||
"once") runit_send_signal "o" "$2" ;;
|
||||
"exit") runit_send_signal "x" "$2" ;;
|
||||
"pause") runit_send_signal "p" "$2" ;;
|
||||
"cont") runit_send_signal "c" "$2" ;;
|
||||
"hup") runit_send_signal "h" "$2" ;;
|
||||
"alarm") runit_send_signal "a" "$2" ;;
|
||||
"interrupt") runit_send_signal "i" "$2" ;;
|
||||
"quit") runit_send_signal "q" "$2" ;;
|
||||
"1") runit_send_signal "1" "$2" ;;
|
||||
"2") runit_send_signal "2" "$2" ;;
|
||||
"term") runit_send_signal "t" "$2" ;;
|
||||
"kill") runit_send_signal "k" "$2" ;;
|
||||
|
||||
"status") ck_status "$2" ;;
|
||||
|
||||
"start")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "u" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if runit_sv_up "$2"; then
|
||||
if [[ -x @RUNITRUNDIR@/service/$2/check ]]; then
|
||||
@RUNITRUNDIR@/service/"$2"/check
|
||||
ret=$?
|
||||
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
((check_fail > 0)) && msg_warn "$2: check failed!"
|
||||
ck_status "$2"
|
||||
((i == 7)) && exit 1 || exit 0
|
||||
elif rc_sv_enabled "$2"; then
|
||||
@RCENABLEDDIR@/"$2"/up
|
||||
ret=$?
|
||||
(( ret == 0 )) && add_daemon "$2"
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"stop")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "d" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if ! runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && exit 1 || exit 0
|
||||
elif rc_sv_enabled "$2"; then
|
||||
[ -x @RCENABLEDDIR@/"$2"/down ] && @RCENABLEDDIR@/"$2"/down
|
||||
(( ret == 0 )) && rm_daemon "$2"
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"reload")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "h" "$2"
|
||||
elif rc_sv_enabled "$2"; then
|
||||
[ -x @RCENABLEDDIR@/"$2"/down ] && @RCENABLEDDIR@/"$2"/down
|
||||
sleep 1
|
||||
@RCENABLEDDIR@/"$2"/up
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"restart")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "t" "$2"
|
||||
runit_send_signal "c" "$2"
|
||||
runit_send_signal "u" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if runit_sv_up "$2"; then
|
||||
if [[ -x @RUNITRUNDIR@/$2/check ]]; then
|
||||
@RUNITRUNDIR@/"$2"/check
|
||||
ret=$?
|
||||
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
else
|
||||
msg_warn "Timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
((check_fail > 0)) && msg_warn "$2: check failed!"
|
||||
ck_status "$2"
|
||||
((i == 7)) && exit 1 || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"shutdown")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "x" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if ! runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && exit 1 || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"force-stop")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "d" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if ! runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && runit_send_signal "k" "$2" || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"force-reload")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "t" "$2"
|
||||
runit_send_signal "c" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && runit_send_signal "k" "$2" || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"force-restart")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "t" "$2"
|
||||
runit_send_signal "c" "$2"
|
||||
runit_send_signal "u" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if runit_sv_up "$2"; then
|
||||
if [[ -x @RUNITRUNDIR@/$2/check ]]; then
|
||||
@RUNITRUNDIR@/"$2"/check
|
||||
ret=$?
|
||||
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
((check_fail > 0)) && msg_warn "$2: check failed!"
|
||||
ck_status "$2"
|
||||
((i == 7)) && runit_send_signal "k" "$2" || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"force-shutdown")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "x" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if ! runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "$2: timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && runit_send_signal "k" "$2" || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"try-restart")
|
||||
if runit_sv_enabled "$2"; then
|
||||
runit_send_signal "t" "$2"
|
||||
runit_send_signal "c" "$2"
|
||||
for i in {1..7}; do
|
||||
sleep 0.1
|
||||
if runit_sv_up "$2"; then
|
||||
break
|
||||
else
|
||||
msg_warn "Timeout in $((8-i))"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
ck_status "$2"
|
||||
((i == 7)) && exit 1 || exit 0
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"enable")
|
||||
if runit_sv_enabled "$2" || rc_sv_enabled "$2"; then
|
||||
msg_error "$2: service is already enabled"
|
||||
elif runit_sv_available "$2"; then
|
||||
enable_runit_sv "$2"
|
||||
elif rc_sv_available "$2"; then
|
||||
enable_rc_sv "$2"
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"disable")
|
||||
if runit_sv_enabled "$2"; then
|
||||
disable_runit_sv "$2"
|
||||
elif rc_sv_enabled "$2"; then
|
||||
disable_rc_sv "$2"
|
||||
elif runit_sv_available "$2" || rc_sv_available "$2"; then
|
||||
msg_error "$2: runit/rc service is already disabled"
|
||||
fi
|
||||
ck_status "$2"
|
||||
;;
|
||||
|
||||
"")
|
||||
msg_error "usage: service command ..."
|
||||
msg_error " for details, please type \"man service\""
|
||||
exit 1
|
||||
;;
|
||||
|
||||
*)
|
||||
msg_error "$1: unrecognized command"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
12
stage1/00-pseudofs.in
Normal file
12
stage1/00-pseudofs.in
Normal file
@@ -0,0 +1,12 @@
|
||||
msg "Mounting /proc"
|
||||
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
|
||||
msg "Mounting /sys"
|
||||
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
|
||||
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
|
||||
[ -d /sys/firmware/efi ] && (mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars)
|
||||
msg "Mounting /dev"
|
||||
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
|
||||
mkdir -p /dev/{pts,shm}
|
||||
mountpoint -q /dev/pts || mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
|
||||
mountpoint -q /dev/shm || mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
|
||||
mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
|
7
stage1/01-cgroups.in
Normal file
7
stage1/01-cgroups.in
Normal file
@@ -0,0 +1,7 @@
|
||||
CGROUP_OPTS=nodev,noexec,nosuid
|
||||
HAVE_CONTROLLER1_GROUPS=${HAVE_CONTROLLER1_GROUPS:-true}
|
||||
CGROUP_MODE=${CGROUP_MODE:-hybrid}
|
||||
CGROUP_CONTROLLERS=""
|
||||
|
||||
msg "Mounting cgroups"
|
||||
mount_cgs
|
4
stage1/01-static-devnodes.in
Normal file
4
stage1/01-static-devnodes.in
Normal file
@@ -0,0 +1,4 @@
|
||||
# The generated file will be run by the next script
|
||||
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
|
||||
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
|
||||
tmpfiles --prefix=/dev --create --boot || emergency_shell
|
6
stage1/02-modules.in
Normal file
6
stage1/02-modules.in
Normal file
@@ -0,0 +1,6 @@
|
||||
# In the off-chance someone compiled their own Linux kernel without
|
||||
# modules support
|
||||
[[ ! -e /proc/modules ]] && return 0
|
||||
|
||||
msg "Loading user-specified modules"
|
||||
modules-load
|
6
stage1/02-udev.in
Normal file
6
stage1/02-udev.in
Normal file
@@ -0,0 +1,6 @@
|
||||
msg "Starting udev"
|
||||
udevd --daemon
|
||||
udevadm trigger --action=add --type=subsystems
|
||||
udevadm trigger --action=add --type=devices
|
||||
msg "Waiting for udev uevents to be processed"
|
||||
udevadm settle
|
17
stage1/03-console-setup.in
Normal file
17
stage1/03-console-setup.in
Normal file
@@ -0,0 +1,17 @@
|
||||
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
|
||||
TTYS=${TTYS:-6}
|
||||
_index=0
|
||||
[ -n "$FONT" ] && msg "Setting up TTY font to ${FONT}"
|
||||
while [ ${_index} -le "$TTYS" ]; do
|
||||
if [ -n "$FONT" ]; then
|
||||
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
|
||||
"$FONT" -C "/dev/tty${_index}"
|
||||
fi
|
||||
printf "\033%s" "%G" >/dev/tty${_index}
|
||||
_index=$((_index + 1))
|
||||
done
|
||||
|
||||
if [ -n "$KEYMAP" ]; then
|
||||
msg "Setting up keymap to ${KEYMAP}"
|
||||
loadkeys -q -u "${KEYMAP}"
|
||||
fi
|
10
stage1/03-hwclock.in
Normal file
10
stage1/03-hwclock.in
Normal file
@@ -0,0 +1,10 @@
|
||||
HWCLOCK_PARAMS="--systz"
|
||||
HARDWARECLOCK=${HARDWARECLOCK:-UTC}
|
||||
|
||||
case $HARDWARECLOCK in
|
||||
UTC) HWCLOCK_PARAMS+=" --utc --noadjfile" ;;
|
||||
localtime) HWCLOCK_PARAMS+=" --localtime --noadjfile" ;;
|
||||
*) HWCLOCK_PARAMS="" ;;
|
||||
esac
|
||||
|
||||
hwclock $HWCLOCK_PARAMS || emergency_shell
|
2
stage1/04-rootfs.in
Normal file
2
stage1/04-rootfs.in
Normal file
@@ -0,0 +1,2 @@
|
||||
msg "Remounting rootfs read-only"
|
||||
mount -o remount,ro / || emergency_shell
|
2
stage1/05-btrfs.in
Normal file
2
stage1/05-btrfs.in
Normal file
@@ -0,0 +1,2 @@
|
||||
msg "Activating btrfs devices"
|
||||
btrfs device scan || emergency_shell
|
2
stage1/05-lvm.in
Normal file
2
stage1/05-lvm.in
Normal file
@@ -0,0 +1,2 @@
|
||||
msg "Activating LVM devices"
|
||||
vgchange --sysinit -a y || emergency_shell
|
8
stage1/06-cryptsetup.in
Normal file
8
stage1/06-cryptsetup.in
Normal file
@@ -0,0 +1,8 @@
|
||||
if [[ -r /etc/crypttab ]]; then
|
||||
msg "Unlocking encrypted devices"
|
||||
read_crypttab do_unlock
|
||||
if [[ -x /usr/bin/vgchange && -x @RCLIBDIR@/stage1/05-lvm ]]; then
|
||||
msg "Activating LVM for encrypted devices"
|
||||
vgchange --sysinit -a y >/dev/null || emergency_shell
|
||||
fi
|
||||
fi
|
14
stage1/06-fsck.in
Normal file
14
stage1/06-fsck.in
Normal file
@@ -0,0 +1,14 @@
|
||||
[ -f /forcefsck ] && FORCEFSCK="-f"
|
||||
[ -f /fastboot ] && return 0
|
||||
|
||||
for arg in $(< /proc/cmdline); do
|
||||
case $arg in
|
||||
fastboot) return 0 ;;
|
||||
forcefsck) FORCEFSCK="-f" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
msg "Checking filesystems"
|
||||
fsck -A -T -a -t no${NET_FS//,/,no},noopts=_netdev $FORCEFSCK
|
||||
fsckret=$?
|
||||
fsck_reboot $fsckret
|
8
stage1/07-mountfs.in
Normal file
8
stage1/07-mountfs.in
Normal file
@@ -0,0 +1,8 @@
|
||||
msg "Remounting root read-write"
|
||||
mount -o remount,rw / || emergency_shell
|
||||
|
||||
msg "Mounting filesystems"
|
||||
mount -a -t "no${NETFS//,/,no}" -O no_netdev || emergency_shell
|
||||
|
||||
msg "Mounting swap"
|
||||
swapon -a || emergency_shell
|
25
stage1/08-misc.in
Normal file
25
stage1/08-misc.in
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
msg "Initializing random seed"
|
||||
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
|
||||
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
|
||||
|
||||
msg "Setting up loopback interface"
|
||||
ip link set up dev lo
|
||||
|
||||
[ -r /etc/hostname ] && [ -s /etc/hostname ] && read -r HOSTNAME < /etc/hostname
|
||||
if [ -n "$HOSTNAME" ]; then
|
||||
msg "Setting hostname to ${HOSTNAME}"
|
||||
printf "%s" "$HOSTNAME" >| /proc/sys/kernel/hostname
|
||||
else
|
||||
msg_warn "/etc/hostname is empty, hostname set to artixlinux"
|
||||
fi
|
||||
|
||||
if [ -x /usr/bin/tmpfiles ]; then
|
||||
msg "Setting up tmpfiles"
|
||||
tmpfiles --exclude-prefix=/dev --create --remove --boot
|
||||
fi
|
||||
|
||||
if [ -x /usr/bin/sysusers ]; then
|
||||
msg "Setting up sysusers"
|
||||
sysusers
|
||||
fi
|
2
stage1/11-sysctl.in
Normal file
2
stage1/11-sysctl.in
Normal file
@@ -0,0 +1,2 @@
|
||||
msg "Loading sysctl settings"
|
||||
sysctl --system
|
17
stage1/99-cleanup.in
Normal file
17
stage1/99-cleanup.in
Normal file
@@ -0,0 +1,17 @@
|
||||
msg "Cleaning up"
|
||||
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
|
||||
fi
|
||||
if [ ! -e /var/log/btmp ]; then
|
||||
install -m0664 -o root -g utmp /dev/null /var/log/btmp
|
||||
fi
|
||||
install -dm1777 /tmp/.X11-unix /tmp/.ICE-unix
|
||||
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot
|
||||
|
||||
if [ -e /proc/sys/kernel/dmesg_restrict ] &&
|
||||
(( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
|
||||
install -Tm 0600 <( dmesg ) /var/log/dmesg.log
|
||||
else
|
||||
install -Tm 0644 <( dmesg ) /var/log/dmesg.log
|
||||
fi
|
7
stage3/10-misc.in
Normal file
7
stage3/10-misc.in
Normal file
@@ -0,0 +1,7 @@
|
||||
msg "Saving random seed"
|
||||
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1)
|
||||
|
||||
halt -w # utmp
|
||||
|
||||
msg "Stopping udev"
|
||||
udevadm control --exit
|
5
stage3/30-killall.in
Normal file
5
stage3/30-killall.in
Normal file
@@ -0,0 +1,5 @@
|
||||
msg "Sending TERM signal to processes"
|
||||
pkill --inverse -s0,1 -TERM
|
||||
sleep 1
|
||||
msg "Sending KILL signal to processes"
|
||||
pkill --inverse -s0,1 -KILL
|
32
stage3/40-filesystem.in
Normal file
32
stage3/40-filesystem.in
Normal file
@@ -0,0 +1,32 @@
|
||||
msg "Deactivating swap"
|
||||
swapoff -a
|
||||
|
||||
msg "Unmounting filesystems"
|
||||
#umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
|
||||
findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | {
|
||||
while read -r target fstype options; do
|
||||
# interpret the ascii chars, such as \x20 (space)
|
||||
printf -v target '%b' "$target"
|
||||
# match only targeted fstypes
|
||||
if [[ $1 && $1 != "$fstype" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# do not unmount API filesystems
|
||||
if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# avoid networked devices
|
||||
IFS=, read -ra opts <<< "$options"
|
||||
if in_array _netdev "${opts[@]}"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
mounts=("$target" "${mounts[@]}")
|
||||
done
|
||||
|
||||
if (( ${#mounts[*]} )); then
|
||||
umount -r "${mounts[@]}" || return 1
|
||||
fi
|
||||
}
|
7
stage3/40-lvm.in
Normal file
7
stage3/40-lvm.in
Normal file
@@ -0,0 +1,7 @@
|
||||
msg "Deactivating LVM volumes"
|
||||
if [[ -x /usr/bin/vgchange ]]; then
|
||||
vgs="$(vgs | wc -l)"
|
||||
if [[ $vgs -gt 0 ]]; then
|
||||
vgchange -a n
|
||||
fi
|
||||
fi
|
9
stage3/50-cryptsetup.in
Normal file
9
stage3/50-cryptsetup.in
Normal file
@@ -0,0 +1,9 @@
|
||||
msg "Deactivating encrypted devices"
|
||||
read_crypttab do_lock
|
||||
if [[ -x /usr/bin/vgchange && -x @RCLIBDIR@/stage3/40-lvm ]]; then
|
||||
msg "Deactivating LVM volumes for encrypted devices"
|
||||
vgs="$(vgs | wc -l)"
|
||||
if [[ $vgs -gt 0 ]]; then
|
||||
vgchange -a n
|
||||
fi
|
||||
fi
|
4
stage3/99-remount-root.in
Normal file
4
stage3/99-remount-root.in
Normal file
@@ -0,0 +1,4 @@
|
||||
msg "Remounting rootfs read-only"
|
||||
mount -o remount,ro /
|
||||
|
||||
sync
|
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
mount_binfmt(){
|
||||
mountpoint -q /proc/sys/fs/binfmt_misc || \
|
||||
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc || return 1
|
||||
|
||||
for path in /usr/lib/binfmt.d /etc/binfmt.d /run/binfmt.d; do
|
||||
[[ ! -d $path ]] && continue
|
||||
[[ -z "$(ls $path)" ]] && continue
|
||||
grep "^:" $path/* | \
|
||||
while read -r line; do
|
||||
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register || return 1
|
||||
done
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Running binfmt"
|
||||
mount_binfmt || stat_die binfmt
|
||||
add_daemon binfmt
|
||||
stat_done binfmt
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
16
sv.d/binfmt/up
Executable file
16
sv.d/binfmt/up
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
mountpoint -q /proc/sys/fs/binfmt_misc || \
|
||||
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
|
||||
ret=$?
|
||||
if [ $ret -gt 0 ]; then
|
||||
msg_error "Cannot mount binfmt!"
|
||||
return 1
|
||||
fi
|
||||
for path in /usr/lib/binfmt.d /usr/local/binfmt.d /run/binfmt.d /etc/binfmt.d; do
|
||||
[[ ! -d $path ]] && continue
|
||||
[[ -z "$(ls $path)" ]] && continue
|
||||
grep "^:" $path/* | \
|
||||
while read -r line; do
|
||||
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register || return 1
|
||||
done
|
||||
done
|
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
start_bootlogd(){
|
||||
bootlogd -p /run/bootlogd.pid -l /var/log/boot.log || return 1
|
||||
}
|
||||
|
||||
stop_bootlogd(){
|
||||
[[ -f /run/bootlogd.pid ]] || return 0
|
||||
touch /var/log/boot.log
|
||||
kill $(< /run/bootlogd.pid)
|
||||
rm -f /run/bootlogd.pid
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting bootlogd"
|
||||
start_bootlogd || stat_die bootlogd
|
||||
add_daemon bootlogd
|
||||
stat_done bootlogd
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping bootlogd"
|
||||
stop_bootlogd || stat_die bootlogd
|
||||
rm_daemon bootlogd
|
||||
stat_done bootlogd
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
131
sv.d/cgroups.in
131
sv.d/cgroups.in
@@ -1,131 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
. @RCDIR@/rc.conf
|
||||
|
||||
CGROUP_OPTS=nodev,noexec,nosuid
|
||||
HAVE_CONTROLLER1_GROUPS=${HAVE_CONTROLLER1_GROUPS:-true}
|
||||
CGROUP_MODE=${CGROUP_MODE:-hybrid}
|
||||
CGROUP_CONTROLLERS=""
|
||||
|
||||
cgroup2_find_path(){
|
||||
if grep -qw cgroup2 /proc/filesystems; then
|
||||
case "${CGROUP_MODE}" in
|
||||
hybrid) printf "/sys/fs/cgroup/unified" ;;
|
||||
unified) printf "/sys/fs/cgroup" ;;
|
||||
esac
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup1_base(){
|
||||
grep -qw cgroup /proc/filesystems || return 0
|
||||
if ! mountpoint -q /sys/fs/cgroup; then
|
||||
local opts="${CGROUP_OPTS},mode=755,size=${rc_cgroupsize:-10m}"
|
||||
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
|
||||
fi
|
||||
|
||||
if ! mountpoint -q /sys/fs/cgroup/openrc; then
|
||||
local agent="@RCLIBDIR@/cgroup-release-agent"
|
||||
mkdir /sys/fs/cgroup/openrc
|
||||
mount -n -t cgroup -o none,${CGROUP_OPTS},name=openrc,release_agent="$agent" openrc /sys/fs/cgroup/openrc
|
||||
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup1_controllers(){
|
||||
${HAVE_CONTROLLER1_GROUPS} && [ -e /proc/cgroups ] && grep -qw cgroup /proc/filesystems || return 0
|
||||
while read -r name _ _ enabled _; do
|
||||
case "${enabled}" in
|
||||
1) if mountpoint -q "/sys/fs/cgroup/${name}";then continue;fi
|
||||
local x
|
||||
for x in $CGROUP_CONTROLLERS; do
|
||||
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
|
||||
continue 2
|
||||
[ "${name}" = "${x}" ] &&
|
||||
continue 2
|
||||
done
|
||||
mkdir "/sys/fs/cgroup/${name}"
|
||||
mount -n -t cgroup -o "${CGROUP_OPTS},${name}" "${name}" "/sys/fs/cgroup/${name}"
|
||||
;;
|
||||
esac
|
||||
done < /proc/cgroups
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup2_base(){
|
||||
grep -qw cgroup2 /proc/filesystems || return 0
|
||||
local base
|
||||
base="$(cgroup2_find_path)"
|
||||
mkdir -p "${base}"
|
||||
mount -t cgroup2 none -o "${CGROUP_OPTS},nsdelegate" "${base}" 2> /dev/null ||
|
||||
mount -t cgroup2 none -o "${CGROUP_OPTS}" "${base}"
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroup2_controllers(){
|
||||
grep -qw cgroup2 /proc/filesystems || return 0
|
||||
local active cgroup_path x y
|
||||
cgroup_path="$(cgroup2_find_path)"
|
||||
[ -z "${cgroup_path}" ] && return 0
|
||||
[ -e "${cgroup_path}/cgroup.controllers" ] && read -r active < "${cgroup_path}/cgroup.controllers"
|
||||
for x in ${CGROUP_CONTROLLERS}; do
|
||||
for y in ${active}; do
|
||||
[ "$x" = "$y" ] && [ -e "${cgroup_path}/cgroup.subtree_control" ] &&
|
||||
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
|
||||
done
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_hybrid(){
|
||||
cgroup1_base
|
||||
cgroup2_base
|
||||
cgroup2_controllers
|
||||
cgroup1_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_legacy(){
|
||||
cgroup1_base
|
||||
cgroup1_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
cgroups_unified(){
|
||||
cgroup2_base
|
||||
cgroup2_controllers
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_cgroups(){
|
||||
case "${CGROUP_MODE}" in
|
||||
hybrid) cgroups_hybrid ;;
|
||||
legacy) cgroups_legacy ;;
|
||||
unified) cgroups_unified ;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_cgs(){
|
||||
if [ -d /sys/fs/cgroup ];then
|
||||
mount_cgroups
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting cgroups filesystem"
|
||||
mount_cgs || stat_die cgroups
|
||||
add_daemon cgroups
|
||||
stat_done cgroups
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
cleaning(){
|
||||
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
|
||||
fi
|
||||
if [ ! -e /var/log/btmp ]; then
|
||||
install -m0600 -o root -g utmp /dev/null /var/log/btmp
|
||||
fi
|
||||
|
||||
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting cleanup"
|
||||
cleaning
|
||||
add_daemon cleanup
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping cleanup"
|
||||
halt -w || stat_die
|
||||
rm_daemon cleanup
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
config(){
|
||||
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
|
||||
TTYS=${TTYS:-6}
|
||||
_index=0
|
||||
while [ ${_index} -le $TTYS ]; do
|
||||
if [ -n "$FONT" ]; then
|
||||
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
|
||||
$FONT -C "/dev/tty${_index}"
|
||||
fi
|
||||
printf "\033%s" "%G" >/dev/tty${_index}
|
||||
_index=$((_index + 1))
|
||||
done
|
||||
if [ -n "$KEYMAP" ]; then
|
||||
loadkeys -q -u ${KEYMAP}
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting console-setup"
|
||||
config
|
||||
add_daemon console-setup
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,134 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
do_unlock_device() {
|
||||
# $1 = requested name
|
||||
# $2 = source device
|
||||
# $3 = password
|
||||
# $4 = options
|
||||
local open=create a=$1 b=$2 failed=0 opts
|
||||
# Ordering of options is different if you are using LUKS vs. not.
|
||||
# Use ugly swizzling to deal with it.
|
||||
# isLuks only gives an exit code but no output to stdout or stderr.
|
||||
if cryptsetup isLuks "$2" 2>/dev/null; then
|
||||
open=luksOpen
|
||||
a=$2
|
||||
b=$1
|
||||
else
|
||||
printhl "Non-LUKS partitions are not supported at the moment."
|
||||
continue
|
||||
fi
|
||||
if [[ $4 ]]; then
|
||||
for i in ${4//,/ }; do
|
||||
case $i in
|
||||
"discard") opts+="--allow-discard" ;;
|
||||
"readonly"|"read-only") opts+="--readonly" ;;
|
||||
"tries"*) opts+="-T ${i##*=}" ;;
|
||||
"keyfile-size"*) opts+="-l ${i##*=}" ;;
|
||||
"keyfile-offset"*) opts+="--keyfile-offset ${i##*=}" ;;
|
||||
"key-slot"*) opts+="-S ${i##*=}" ;;
|
||||
*)
|
||||
printhl "The option is not currently supported at the moment."
|
||||
printhl "Please add an issue to https://github.com/artix-linux/runit-rc"
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
case $3 in
|
||||
/dev*)
|
||||
local ckdev=${3%%:*}
|
||||
local cka=${3#*:}
|
||||
local ckb=${cka#*:}
|
||||
local cka=${cka%:*}
|
||||
local ckfile=/dev/ckfile
|
||||
local ckdir=/dev/ckdir
|
||||
case ${cka} in
|
||||
*[!0-9]*)
|
||||
# Use a file on the device
|
||||
# cka is not numeric: cka=filesystem, ckb=path
|
||||
mkdir ${ckdir}
|
||||
mount -r -t ${cka} ${ckdev} ${ckdir}
|
||||
dd if=${ckdir}/${ckb} of=${ckfile} >/dev/null 2>&1
|
||||
umount ${ckdir}
|
||||
rmdir ${ckdir};;
|
||||
*)
|
||||
# Read raw data from the block device
|
||||
# cka is numeric: cka=offset, ckb=length
|
||||
dd if=${ckdev} of=${ckfile} bs=1 skip=${cka} count=${ckb} >/dev/null 2>&1;;
|
||||
esac
|
||||
cryptsetup -d ${ckfile} $opts $open "$a" "$b" >/dev/null
|
||||
dd if=/dev/urandom of=${ckfile} bs=1 count=$(stat -c %s ${ckfile}) conv=notrunc >/dev/null 2>&1
|
||||
rm ${ckfile};;
|
||||
/*)
|
||||
cryptsetup -d "$3" $opts $open "$a" "$b" >/dev/null;;
|
||||
"none" | "")
|
||||
cryptsetup $opts $open "$a" "$b" >/dev/null;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
do_unlock() {
|
||||
local name=$1 device=$2 password=$3 options=$4
|
||||
|
||||
printf "${C_MAIN}Unlocking $1${C_CLEAR}\n"
|
||||
|
||||
if [[ ${options:0:2} =~ -. ]]; then
|
||||
do_unlock_device "$name" "$device" "$password" "$options"
|
||||
return $?
|
||||
fi
|
||||
|
||||
do_unlock_device "$name" "$device" "$password" "$options"
|
||||
esac
|
||||
failed=$?
|
||||
if (( $failed )); then
|
||||
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
|
||||
do_lock() {
|
||||
#status "Detaching encrypted device ${1}"
|
||||
cryptsetup luksClose "$1" >/dev/null
|
||||
}
|
||||
|
||||
read_crypttab() {
|
||||
# $1 = function to call with the split out line from the crypttab
|
||||
local line nspo failed=0
|
||||
while read line <&3; do
|
||||
[[ $line && $line != '#'* ]] || continue
|
||||
eval nspo=("${line%#*}")
|
||||
if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then
|
||||
crypto_unlocked=1
|
||||
else
|
||||
failed=1
|
||||
fi
|
||||
done 3< /etc/crypttab
|
||||
return $failed
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting encrypted devices"
|
||||
read_crypttab do_unlock
|
||||
rc=$?
|
||||
vgchange --sysinit -a y >/dev/null
|
||||
(( rc || $? )) && stat_die
|
||||
add_daemon cryptsetup
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping encrypted devices"
|
||||
vgchange --sysinit -a n &>/dev/null
|
||||
rc=$?
|
||||
read_crypttab do_lock
|
||||
(( rc || $? )) && stat_die
|
||||
rm_daemon cryptsetup
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
mount_devfs(){
|
||||
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
|
||||
mkdir -p /dev/{pts,shm}
|
||||
mountpoint -q /dev/pts || mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
|
||||
mountpoint -q /dev/shm || mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
|
||||
mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting dev filesystem"
|
||||
mount_devfs
|
||||
add_daemon devfs
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
config(){
|
||||
if [[ -e /proc/sys/kernel/dmesg_restrict ]] &&
|
||||
(( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
|
||||
install -Tm 0600 <( dmesg ) /var/log/dmesg.log
|
||||
else
|
||||
install -Tm 0644 <( dmesg ) /var/log/dmesg.log
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Saving dmesg log"
|
||||
config
|
||||
add_daemon dmesg
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
config(){
|
||||
unset HOSTNAME
|
||||
|
||||
if [[ -s /etc/hostname ]]; then
|
||||
HOSTNAME=$(< /etc/hostname)
|
||||
fi
|
||||
|
||||
if [[ $HOSTNAME ]]; then
|
||||
echo "$HOSTNAME" >| /proc/sys/kernel/hostname
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting hostname"
|
||||
config
|
||||
add_daemon hostname
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
HWCLOCK_PARAMS="--systz"
|
||||
HARDWARECLOCK=${HARDWARECLOCK:-UTC}
|
||||
|
||||
case $HARDWARECLOCK in
|
||||
UTC) HWCLOCK_PARAMS+=" --utc --noadjfile" ;;
|
||||
localtime) HWCLOCK_PARAMS+=" --localtime --noadjfile" ;;
|
||||
*) HWCLOCK_PARAMS="";;
|
||||
esac
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Adjusting hwclock"
|
||||
hwclock $HWCLOCK_PARAMS || stat_die
|
||||
add_daemon hwclock
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Adjusting hwclock"
|
||||
hwclock --adjust $HWCLOCK_PARAMS || stat_die
|
||||
rm_daemon hwclock
|
||||
stat_done
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
sleep 2
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop|restart}"
|
||||
;;
|
||||
esac
|
||||
|
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
conig(){
|
||||
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
|
||||
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting kmod-static-nodes"
|
||||
conig
|
||||
add_daemon kmod-static-nodes
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting monitoring of LVM2 groups"
|
||||
vgchange --monitor y >/dev/null || stat_die
|
||||
add_daemon lvm-monitoring
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping monitoring of LVM2 groups"
|
||||
vgchange --monitor n || stat_die
|
||||
rm_daemon lvm-monitoring
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
22
sv.d/lvm.in
22
sv.d/lvm.in
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting LVM2 groups"
|
||||
vgchange --sysinit -a y >/dev/null || stat_die
|
||||
add_daemon lvm
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping LVM2 groups"
|
||||
vgchange --sysinit -a n &>/dev/null || stat_die
|
||||
rm_daemon lvm
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
87
sv.d/misc.in
87
sv.d/misc.in
@@ -1,87 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
# Check local filesystems
|
||||
fsck_all() {
|
||||
if [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline); then
|
||||
FORCEFSCK="-f"
|
||||
elif [[ -f /fastboot ]] || in_array fastboot $(< /proc/cmdline); then
|
||||
return 0
|
||||
elif [[ -e /run/initramfs/root-fsck ]]; then
|
||||
IGNORE_MOUNTED="-M"
|
||||
fi
|
||||
|
||||
fsck -A -T -C${FSCK_FD} -a -t no${NETFS//,/,no},noopts=_netdev ${IGNORE_MOUNTED} -- ${FORCEFSCK}
|
||||
}
|
||||
|
||||
# Single-user login and/or automatic reboot after fsck (if needed)
|
||||
fsck_reboot() {
|
||||
# $1 = exit code returned by fsck
|
||||
# Ignore conditions 'FS errors corrected' and 'Cancelled by the user'
|
||||
(( ($1 | 33) == 33 )) && return 0
|
||||
if (( $1 & 2 )); then
|
||||
echo
|
||||
echo "********************** REBOOT REQUIRED *********************"
|
||||
echo "* *"
|
||||
echo "* The system will be rebooted automatically in 15 seconds. *"
|
||||
echo "* *"
|
||||
echo "************************************************************"
|
||||
echo
|
||||
sleep 15
|
||||
else
|
||||
echo
|
||||
echo "***************** FILESYSTEM CHECK FAILED ****************"
|
||||
echo "* *"
|
||||
echo "* Please repair manually and reboot. Note that the root *"
|
||||
echo "* file system is currently mounted read-only. To remount *"
|
||||
echo "* it read-write, type: mount -o remount,rw / *"
|
||||
echo "* When you exit the maintenance shell, the system will *"
|
||||
echo "* reboot automatically. *"
|
||||
echo "* *"
|
||||
echo "************************************************************"
|
||||
echo
|
||||
sulogin -p
|
||||
fi
|
||||
echo "Automatic reboot in progress..."
|
||||
umount -a
|
||||
mount -o remount,ro /
|
||||
reboot -f
|
||||
exit 0
|
||||
}
|
||||
|
||||
do_fsck(){
|
||||
if [[ -x $(type -P fsck) ]]; then
|
||||
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
|
||||
declare -r fsckret=$?
|
||||
else
|
||||
declare -r fsckret=0
|
||||
fi
|
||||
fsck_reboot $fsckret
|
||||
}
|
||||
|
||||
kill_all(){
|
||||
pkill --inverse -s0,1 -TERM
|
||||
sleep 1
|
||||
pkill --inverse -s0,1 -KILL
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Checking filesystems"
|
||||
do_fsck
|
||||
add_daemon misc
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Running kill-all"
|
||||
kill_all
|
||||
rm_daemon misc
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
load_modules() {
|
||||
local rc=0
|
||||
|
||||
/usr/bin/modules-load
|
||||
(( rc+=$? ))
|
||||
|
||||
return $rc
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Loading user-specified modules"
|
||||
load_modules || stat_die modules
|
||||
add_daemon modules
|
||||
stat_done modules
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting mount-all"
|
||||
mount -a -t "no${NETFS//,/,no}" -O no_netdev || stat_die mount-all
|
||||
add_daemon mount-all
|
||||
stat_done mount-all
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting net-lo"
|
||||
ip link set up dev lo || stat_die
|
||||
add_daemon net-lo
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting network filesystems"
|
||||
mount -a -t "$NETFS"
|
||||
rc=$?
|
||||
mount -a -O _netdev
|
||||
(( rc || $? )) && stat_die
|
||||
add_daemon netfs
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Unmounting network filesystems"
|
||||
umount -a -f -O _netdev
|
||||
rc=$?
|
||||
umount -a -f -t "$NETFS"
|
||||
(( rc || $? )) && stat_die
|
||||
rm_daemon netfs
|
||||
stat_done
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
sleep 1
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
8
sv.d/netmount/down
Executable file
8
sv.d/netmount/down
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
umount -a -f -t "$NETFS"
|
||||
ret=$?
|
||||
[ $ret != 0 ] && umount -a -f -l -t "$NETFS"
|
||||
|
||||
umount -a -f -O _netdev
|
||||
ret=$?
|
||||
[ $ret != 0 ] && umount -a -f -l -O _netdev
|
3
sv.d/netmount/up
Executable file
3
sv.d/netmount/up
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
mount -a -t "$NETFS" || return 1
|
||||
mount -a -O _netdev || return 1
|
@@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
mount_procfs(){
|
||||
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting proc filesystem"
|
||||
mount_procfs
|
||||
add_daemon procfs
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,32 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
load_seed(){
|
||||
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
|
||||
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
|
||||
}
|
||||
|
||||
save_seed(){
|
||||
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting random-seed"
|
||||
load_seed
|
||||
add_daemon random-seed
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping random-seed"
|
||||
save_seed
|
||||
rm_daemon random-seed
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Remounting root filesystem rw"
|
||||
mount -o remount,rw / || stat_die remount-root
|
||||
add_daemon remount-root
|
||||
stat_done remount-root
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Remounting root filesystem ro"
|
||||
mount -o remount,ro / || stat_die remount-root
|
||||
sync
|
||||
rm_daemon remount-root
|
||||
stat_done remount-root
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
63
sv.d/root.in
63
sv.d/root.in
@@ -1,63 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
mount_fs(){
|
||||
findmnt / --options ro &>/dev/null || mount -o remount,ro / || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
# umount_fs(){
|
||||
# umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
|
||||
# }
|
||||
|
||||
umount_fs() {
|
||||
findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | {
|
||||
while read -r target fstype options; do
|
||||
# interpret the ascii chars, such as \x20 (space)
|
||||
printf -v target '%b' "$target"
|
||||
# match only targeted fstypes
|
||||
if [[ $1 && $1 != "$fstype" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# do not unmount API filesystems
|
||||
if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# avoid networked devices
|
||||
IFS=, read -ra opts <<< "$options"
|
||||
if in_array _netdev "${opts[@]}"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
mounts=("$target" "${mounts[@]}")
|
||||
done
|
||||
|
||||
if (( ${#mounts[*]} )); then
|
||||
umount -r "${mounts[@]}" || return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting filesystems"
|
||||
mount_fs || stat_die root
|
||||
add_daemon root
|
||||
stat_done root
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Unounting filesystems"
|
||||
umount_fs || stat_die root
|
||||
rm_daemon root
|
||||
stat_done root
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
11
sv.d/staticnet/conf
Normal file
11
sv.d/staticnet/conf
Normal file
@@ -0,0 +1,11 @@
|
||||
# The interface to be used
|
||||
#INTERFACE="enp3s0"
|
||||
|
||||
# The IP address, in CIDR notation
|
||||
#IPADDR="192.168.1.2/24"
|
||||
|
||||
# The broadcast address, leave it commented to determine it automatically
|
||||
#BROADCAST="192.168.1.255"
|
||||
|
||||
# IP routing gateway
|
||||
#ROUTE="default via 192.168.1.1"
|
4
sv.d/staticnet/down
Executable file
4
sv.d/staticnet/down
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
[ -r conf ] && . ./conf
|
||||
ip addr del "${IPADDR}" dev "${INTERFACE}"
|
||||
ip route del "${ROUTE}" dev "${INTERFACE}"
|
11
sv.d/staticnet/up
Executable file
11
sv.d/staticnet/up
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
[ -r conf ] && . ./conf
|
||||
if [ -z "${INTERFACE}" ]; then
|
||||
msg_error "Interface has not been set! See ./conf for more details"; return 1
|
||||
elif [ -z "${IPADDR}" ]; then
|
||||
msg_error "IP address has not been set! See /etc/rc/sv.d/staticnet/conf for more details"; return 1
|
||||
elif [ -z "${ROUTE}" ]; then
|
||||
msg_error "IP route has not been set! See /etc/rc/sv.d/staticnet/conf for more details"; return 1
|
||||
fi
|
||||
ip addr add "${IPADDR}" broadcast "${BROADCAST:=+}" dev "${INTERFACE}"
|
||||
ip route add "${ROUTE}" dev "${INTERFACE}"
|
23
sv.d/swap.in
23
sv.d/swap.in
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Activating swap"
|
||||
swapon -a || stat_die swap
|
||||
add_daemon swap
|
||||
stat_done swap
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Deactivating swap"
|
||||
swapoff -a || stat_die swap
|
||||
rm_daemon swap
|
||||
stat_done swap
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Loading sysctl settings"
|
||||
sysctl --system || stat_die sysctl
|
||||
add_daemon sysctl
|
||||
stat_done sysctl
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
mount_sysfs(){
|
||||
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
|
||||
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
|
||||
[ -d /sys/firmware/efi ] && (mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars)
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Mounting sys filesystem"
|
||||
mount_sysfs
|
||||
add_daemon sysfs
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting sysusers"
|
||||
sysusers
|
||||
add_daemon sysusers
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Setting timezone"
|
||||
zonefile=/usr/share/zoneinfo/$TIMEZONE
|
||||
|
||||
# [[ $TIMEZONE ]] || return 1
|
||||
|
||||
if [[ ! -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
|
||||
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
|
||||
fi
|
||||
add_daemon timezone
|
||||
stat_done
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Setting timezone"
|
||||
zonefile=/usr/share/zoneinfo/$TIMEZONE
|
||||
|
||||
# [[ $TIMEZONE ]] || return 1
|
||||
|
||||
if [[ ! -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
|
||||
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
|
||||
fi
|
||||
rm_daemon timezone
|
||||
stat_done
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting tmpfiles-dev"
|
||||
tmpfiles --prefix=/dev --create --boot || stat_die tmpfiles-dev
|
||||
add_daemon tmpfiles-dev
|
||||
stat_done tmpfiles-dev
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Starting tmpfiles-setup"
|
||||
tmpfiles --exclude-prefix=/dev --create --remove --boot || stat_die tmpfiles-setup
|
||||
add_daemon tmpfiles-setup
|
||||
stat_done tmpfiles-setup
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@@ -1,19 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Waiting for udev uevents to be processed"
|
||||
udevadm settle || stat_die udev-settle
|
||||
calc_columns
|
||||
add_daemon udev-settle
|
||||
stat_done udev-settle
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
@@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
stat_busy "Triggering udev uevents"
|
||||
udevadm trigger --action=add --type=subsystems
|
||||
ret=$?
|
||||
udevadm trigger --action=add --type=devices
|
||||
(( ret || $? )) && stat_die udev-trigger
|
||||
add_daemon udev-trigger
|
||||
stat_done udev-trigger
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
29
sv.d/udev.in
29
sv.d/udev.in
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# sourcing our current rc.conf requires this to be a bash script
|
||||
. @RCLIBDIR@/functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
# check if runit already runs udevd
|
||||
if ! pgrep -f "runsv udevd" >/dev/null 2>&1; then
|
||||
stat_busy "Starting udev daemon"
|
||||
udevd --daemon || stat_die udev
|
||||
# Note: This is only needed for initialization, udev will
|
||||
# be controlled by runit on stage 2.
|
||||
add_daemon udev
|
||||
stat_done udev
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
stat_busy "Stopping udev"
|
||||
udevadm control --exit || stat_die udev
|
||||
rm_daemon udev
|
||||
stat_done udev
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 {start|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user