commit c923fb97f431894ea85b3381520a2258afe4eb62
parent a775d2ef08f295a10cac91efae73b5d3e2d7cd59
Author: Jan Pobříslo <ccx@te2000.cz>
Date: Tue, 1 Nov 2022 23:59:01 +0100
Optional service definition function helpers. Can omit unused tables.
Diffstat:
3 files changed, 87 insertions(+), 24 deletions(-)
diff --git a/config.aat b/config.aat
@@ -13,6 +13,18 @@ tty_setfont=ter-v14n
dev_manager=udev
+enable_loopback=1
+enable_dhcpcd=1
+enable_unbound=1
+enable_loadkeys=1
+enable_sshd=1
+enable_alsactl_rdaemon=1
+enable_brightness=1
+enable_tlp=1
+enable_containers=1
+enable_syncthing=1
+enable_wpa_supplicant=1
+
X_servers=[
svc vtN
X5 5
@@ -52,16 +64,16 @@ wmi_bmof
xhci_pci
]
-static_ip=[
-iface ip cidr
-|#|#lo 127.0.0.1 8
-|#eth0 10.70.145.187 25
-]
+#static_ip=[
+#iface ip prefix
+#|#lo 127.0.0.1 8
+#|#eth0 10.70.145.187 25
+#]
-static_route=[
-iface spec
-|#eth0 default via 10.70.145.129
-]
+#static_route=[
+#iface spec
+#|#eth0 default via 10.70.145.129
+#]
user_svscan=[
id name
diff --git a/rc-builder.include.awk b/rc-builder.include.awk
@@ -2,15 +2,21 @@ function error(message) {
print "error: " message >"/dev/stderr"
exit 1
}
-function start_service(svc_name, type) {
+function start_service(svc_name, type, variable_enable) {
if(length(current_service_name)) {
error("start_service(\""svc_name"\", \""type"\", \""deps"\"): service \"" current_service_name "\" not terminated")
}
if(type !~ /^(oneshot|longrun)$/) {
error("start_service(\""svc_name"\", \""type"\", \""deps"\"): invalid service type")
}
+ if(length(variable_enable) != 0) {
+ if(!(find(variable_enable)?found:0)) {
+ return 0
+ }
+ }
current_service_name = svc_name
current_service_type = type
+ return 1
}
function start_oneshot(svc_name, deps) {
start_service(svc_name, "oneshot")
@@ -24,11 +30,48 @@ function start_longrun_with_logger(svc_name, deps) {
start_service(svc_name, "longrun")
longrun_with_logger(svc_name, deps)
}
-function in_bundle(name) {
+function enabled_service(svc_name, deps, var_name) {
+ var_name = "enable_" current_service_name
+ gsub(/[-. ]/, "_", var_name)
+ return start_service(svc_name, type, var_name)
+}
+function enabled_oneshot(svc_name, deps) {
+ if(enabled_service(svc_name, "oneshot", var_name)) {
+ oneshot(svc_name, deps)
+ return 1
+ }
+ return 0
+}
+function enabled_longrun(svc_name, deps) {
+ if(enabled_service(svc_name, "longrun", var_name)) {
+ longrun(svc_name, deps)
+ return 1
+ }
+ return 0
+}
+function enabled_longrun_with_logger(svc_name, deps) {
+ if(enabled_service(svc_name, "longrun", var_name)) {
+ longrun_with_logger(svc_name, deps)
+ return 1
+ }
+ return 0
+}
+function in_bundle(name, variable_enable) {
if(!length(current_service_name)) {
error("in_bundle(\""name"\"): not in service context")
}
+ if(length(variable_enable) != 0) {
+ if(!(find(variable_enable)?found:0)) {
+ return 0
+ }
+ }
add_to_bundle(name, current_service_name)
+ return 1
+}
+function enabled_bundle(name, var_name) {
+ var_name = "enable_" current_service_name
+ gsub(/[-. ]/, "_", var_name)
+ in_bundle(name, var_name)
}
function flush_current_file() {
if(length(current_file_mode)) {
diff --git a/s6-rc.aat b/s6-rc.aat
@@ -16,26 +16,29 @@
|### Networking ###
|start_oneshot("loopback")
-|in_bundle("net-all")
+|enabled_bundle("net-all")
|up()
if { ip link set lo up }
if -nt { ip addr add 127.0.0.1/8 dev lo brd + }
pipeline { ip addr show dev lo } grep -q "inet 127\\.0\\.0\\.1"
|end()
+|if(find("static_ip.rows")) {
@for i in static_ip
|start_oneshot(with_counter("net-" get("i.iface") "-ip"))
|in_bundle("net-" get("i.iface"))
|add_to_bundle("net-all", "net-" get("i.iface"))
|up()
if { ip link set {<i.iface>} up }
- if -nt { ip addr add {<i.ip>}/{<i.cidr>} dev {<i.iface>} }
- pipeline { ip addr show dev {<i.iface>} } grep -F -q -e "inet {<i.ip>}/{<i.cidr>} "
+ if -nt { ip addr add {<i.ip>}/{<i.prefix>} dev {<i.iface>} }
+ pipeline { ip addr show dev {<i.iface>} } grep -F -q -e "inet {<i.ip>}/{<i.prefix>} "
|down()
ip addr del {<i.ip>} dev {<i.iface>}
|end()
@endfor
+|}
+|if(find("static_route.rows")) {
@for i in static_route
|start_oneshot(with_counter("net-" get("i.iface") "-route"), list_services_with_counter("net-" get("i.iface") "-ip"))
|in_bundle("net-" get("i.iface"))
@@ -47,14 +50,15 @@
ip route del dev {<i.iface>} {<i.spec>}
|end()
@endfor
+|}
|start_longrun_with_logger("dhcpcd", "modules ok-mount ok-sysinit")
-|in_bundle("net-all")
+|enabled_bundle("net-all")
|run_arg("dhcpcd --nobackground")
|end()
|start_longrun_with_logger("unbound", "loopback ok-mount ok-sysinit")
-|in_bundle("net-all")
+|enabled_bundle("net-all")
|run_arg("unbound -ddp")
|end()
@@ -65,7 +69,7 @@
|end()
|start_oneshot("loadkeys", "kbd_mode")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|up()
loadkeys --unicode /root/keymap
|end()
@@ -188,7 +192,7 @@
/.scripts d m755
|start_longrun_with_logger("sshd", "ssh_host_ed25519_key ssh_host_rsa_key ok-sysinit")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|run_arg("/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config")
|end()
@@ -227,12 +231,12 @@
|end()
|start_longrun_with_logger("alsactl-rdaemon","alsa-devices")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|run_arg("alsactl rdaemon")
|end()
|start_oneshot("brightness", "ok-sysinit")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|up()
foreground { redirfd -w 1 /sys/class/backlight/intel_backlight/brightness echo 800 }
if { chgrp users /sys/class/backlight/intel_backlight/brightness }
@@ -240,7 +244,7 @@
|end()
|start_oneshot("tlp", "ok-sysinit")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|up()
tlp init start
|down()
@@ -248,7 +252,7 @@
|end()
|start_oneshot("containers", "ok-mount")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|up()
export TERM "linux"
if {
@@ -257,6 +261,7 @@
s6-svscanctl -a /run/service
|end()
+|if(find("user_svscan.rows")) {
@for u in user_svscan
|start_longrun("svscan-"(<u.name>)"-log", "ok-sysinit rootfs")
|consumer_for("svscan-"(<u.name>))
@@ -283,9 +288,10 @@
s6-svscan -d 3 /run/user/{<u.id>}/service
|end()
@endfor
+|}
|start_longrun_with_logger("syncthing", "ok-mount")
-|in_bundle("ok-all-but-tty")
+|enabled_bundle("ok-all-but-tty")
|run_el()
/usr/bin/env HOME=/var/lib/syncthing
s6-setuidgid syncthing
@@ -298,7 +304,7 @@
|end()
|start_longrun_with_logger("wpa_supplicant", "modules\nok-sysinit")
-|in_bundle("net-all")
+|enabled_bundle("net-all")
|run_el()
/sbin/wpa_supplicant
-iwlan0
@@ -306,6 +312,7 @@
|end()
+|if(find("X_servers.rows")) {
@for i in X_servers
/{<i.svc>} d m750
/{<i.svc>}/data d m750
@@ -382,6 +389,7 @@ CN #!/command/execlineb -P
vt${vtN} :${vtN}
m755
+|}
|print_bundles()
|}