feat: add Alpine Linux (OpenRC) support

This commit is contained in:
rowanchen-com
2026-03-17 01:40:32 +08:00
parent 91f04192ea
commit 0d160f112d
4 changed files with 161 additions and 46 deletions
+58
View File
@@ -1,4 +1,16 @@
# detect init system
is_systemd=$(type -P systemctl)
is_openrc=$(type -P rc-service)
install_service() {
if [[ $is_systemd ]]; then
install_service_systemd $1
elif [[ $is_openrc ]]; then
install_service_openrc $1
fi
}
install_service_systemd() {
case $1 in
$is_core)
is_doc_site=https://sing-box.sagernet.org/
@@ -56,3 +68,49 @@ WantedBy=multi-user.target"
systemctl enable $1
systemctl daemon-reload
}
install_service_openrc() {
case $1 in
$is_core)
cat >/etc/init.d/$is_core <<EOF
#!/sbin/openrc-run
name="$is_core_name"
description="$is_core_name Service"
command="$is_core_bin"
command_args="run -c $is_config_json -C $is_conf_dir"
command_background=true
pidfile="/run/\${RC_SVCNAME}.pid"
output_log="/var/log/$is_core/access.log"
error_log="/var/log/$is_core/error.log"
depend() {
need net
after firewall
}
EOF
chmod +x /etc/init.d/$is_core
;;
caddy)
cat >/etc/init.d/caddy <<EOF
#!/sbin/openrc-run
name="Caddy"
description="Caddy web server"
command="$is_caddy_bin"
command_args="run --environ --config $is_caddyfile --adapter caddyfile"
command_background=true
pidfile="/run/\${RC_SVCNAME}.pid"
depend() {
need net
after firewall
}
EOF
chmod +x /etc/init.d/caddy
;;
esac
# enable
rc-update add $1 default
}