18 Commits
1.6.1 ... 2.1

Author SHA1 Message Date
c9518dae35 openrc-hook: fix user help 2025-03-10 16:14:31 +01:00
51cf1104bd openrc: small refactoring 2025-03-08 23:03:00 +01:00
89b170310d remove live check from openrc-user-hook 2025-03-08 16:51:06 +01:00
4937e1ee11 Merge pull request 'add openrc-user-hook' (#27) from openrc-user-sv into master
Reviewed-on: #27
2025-03-08 16:30:54 +01:00
b6e6922998 add openrc-user-hook 2025-03-08 16:28:30 +01:00
48b9a2a9ec openrc (#26)
Reviewed-on: #26
2025-03-06 22:44:30 +00:00
e14878b49c artix-service: use dinitctl for disable and enable ops 2024-06-03 07:42:36 +07:00
31f3dda786 openrc: readd binfmt hook 2024-05-05 19:36:55 +02:00
09ef3fc619 Merge pull request 'unify binfmt into a single implementation' (#25) from binfmt into master
Reviewed-on: #25
2024-05-05 17:46:14 +02:00
9442565f14 unify binfmt into a single implementation
Since binfmt now lives in artix-groups, all the inits can use the same,
simplified hook.
2024-05-05 09:50:02 -05:00
c17eb2ad37 wrapper: fix quote to run 2024-01-07 22:06:00 +01:00
70445d2177 wrapper: remove script name from help 2024-01-05 00:35:32 +01:00
5d3cd01ffe wrapper: drop printf 2024-01-04 23:31:00 +01:00
fccd8fcdd9 bash (#24)
Reviewed-on: #24
2024-01-04 20:08:21 +01:00
0126b86bf7 wrapper: fix runit enable/disable 2024-01-04 03:50:49 +01:00
1487bf4089 makefile: install wrapper in /bin 2024-01-02 02:52:50 +01:00
cf66dd76c5 wrapper: add artix-service 2024-01-02 02:44:31 +01:00
d68ed909c4 actually fix runit test 2023-11-10 18:50:35 +07:00
13 changed files with 150 additions and 91 deletions

View File

@@ -2,6 +2,7 @@ PREFIX ?= /usr
ALPMDIR = $(PREFIX)/share/libalpm
SCRIPTSDIR = $(ALPMDIR)/scripts
HOOKSDIR = $(ALPMDIR)/hooks
BINDIR = $(PREFIX)/bin
OPENRCSCRIPTS = $(wildcard openrc/scripts/*)
OPENRCHOOKS = $(wildcard openrc/hooks/*)
@@ -39,8 +40,6 @@ SYSUSERSHOOKS = $(wildcard esysusers/hooks/*)
WRAPPER = $(wildcard wrapper/*)
WRAPPERDIR = $(PREFIX)/share/artix
DMODE = -dm0755
MODE = -m0644
EMODE = -m0755
@@ -110,7 +109,7 @@ install_dinit_dbus: install_hook_common
install $(MODE) $(DINITDBUSHOOKS) $(DESTDIR)$(HOOKSDIR)
install_wrapper:
install $(DMODE) $(DESTDIR)$(WRAPPERDIR)
install $(EMODE) $(WRAPPER) $(DESTDIR)$(WRAPPERDIR)
install $(DMODE) $(DESTDIR)$(BINDIR)
install $(EMODE) $(WRAPPER) $(DESTDIR)$(BINDIR)
.PHONY: install install_base install_s6 install_openrc install_runit install_dinit install_wrapper

View File

@@ -7,5 +7,5 @@ Target = usr/lib/binfmt.d/*.conf
[Action]
Description = Registering binary formats...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/dinit-hook binfmt
Exec = /usr/lib/artix/binfmt.sh
NeedsTargets

View File

@@ -46,7 +46,6 @@ op="$1"; shift
case $op in
sysctl) dinit_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) dinit_live; /usr/bin/dinitctl restart binfmt ;;
dbus_reload) dinit_live; reload_dbus ;;
# For use by other packages
reload) dinit_live; /usr/bin/dinitctl reload "$@"; /usr/bin/dinitctl restart "$@" ;;

View File

@@ -4,6 +4,6 @@ Operation = Upgrade
Target = openrc
[Action]
Description = Reexecuting init ...
Description = Configuring user service & reexecuting init ...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/openrc-hook reexec

View File

@@ -0,0 +1,11 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = etc/user/init.d/*
[Action]
Description = Displaying openrc user service help ...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/openrc-hook uadd
NeedsTargets

View File

@@ -0,0 +1,10 @@
[Trigger]
Type = Path
Operation = Remove
Target = etc/user/init.d/*
[Action]
Description = Displaying openrc user service help ...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/openrc-hook udel
NeedsTargets

View File

@@ -24,6 +24,37 @@ svc_del_help(){
svc_help
}
svc_user_help(){
echo " ==> Start/stop/restart a service:"
echo " rc-service -U <service> <start/stop/restart>"
}
svc_user_add_help(){
echo " ==> Add a user service to runlevel:"
echo " rc-update -U add <service> <runlevel>"
svc_user_help
}
svc_user_del_help(){
echo " ==> Remove a user service from runlevel:"
echo " rc-update -U del <service> <runlevel>"
svc_user_help
}
svc_user_ln() {
umin=$(grep "^UID_MIN" /etc/login.defs)
umax=$(grep "^UID_MAX" /etc/login.defs)
users=$(awk -F':' -v "min=${umin##UID_MIN}" -v "max=${umax##UID_MAX}" \
'{ if ( $3 >= min && $3 <= max ) print $0 }' /etc/passwd \
| cut -d: -f1)
for u in $users; do
if [ ! -e /etc/init.d/user.$u ]; then
ln -sv /etc/init.d/user /etc/init.d/user.$u
fi
done
}
each_conf() {
while read -r f; do
"$@" "/$f"
@@ -33,13 +64,15 @@ each_conf() {
op="$1"; shift
case $op in
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
reexec) openrc_live; /usr/bin/openrc-shutdown -R ;;
# For use by other packages
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
reexec) svc_user_ln; openrc_live; /usr/bin/openrc-shutdown -R ;;
# For use by other packages
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
add) svc_add_help ;;
del) svc_del_help ;;
uadd) svc_user_add_help ;;
udel) svc_user_del_help ;;
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
esac

View File

@@ -1,11 +0,0 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/binfmt.d/*.conf
[Action]
Description = Registering binary formats...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/runit-hook binfmt
NeedsTargets

View File

@@ -34,7 +34,6 @@ op="$1"; shift
case $op in
sysctl) runit_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) runit_live; each_conf /usr/lib/rc/sv.d/binfmt once ;;
# For use by other packages
reload) runit_live; /usr/bin/sv "$@" reload ;;
add) svc_add_help ;;

View File

@@ -1,11 +0,0 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/binfmt.d/*.conf
[Action]
Description = Registering binary formats...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/s6-rc-hook binfmt
NeedsTargets

View File

@@ -51,7 +51,6 @@ op="$1"; shift
case $op in
sysctl) s6_live; each_conf /usr/bin/sysctl -q -p ;;
binfmt) s6_live; sh /etc/s6/sv/binfmt/shell_up ;;
dbus_reload) s6_live; reload_dbus ;;
# For use by other packages
add) svc_add_help ;;

86
wrapper/artix-service Normal file
View File

@@ -0,0 +1,86 @@
#!/bin/bash
cmds_openrc() {
COMMANDS[enable]="rc-update add ${SV} default"
COMMANDS[disable]="rc-update del ${SV} default"
COMMANDS[start]="rc-service ${SV} start"
COMMANDS[stop]="rc-service ${SV} stop"
}
cmds_s6() {
COMMANDS[start]="s6-rc -u change ${SV}"
COMMANDS[stop]="s6-rc -d change ${SV}"
COMMANDS[enable]="s6-service add default ${SV}"
COMMANDS[disable]="s6-service del default ${SV}"
}
cmds_dinit() {
COMMANDS[start]="dinitctl start ${SV}"
COMMANDS[stop]="dinitctl stop ${SV}"
COMMANDS[enable]="dinitctl -o enable ${SV}"
COMMANDS[disable]="dinitctl -o disable ${SV}"
}
cmds_runit() {
COMMANDS[start]="runsv /etc/runit/sv/${SV}"
COMMANDS[stop]="sv stop /etc/runit/sv/${SV}"
COMMANDS[enable]="ln -s /etc/runit/sv/${SV} /run/runit/service/"
COMMANDS[disable]="rm /run/runit/service/${SV}"
}
is_live() {
if [[ ! -d /run/openrc && "${INIT}" == "openrc" ]]; then
echo >&2 " Skipped: ${INIT} is not running."
exit 0
elif [[ ! -d /run/s6-rc && "${INIT}" == "s6" ]]; then
echo >&2 " Skipped: ${INIT} is not running."
exit 0
elif [[ ! -S /run/dinitctl && "${INIT}" == "dinit" ]]; then
echo >&2 " Skipped: ${INIT} is not running."
exit 0
elif [[ ! -d /run/runit && "${INIT}" == "runit" ]]; then
echo >&2 " Skipped: ${INIT} is not running."
exit 0
fi
}
detect() {
for i in "${SUPPORTED[@]}"; do
if [[ -f /usr/bin/"$i"-init ]]; then
INIT="$i"
cmds_"${INIT}"
fi
done
}
usage() {
cat <<EOF
usage: ${0##*/} [action] [service]
actions:
enable
disable
start
stop
EOF
}
readonly SUPPORTED=(openrc s6 dinit runit)
declare -A COMMANDS
INIT=
ACTION="$1"
SV="$2"
if [[ -z "${SV}" ]]; then
usage; exit 1
fi
detect
case "${ACTION}" in
start|stop) is_live; ${COMMANDS["${ACTION}"]} ;;
enable|disable) ${COMMANDS["${ACTION}"]} ;;
help) usage; exit 0 ;;
*) usage; exit 1 ;;
esac

View File

@@ -1,55 +0,0 @@
#!/bin/sh
sv_start() {
case "$init" in
openrc) exec /usr/bin/rc-service "$1" start ;;
runit) exec /usr/bin/sv start /run/runit/service/"$1" ;;
s6) exec /usr/bin/s6-rc -u change "$1" ;;
dinit) exec /usr/bin/dinitctl start "$1" ;;
esac
}
sv_stop() {
case "$init" in
openrc) exec /usr/bin/rc-service "$1" stop ;;
runit) exec /usr/bin/sv stop /run/runit/service/"$1" ;;
s6) exec /usr/bin/s6-rc -d change "$1" ;;
dinit) exec /usr/bin/dinitctl stop "$1" ;;
esac
}
sv_enable() {
case "$init" in
openrc) exec /usr/bin/rc-update add "$1" default ;;
runit) exec unlink /run/runit/service/"$1"/down ;;
s6) exec /usr/bin/s6-service add default "$1" ;;
dinit) exec /usr/bin/dinitctl enable "$1" ;;
esac
}
sv_disable() {
case "$init" in
openrc) exec /usr/bin/rc-update del "$1" default ;;
runit) exec touch /run/runit/service/"$1"/down ;;
s6) exec /usr/bin/s6-service delete default "$1" ;;
dinit) exec /usr/bin/dinitctl disable "$1" ;;
esac
}
if [ -d /run/openrc ]; then
init=openrc
elif [-d /run/runit ]; then
init=runit
elif [ -d /run/s6-rc ]; then
init=s6
elif [ -S /run/dinitctl ]; then
init=dinit
fi
case "$1" in
start) shift; sv_start "$@" ;;
stop) shift; sv_stop "$@" ;;
enable) shift; sv_enable "$@" ;;
disable) shift; sv_disable "$@" ;;
esac