forked from artix/alpm-hooks
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a54971dada | |||
| 6e5f39e281 | |||
| c4d712bcc4 | |||
| 199eee77c1 | |||
| faca7dbca1 | |||
| 1f78e5fa1c | |||
| e5e819e337 | |||
| 1729205a54 | |||
| bd83fd645d | |||
| c9518dae35 | |||
| 51cf1104bd | |||
| 89b170310d | |||
| 4937e1ee11 | |||
| b6e6922998 | |||
| 48b9a2a9ec | |||
| e14878b49c | |||
| 31f3dda786 | |||
| 09ef3fc619 | |||
| 9442565f14 | |||
| c17eb2ad37 | |||
| 70445d2177 | |||
| 5d3cd01ffe | |||
| fccd8fcdd9 | |||
| 0126b86bf7 | |||
| 1487bf4089 | |||
| cf66dd76c5 |
30
Makefile
30
Makefile
@@ -2,6 +2,7 @@ PREFIX ?= /usr
|
|||||||
ALPMDIR = $(PREFIX)/share/libalpm
|
ALPMDIR = $(PREFIX)/share/libalpm
|
||||||
SCRIPTSDIR = $(ALPMDIR)/scripts
|
SCRIPTSDIR = $(ALPMDIR)/scripts
|
||||||
HOOKSDIR = $(ALPMDIR)/hooks
|
HOOKSDIR = $(ALPMDIR)/hooks
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
|
||||||
OPENRCSCRIPTS = $(wildcard openrc/scripts/*)
|
OPENRCSCRIPTS = $(wildcard openrc/scripts/*)
|
||||||
OPENRCHOOKS = $(wildcard openrc/hooks/*)
|
OPENRCHOOKS = $(wildcard openrc/hooks/*)
|
||||||
@@ -20,8 +21,13 @@ S6CRONIEHOOKS = $(wildcard s6/cronie-hooks/*)
|
|||||||
S6DBUSHOOKS = $(wildcard s6/dbus-hooks/*)
|
S6DBUSHOOKS = $(wildcard s6/dbus-hooks/*)
|
||||||
S6ATDHOOKS = $(wildcard s6/atd-hooks/*)
|
S6ATDHOOKS = $(wildcard s6/atd-hooks/*)
|
||||||
|
|
||||||
DINITSCRIPTS = $(wildcard dinit/scripts/*)
|
DINITSYSTEMSCRIPTS = $(wildcard dinit/scripts/system/*)
|
||||||
DINITHOOKS = $(wildcard dinit/hooks/*)
|
DINITUSERSCRIPTS = $(wildcard dinit/scripts/user/*)
|
||||||
|
DINITSYSTEMHOOKS = $(wildcard dinit/hooks/system/*)
|
||||||
|
DINITUSERHOOKS = $(wildcard dinit/hooks/user/*)
|
||||||
|
|
||||||
|
DINITUSERSPAWNSCRIPTS = $(wildcard dinit/scripts/user-spawn/*)
|
||||||
|
DINITUSERSPAWNHOOKS = $(wildcard dinit/hooks/user-spawn/*)
|
||||||
|
|
||||||
DINITCRONIEHOOKS = $(wildcard dinit/cronie-hooks/*)
|
DINITCRONIEHOOKS = $(wildcard dinit/cronie-hooks/*)
|
||||||
DINITDBUSHOOKS = $(wildcard dinit/dbus-hooks/*)
|
DINITDBUSHOOKS = $(wildcard dinit/dbus-hooks/*)
|
||||||
@@ -39,8 +45,6 @@ SYSUSERSHOOKS = $(wildcard esysusers/hooks/*)
|
|||||||
|
|
||||||
WRAPPER = $(wildcard wrapper/*)
|
WRAPPER = $(wildcard wrapper/*)
|
||||||
|
|
||||||
WRAPPERDIR = $(PREFIX)/share/artix
|
|
||||||
|
|
||||||
DMODE = -dm0755
|
DMODE = -dm0755
|
||||||
MODE = -m0644
|
MODE = -m0644
|
||||||
EMODE = -m0755
|
EMODE = -m0755
|
||||||
@@ -79,8 +83,16 @@ install_s6: install_common
|
|||||||
install $(MODE) $(S6HOOKS) $(DESTDIR)$(HOOKSDIR)
|
install $(MODE) $(S6HOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
|
|
||||||
install_dinit: install_common
|
install_dinit: install_common
|
||||||
install $(EMODE) $(DINITSCRIPTS) $(DESTDIR)$(SCRIPTSDIR)
|
install $(EMODE) $(DINITSYSTEMSCRIPTS) $(DESTDIR)$(SCRIPTSDIR)
|
||||||
install $(MODE) $(DINITHOOKS) $(DESTDIR)$(HOOKSDIR)
|
install $(MODE) $(DINITSYSTEMHOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
|
|
||||||
|
install_dinit_user: install_common
|
||||||
|
install $(EMODE) $(DINITUSERSCRIPTS) $(DESTDIR)$(SCRIPTSDIR)
|
||||||
|
install $(MODE) $(DINITUSERHOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
|
|
||||||
|
install_dinit_user_spawn: install_common
|
||||||
|
install $(EMODE) $(DINITUSERSPAWNSCRIPTS) $(DESTDIR)$(SCRIPTSDIR)
|
||||||
|
install $(MODE) $(DINITUSERSPAWNHOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
|
|
||||||
install_openrc_cronie: install_hook_common
|
install_openrc_cronie: install_hook_common
|
||||||
install $(MODE) $(OPENRCCRONIEHOOKS) $(DESTDIR)$(HOOKSDIR)
|
install $(MODE) $(OPENRCCRONIEHOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
@@ -110,7 +122,7 @@ install_dinit_dbus: install_hook_common
|
|||||||
install $(MODE) $(DINITDBUSHOOKS) $(DESTDIR)$(HOOKSDIR)
|
install $(MODE) $(DINITDBUSHOOKS) $(DESTDIR)$(HOOKSDIR)
|
||||||
|
|
||||||
install_wrapper:
|
install_wrapper:
|
||||||
install $(DMODE) $(DESTDIR)$(WRAPPERDIR)
|
install $(DMODE) $(DESTDIR)$(BINDIR)
|
||||||
install $(EMODE) $(WRAPPER) $(DESTDIR)$(WRAPPERDIR)
|
install $(EMODE) $(WRAPPER) $(DESTDIR)$(BINDIR)
|
||||||
|
|
||||||
.PHONY: install install_base install_s6 install_openrc install_runit install_dinit install_wrapper
|
.PHONY: install install_base install_s6 install_openrc install_runit install_dinit install_wrapper install_dinit_user install_dinit_user_spawn
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ Target = usr/lib/binfmt.d/*.conf
|
|||||||
[Action]
|
[Action]
|
||||||
Description = Registering binary formats...
|
Description = Registering binary formats...
|
||||||
When = PostTransaction
|
When = PostTransaction
|
||||||
Exec = /usr/share/libalpm/scripts/dinit-hook binfmt
|
Exec = /usr/lib/artix/binfmt.sh
|
||||||
NeedsTargets
|
NeedsTargets
|
||||||
9
dinit/hooks/user-spawn/dinit-user-spawn-install.hook
Normal file
9
dinit/hooks/user-spawn/dinit-user-spawn-install.hook
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Trigger]
|
||||||
|
Type = Path
|
||||||
|
Operation = Install
|
||||||
|
Target = usr/lib/dinit.d/dinit-user-spawn
|
||||||
|
[Action]
|
||||||
|
Description = Enabling dinit user spawn service ...
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /usr/share/libalpm/scripts/dinit-user-spawn-hook enable
|
||||||
|
NeedsTargets
|
||||||
9
dinit/hooks/user-spawn/dinit-user-spawn-remove.hook
Normal file
9
dinit/hooks/user-spawn/dinit-user-spawn-remove.hook
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Trigger]
|
||||||
|
Type = Path
|
||||||
|
Operation = Remove
|
||||||
|
Target = usr/lib/dinit.d/dinit-user-spawn
|
||||||
|
[Action]
|
||||||
|
Description = Disabling dinit user spawn service ...
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /usr/share/libalpm/scripts/dinit-user-spawn-hook disable
|
||||||
|
NeedsTargets
|
||||||
11
dinit/hooks/user/dinit-user-install.hook
Normal file
11
dinit/hooks/user/dinit-user-install.hook
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[Trigger]
|
||||||
|
Type = Path
|
||||||
|
Operation = Install
|
||||||
|
Operation = Upgrade
|
||||||
|
Target = etc/dinit.d/user/*
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
Description = Displaying dinit user service help ...
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /usr/share/libalpm/scripts/dinit-user-hook addU
|
||||||
|
NeedsTargets
|
||||||
10
dinit/hooks/user/dinit-user-remove.hook
Normal file
10
dinit/hooks/user/dinit-user-remove.hook
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Trigger]
|
||||||
|
Type = Path
|
||||||
|
Operation = Remove
|
||||||
|
Target = etc/dinit.d/user/*
|
||||||
|
|
||||||
|
[Action]
|
||||||
|
Description = Displaying dinit user service help ...
|
||||||
|
When = PostTransaction
|
||||||
|
Exec = /usr/share/libalpm/scripts/dinit-user-hook delU
|
||||||
|
NeedsTargets
|
||||||
@@ -14,13 +14,25 @@ svc_help(){
|
|||||||
|
|
||||||
svc_add_help(){
|
svc_add_help(){
|
||||||
echo " ==> Add a service:"
|
echo " ==> Add a service:"
|
||||||
echo " dinitctl enable <service>"
|
echo " # dinitctl enable <service>"
|
||||||
svc_help
|
svc_help
|
||||||
}
|
}
|
||||||
|
|
||||||
svc_del_help(){
|
svc_del_help(){
|
||||||
echo " ==> Remove a service:"
|
echo " ==> Remove a service:"
|
||||||
echo " dinitctl disable <service>"
|
echo " # dinitctl disable <service>"
|
||||||
|
svc_help
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_user_add_help(){
|
||||||
|
echo " ==> Add a user service:"
|
||||||
|
echo " $ dinitctl enable <service>"
|
||||||
|
svc_help
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_user_del_help(){
|
||||||
|
echo " ==> Remove a user service:"
|
||||||
|
echo " $ dinitctl disable <service>"
|
||||||
svc_help
|
svc_help
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,13 +58,14 @@ op="$1"; shift
|
|||||||
|
|
||||||
case $op in
|
case $op in
|
||||||
sysctl) dinit_live; each_conf /usr/bin/sysctl -q -p ;;
|
sysctl) dinit_live; each_conf /usr/bin/sysctl -q -p ;;
|
||||||
binfmt) dinit_live; /usr/bin/dinitctl restart binfmt ;;
|
|
||||||
dbus_reload) dinit_live; reload_dbus ;;
|
dbus_reload) dinit_live; reload_dbus ;;
|
||||||
# For use by other packages
|
# For use by other packages
|
||||||
reload) dinit_live; /usr/bin/dinitctl reload "$@"; /usr/bin/dinitctl restart "$@" ;;
|
reload) dinit_live; /usr/bin/dinitctl reload "$@"; /usr/bin/dinitctl restart "$@" ;;
|
||||||
restart) dinit_live; restart_service "$1" ;;
|
restart) dinit_live; restart_service "$1" ;;
|
||||||
add) svc_add_help ;;
|
add) svc_add_help ;;
|
||||||
del) svc_del_help ;;
|
del) svc_del_help ;;
|
||||||
|
addU) svc_user_add_help ;;
|
||||||
|
delU) svc_user_del_help ;;
|
||||||
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
20
dinit/scripts/user-spawn/dinit-user-spawn-hook
Normal file
20
dinit/scripts/user-spawn/dinit-user-spawn-hook
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
handle_user_spawn() {
|
||||||
|
if [ ! -S /run/dinitctl ]; then
|
||||||
|
echo >&2 " Current root is not booted."
|
||||||
|
dinitctl "$1" -o "$2"
|
||||||
|
else
|
||||||
|
dinitctl "$1" "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
op="$1"; shift
|
||||||
|
|
||||||
|
case $op in
|
||||||
|
enable) handle_user_spawn "$op" 'dinit-user-spawn' ;;
|
||||||
|
disable) handle_user_spawn "$op" 'dinit-user-spawn' ;;
|
||||||
|
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
28
dinit/scripts/user/dinit-user-hook
Normal file
28
dinit/scripts/user/dinit-user-hook
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
svc_help(){
|
||||||
|
echo " ==> Start/stop/restart a service:"
|
||||||
|
echo " dinitctl <start/stop/restart> <service>"
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_user_add_help(){
|
||||||
|
echo " ==> Add a user service:"
|
||||||
|
echo " $ dinitctl enable <service>"
|
||||||
|
svc_help
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_user_del_help(){
|
||||||
|
echo " ==> Remove a user service:"
|
||||||
|
echo " $ dinitctl disable <service>"
|
||||||
|
svc_help
|
||||||
|
}
|
||||||
|
|
||||||
|
op="$1"; shift
|
||||||
|
|
||||||
|
case $op in
|
||||||
|
addU) svc_user_add_help ;;
|
||||||
|
delU) svc_user_del_help ;;
|
||||||
|
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -4,6 +4,6 @@ Operation = Upgrade
|
|||||||
Target = openrc
|
Target = openrc
|
||||||
|
|
||||||
[Action]
|
[Action]
|
||||||
Description = Reexecuting init ...
|
Description = Configuring user service & reexecuting init ...
|
||||||
When = PostTransaction
|
When = PostTransaction
|
||||||
Exec = /usr/share/libalpm/scripts/openrc-hook reexec
|
Exec = /usr/share/libalpm/scripts/openrc-hook reexec
|
||||||
|
|||||||
11
openrc/hooks/openrc-user-install.hook
Normal file
11
openrc/hooks/openrc-user-install.hook
Normal 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
|
||||||
10
openrc/hooks/openrc-user-remove.hook
Normal file
10
openrc/hooks/openrc-user-remove.hook
Normal 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
|
||||||
@@ -7,39 +7,73 @@ openrc_live() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
svc_help(){
|
|
||||||
echo " ==> Start/stop/restart a service:"
|
|
||||||
echo " rc-service <service> <start/stop/restart>"
|
|
||||||
}
|
|
||||||
|
|
||||||
svc_add_help(){
|
|
||||||
echo " ==> Add a service to runlevel:"
|
|
||||||
echo " rc-update add <service> <runlevel>"
|
|
||||||
svc_help
|
|
||||||
}
|
|
||||||
|
|
||||||
svc_del_help(){
|
|
||||||
echo " ==> Remove a service from runlevel:"
|
|
||||||
echo " rc-update del <service> <runlevel>"
|
|
||||||
svc_help
|
|
||||||
}
|
|
||||||
|
|
||||||
each_conf() {
|
each_conf() {
|
||||||
while read -r f; do
|
while read -r f; do
|
||||||
"$@" "/$f"
|
"$@" "/$f"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
svc_help(){
|
||||||
|
arg="${1:-}"
|
||||||
|
str="${arg#--*}"
|
||||||
|
if [ -n "$str" ]; then
|
||||||
|
echo " ==> Start/stop/restart a $str service:"
|
||||||
|
else
|
||||||
|
echo " ==> Start/stop/restart a service:"
|
||||||
|
fi
|
||||||
|
echo " rc-service <service> <start/stop/restart>" "$arg"
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_add_help(){
|
||||||
|
arg="${1:-}"
|
||||||
|
str="${arg#--*}"
|
||||||
|
if [ -n "$str" ]; then
|
||||||
|
echo " ==> Add a $str service to runlevel:"
|
||||||
|
else
|
||||||
|
echo " ==> Add a service to runlevel:"
|
||||||
|
fi
|
||||||
|
echo " rc-update add <service> <runlevel>" "$arg"
|
||||||
|
svc_help "$arg"
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_del_help(){
|
||||||
|
arg="${1:-}"
|
||||||
|
str="${arg#--*}"
|
||||||
|
if [ -n "$str" ]; then
|
||||||
|
echo " ==> Remove a $str service from runlevel:"
|
||||||
|
else
|
||||||
|
echo " ==> Remove a service from runlevel:"
|
||||||
|
fi
|
||||||
|
echo " rc-update del <service> <runlevel>" "$arg"
|
||||||
|
svc_help "$arg"
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
op="$1"; shift
|
op="$1"; shift
|
||||||
|
|
||||||
case $op in
|
case $op in
|
||||||
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
|
sysctl) openrc_live; each_conf /usr/bin/sysctl -q -p ;;
|
||||||
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
|
binfmt) openrc_live; each_conf /usr/lib/openrc/sh/binfmt.sh ;;
|
||||||
reexec) openrc_live; /usr/bin/openrc-shutdown -R ;;
|
reexec) svc_user_ln; openrc_live; /usr/bin/openrc-shutdown -R ;;
|
||||||
# For use by other packages
|
# For use by other packages
|
||||||
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
|
reload) openrc_live; /usr/bin/rc-service "$@" reload ;;
|
||||||
add) svc_add_help ;;
|
add) svc_add_help ;;
|
||||||
del) svc_del_help ;;
|
del) svc_del_help ;;
|
||||||
|
uadd) svc_add_help "--user" ;;
|
||||||
|
udel) svc_del_help "--user" ;;
|
||||||
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
*) echo >&2 " Invalid operation '$op'"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -34,7 +34,6 @@ op="$1"; shift
|
|||||||
|
|
||||||
case $op in
|
case $op in
|
||||||
sysctl) runit_live; each_conf /usr/bin/sysctl -q -p ;;
|
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
|
# For use by other packages
|
||||||
reload) runit_live; /usr/bin/sv "$@" reload ;;
|
reload) runit_live; /usr/bin/sv "$@" reload ;;
|
||||||
add) svc_add_help ;;
|
add) svc_add_help ;;
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -51,7 +51,6 @@ op="$1"; shift
|
|||||||
|
|
||||||
case $op in
|
case $op in
|
||||||
sysctl) s6_live; each_conf /usr/bin/sysctl -q -p ;;
|
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 ;;
|
dbus_reload) s6_live; reload_dbus ;;
|
||||||
# For use by other packages
|
# For use by other packages
|
||||||
add) svc_add_help ;;
|
add) svc_add_help ;;
|
||||||
|
|||||||
86
wrapper/artix-service
Normal file
86
wrapper/artix-service
Normal 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
|
||||||
@@ -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
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user