mrrl-system-config

system configuration on top of MRRL
git clone https://ccx.te2000.cz/git/mrrl-system-config
Log | Files | Refs

s6-rc.aat (11330B)


      1 @include common.aat
      2 @include rc-common.aat
      3 @awk rc-builder.include.awk
      4 |END{
      5 /	d	m755
      6 
      7 
      8 |declare_bundle("ok-all", "ok-all-but-tty gettys")
      9 
     10 |declare_bundle("ok-sysinit", "mount-sysinit dev-coldplug")
     11 
     12 |declare_bundle("ok-mount", "ok-sysinit ok-localmount")
     13 
     14 |declare_bundle("ok-all-but-tty", "net-all ok-mount")
     15 
     16 |declare_bundle("net-all")
     17 
     18 |### Networking ###
     19 |start_oneshot("loopback")
     20 |# TODO: make loopback conditional
     21 |enabled_bundle("net-all")
     22 |up()
     23 	{{qexec("if")}} { {{qexec("ip")}} link set dev lo up }
     24 	{{qexec("if")}} -nt { {{qexec("ip")}} addr add 127.0.0.1/8 dev lo }
     25 	{{qexec("pipeline")}} { {{qexec("ip")}} addr show dev lo } {{qexec("grep")}} -q "inet 127\\.0\\.0\\.1"
     26 |end()
     27 
     28 |if(find("static_ip.rows")) {
     29 @for i in static_ip
     30 |start_oneshot(with_counter("net-" get("i.iface") "-ip"))
     31 |in_bundle("net-" get("i.iface"))
     32 |add_to_bundle("net-all", "net-" get("i.iface"))
     33 |up()
     34 	{{qexec("if")}} { {{qexec("ip")}} link set {<i.iface>} up }
     35 	{{qexec("if")}} -nt { {{qexec("ip")}} addr add {<i.ip>}/{<i.prefix>} dev {<i.iface>} }
     36 	{{qexec("pipeline")}} { {{qexec("ip")}} ip addr show dev {<i.iface>} } {{qexec("grep")}} -F -q -e "inet {<i.ip>}/{<i.prefix>} "
     37 |down()
     38 	{{qexec("ip")}} addr del {<i.ip>} dev {<i.iface>}
     39 |end()
     40 @endfor
     41 |}
     42 
     43 |if(find("static_route.rows")) {
     44 @for i in static_route
     45 |start_oneshot(with_counter("net-" get("i.iface") "-route"), list_services_with_counter("net-" get("i.iface") "-ip"))
     46 |in_bundle("net-" get("i.iface"))
     47 |up()
     48 	{{qexec("if")}} { {{qexec("ip")}} link set {<i.iface>} up }
     49 	{{qexec("if")}} -nt { {{qexec("ip")}} route add dev {<i.iface>} {<i.spec>} }
     50 	{{qexec("pipeline")}} { {{qexec("ip")}} route show dev {<i.iface>} {<i.spec>} } grep -q .
     51 |down()
     52 	{{qexec("ip")}} route del dev {<i.iface>} {<i.spec>}
     53 |end()
     54 @endfor
     55 |}
     56 
     57 |start_longrun_with_logger("dhcpcd", "sysctl modules ok-mount ok-sysinit")
     58 |enabled_bundle("net-all")
     59 |run_arg("dhcpcd --nobackground --nohook 20-resolv.conf")
     60 |end()
     61 
     62 |start_longrun_with_logger("unbound", "loopback ok-mount ok-sysinit")
     63 |enabled_bundle("net-all")
     64 |run_arg("unbound -d -p")
     65 |end()
     66 
     67 |start_oneshot("hostname")
     68 |in_bundle("ok-all-but-tty")
     69 |up()
     70 	{{qexec("hostname")}} -F {{qconfig("hostname")}}
     71 |end()
     72 
     73 |start_oneshot("loadkeys", "kbd_mode")
     74 |enabled_bundle("ok-all-but-tty")
     75 |up()
     76 	{{qexec("cd")}} {{qconfig("console_keymap")}} {{qexec("loadkeys")}} --unicode keymap
     77 |end()
     78 
     79 |### per-TTY services ###
     80 
     81 |for(tty=1; tty<=(<getty_max>+0); tty++) {
     82 |start_longrun("tty" tty, "ok-sysinit")
     83 |in_bundle("gettys")
     84 |run_el()
     85 	{{qexec("foreground")}} { {{qexec("issue-gen")}} }
     86 	{{qexec("env")}} LOGIN_TTY=/dev/tty{{tty}} {{qexec("getty")}} -l {{qexec("login-keepenv")}} 38400 tty{{tty}} linux
     87 |if(tty >= 1 && tty <= 4) {
     88 |finish_el()
     89 	{{qexec("foreground")}} {
     90 		{{qexec("chgrp")}}
     91 		-R root
     92 		/run/service/X{{tty + 4}}/supervise
     93 		/run/service/X{{tty + 4}}/event
     94 	}
     95 	{{qexec("foreground")}} { {{qexec("chown")}} xorg:root /run/Xauthority.$X }
     96 	{{qexec("s6-svc")}} -wD -d /run/service/X{{tty + 4}}
     97 |end()
     98 |}
     99 |}
    100 
    101 |for(tty=1; tty<=(<tty_max>+0); tty++) {
    102 |start_oneshot("kbd_mode-tty" tty)
    103 |in_bundle("kbd_mode")
    104 |up()
    105 	kbd_mode -u -C /dev/tty{{tty}}
    106 |end()
    107 |}
    108 
    109 |if(get("tty_setfont")) {
    110 |add_to_bundle("ok-all-but-tty", "setfont")
    111 |for(tty=1; tty<=(<tty_max>+0); tty++) {
    112 |start_oneshot("setfont-tty" tty)
    113 |in_bundle("setfont")
    114 |up()
    115 	redirfd -r 0 /dev/tty{{tty}} setfont {<tty_setfont>}
    116 |end()
    117 |}
    118 |}
    119 
    120 |start_oneshot("dmesg")
    121 |in_bundle("ok-all-but-tty")
    122 |up()
    123 	# description="Set the dmesg level for a cleaner boot"
    124 	# dmesg_level=1
    125 	{{qexec("dmesg")}} -n1
    126 |end()
    127 
    128 |start_oneshot("modules", "dmesg")
    129 |in_bundle("ok-all-but-tty")
    130 |up()
    131 @for i in modprobe_modules
    132 	{{qexec("foreground")}} { {{qexec("modprobe")}} {<i.module>} }
    133 @endfor
    134 |end()
    135 
    136 |start_oneshot("sysctl", "modules")
    137 |in_bundle("ok-all-but-tty")
    138 |up()
    139 	{{qexec("sysctl")}} -p {{qconfig("sysctl.conf")}}
    140 |end()
    141 
    142 |start_oneshot("cgroups", "mount-run-cgroup")
    143 |in_bundle("ok-sysinit")
    144 |up()
    145 	cgconfigparser -l {{qconfig("cgconfig.conf")}}
    146 |end()
    147 
    148 |start_oneshot("mdevd-coldplug", "mount-dev mount-sys sysctl modules mdevd")
    149 |up()
    150 	{{qenv("mdevd")}} mdevd-coldplug
    151 |end()
    152 
    153 |start_oneshot("udev-coldplug", "mount-dev mount-sys sysctl modules udev")
    154 |up()
    155 	udevadm settle
    156 |end()
    157 
    158 |if(get("dev_manager")) {
    159 |service("dev-coldplug", "bundle", (<dev_manager>)"-coldplug")
    160 |add_to_bundle("ok-sysinit", (<dev_manager>))
    161 |}
    162 
    163 |start_oneshot("prepare-dev", "mount-dev")
    164 |up()
    165 	if { ln -s -f /proc/self/fd  /dev/ }
    166 	if { ln -s -f /proc/self/fd/0  /dev/stdin }
    167 	if { ln -s -f /proc/self/fd/1  /dev/stdout }
    168 	ln -s -f /proc/self/fd/2  /dev/stderr
    169 |end()
    170 
    171 |start_longrun("mdevd", "mount-dev prepare-dev mount-sys")  # TODO add "mount-proc mount-sys", add logger
    172 |notification_fd(3)
    173 |run()
    174 	#!{{env_el("mdevd")}} -P
    175 	mdevd -D 3 -b 67108864 -f {{qconfig("mdevd.conf")}}
    176 |end()
    177 
    178 |start_longrun("udev", "mount-sys mount-proc mount-dev")  # TODO add logger
    179 |notification_fd(3)
    180 |run_el()
    181 	background {
    182 		sh -xc "until /sbin/udevadm settle --timeout=120; do sleep 0.5; done; echo >&3 settled"
    183 		#foreground { loopwhilex -x 0 if -nt { /sbin/udevadm settle --timeout=120 } foreground { sleep 0.1 } exit 1 }
    184 		#fdmove -c 3 1
    185 		#echo
    186 	}
    187 	fdclose 3
    188 	/sbin/udevd
    189 |end()
    190 
    191 |start_oneshot("swapon-vg-swap", "dev-coldplug")
    192 |#in_bundle("ok-all-but-tty")
    193 |up()
    194 	{{qexec("swapon")}} /dev/vg/swap
    195 |down()
    196 	{{qexec("swapoff")}} /dev/vg/swap
    197 |end()
    198 
    199 |start_oneshot("mount-tmp-X11", "ok-sysinit")
    200 |in_bundle("ok-mount")
    201 |up()
    202 	{{qexec("if")}} { {{qexec("mkdir")}} -p /tmp/.X11-unix /run/X11 }
    203 	{{qexec("if")}} { {{qexec("chmod")}} 771 /run/X11 }
    204 	{{qexec("if")}} { {{qexec("chown")}} root:xorg /run/X11 }
    205 	{{qexec("mount")}} --bind /run/X11 /tmp/.X11-unix
    206 |down()
    207 	{{qexec("foreground")}} { {{qexec("umount")}} /tmp/.X11-unix }
    208 |end()
    209 
    210 |start_oneshot("openrc", "ok-sysinit ok-mount sysctl modules")
    211 |up()
    212 	export TERM "linux"
    213 	foreground { /sbin/openrc boot }
    214 	/sbin/openrc default
    215 |down()
    216 	export TERM "linux"
    217 	/sbin/openrc shutdown
    218 |end()
    219 
    220 |start_longrun_with_logger("sshd", "ssh_host_ed25519_key ssh_host_rsa_key ok-sysinit")
    221 |enabled_bundle("ok-all-but-tty")
    222 |run_arg("/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config")
    223 |end()
    224 
    225 |start_oneshot("ssh_host_ed25519_key", "hostname rootfs")
    226 |up()
    227 	if -n -t { eltest -f /etc/ssh/ssh_host_ed25519_key }
    228 	ssh-keygen -N "" -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
    229 |end()
    230 
    231 |start_oneshot("ssh_host_rsa_key", "hostname rootfs")
    232 |up()
    233 	if -n -t { eltest -f /etc/ssh/ssh_host_rsa_key }
    234 	ssh-keygen -N "" -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key
    235 |end()
    236 
    237 |#|add_to_bundle("ok-all-but-tty", "swap")
    238 |#/swap	d	m755
    239 |#/swap/type	cN	oneshot	m644
    240 |#/swap/up	cN	swapon -a	m644
    241 |#/swap/down	cN	swapoff -a	m644
    242 
    243 |start_oneshot("alsa-devices", "sysctl modules dev-coldplug")
    244 |up()
    245 	sh -c "
    246 	retry=true
    247 	while $retry; do
    248 	retry=false
    249 	for card in $(sed -n -e '/^ \\?[0-9]/{s/ *\\([0-9]*\\).*/\\1/;p}' /proc/asound/cards); do
    250 	$retry && sleep 0.5
    251 	test -e /dev/snd/controlC${card} || retry=true
    252 	done
    253 	$retry && sleep 0.5
    254 	done
    255 	:
    256 	"
    257 |end()
    258 
    259 |start_longrun_with_logger("alsactl-rdaemon","alsa-devices")
    260 |enabled_bundle("ok-all-but-tty")
    261 |run_arg("alsactl rdaemon")
    262 |end()
    263 
    264 |start_oneshot("brightness", "ok-sysinit")
    265 |enabled_bundle("ok-all-but-tty")
    266 |up()
    267 	foreground { redirfd -w 1 /sys/class/backlight/intel_backlight/brightness echo 800 }
    268 	if { chgrp users /sys/class/backlight/intel_backlight/brightness }
    269 	chmod g+w  /sys/class/backlight/intel_backlight/brightness
    270 |end()
    271 
    272 |start_oneshot("tlp", "ok-sysinit")
    273 |enabled_bundle("ok-all-but-tty")
    274 |up()
    275 	tlp init start
    276 |down()
    277 	tlp init stop
    278 |end()
    279 
    280 |start_oneshot("containers", "ok-mount")
    281 |enabled_bundle("ok-all-but-tty")
    282 |up()
    283 	{{qenv("containers")}}
    284 	export TERM "linux"
    285 	if {
    286 		export quiet 1
    287 		confz site_container_services
    288 	}
    289 	s6-svscanctl -a /run/service
    290 |end()
    291 
    292 |if(find("user_svscan.rows")) {
    293 @for u in user_svscan
    294 |start_longrun("svscan-"(<u.name>)"-log", "ok-sysinit rootfs")
    295 |consumer_for("svscan-"(<u.name>))
    296 |run_el()
    297 	if { mkdir -p /run/user/{<u.id>}.logs }
    298 	if { ln -sf {<u.id>}.logs /run/user/{<u.name>}.logs }
    299 	if { chown {<u.name>}: /run/user/{<u.id>}.logs }
    300 	if { chmod 700 /run/user/{<u.id>}.logs }
    301 	s6-envuidgid {<u.name>} applyuidgid-caps -U ""
    302 	s6-log -- t /run/user/{<u.id>}.logs
    303 |end()
    304 
    305 |start_longrun("svscan-"(<u.name>), "ok-sysinit rootfs")
    306 |in_bundle("ok-all-but-tty")
    307 |notification_fd(3)
    308 |producer_for("svscan-"(<u.name>)"-log")
    309 |run_el()
    310 	if { mkdir -p /run/user/{<u.id>} }
    311 	if { ln -sf {<u.id>} /run/user/{<u.name>} }
    312 	if { chown {<u.name>}: /run/user/{<u.id>} }
    313 	if { chmod 700 /run/user/{<u.id>} }
    314 	s6-envuidgid {<u.name>} applyuidgid-caps -U ""
    315 	if { mkdir -p /run/user/{<u.id>}/service }
    316 	s6-svscan -d 3 /run/user/{<u.id>}/service
    317 |end()
    318 @endfor
    319 |}
    320 
    321 |start_longrun_with_logger("syncthing", "ok-mount")
    322 |enabled_bundle("ok-all-but-tty")
    323 |run_el()
    324 	/usr/bin/env HOME=/var/lib/syncthing
    325 	s6-envuidgid syncthing applyuidgid-caps -U ""
    326 	syncthing -logflags 0
    327 |end()
    328 
    329 |if(find("tinc_networks.rows")) {
    330 @for i in tinc_networks
    331 |tinc_network = get("i.name")
    332 |start_longrun_with_logger("tinc." tinc_network, "net-all")
    333 |add_to_bundle("ok-all-but-tty", "tinc." tinc_network)
    334 |run_arg("tincd -n \"" tinc_network "\" -D -d")
    335 |end()
    336 @endfor
    337 |}
    338 
    339 |start_longrun_with_logger("rsyncd", "loopback\nok-mount")
    340 |run_el()
    341 	/usr/bin/rsync
    342 	--daemon
    343 	--no-detach
    344 	--log-file=/dev/stdout
    345 	--address=127.0.0.1
    346 	--port=873
    347 	--config=/etc/rsyncd.conf
    348 |end()
    349 
    350 |start_longrun_with_logger("wpa_supplicant", "sysctl modules ok-sysinit")
    351 |#enabled_bundle("net-all")
    352 |run_el()
    353 	/usr/sbin/wpa_supplicant
    354 	-iwlan0
    355 	-c/etc/wpa_supplicant/wpa_supplicant.conf
    356 |end()
    357 
    358 
    359 |if(find("X_servers.rows")) {
    360 /.scripts	d	m755
    361 /.scripts/X.run
    362 CN	#!{{env_el("containers")}} -P
    363 	fdmove -c 2 1
    364 	s6-envdir env
    365 	importas vtN vtN
    366 	export XDG_RUNTIME_DIR /run/service/X${vtN}/data
    367 	importas XDG_RUNTIME_DIR XDG_RUNTIME_DIR
    368 	if { truncate -s 0 ${XDG_RUNTIME_DIR}/Xauthority }
    369 	if { chmod 600 ${XDG_RUNTIME_DIR}/Xauthority }
    370 	if { chown xorg:xorg ${XDG_RUNTIME_DIR}/Xauthority }
    371 	if { chown xorg:xorg ${XDG_RUNTIME_DIR} }
    372 	if {
    373 	  pipeline {
    374 	    if { printf "add :%d . " ${vtN} }
    375 	    if { redirfd -r 0 /dev/urandom xxd -p -l 16 }
    376 	  }
    377 	  xauth -f ${XDG_RUNTIME_DIR}/Xauthority source -
    378 	}
    379 	piperw 4 5
    380 	background -d {
    381 	  fdclose 5
    382 	  if { mkdir -p ${XDG_RUNTIME_DIR}/env }
    383 	  if {
    384 	    redirfd -w 1 ${XDG_RUNTIME_DIR}/env/XAUTHORITY
    385 	    printf "%s/Xauthority" ${XDG_RUNTIME_DIR}
    386 	  }
    387 	  if {
    388 	    fdmove 0 4
    389 	    redirfd -w 1 ${XDG_RUNTIME_DIR}/env/DISPLAY
    390 	    if { printf : }
    391 	    head -n1
    392 	  }
    393 	  fdmove 1 3
    394 	  echo
    395 	}
    396 	unexport !
    397 	fdclose 4
    398 	fdclose 3
    399 	umask 077
    400 	if { chmod 660 /dev/tty${vtN} }
    401 	if { chown root:xorg /dev/tty${vtN} }
    402 	if {
    403 	  elglob dev /dev/input/event*
    404 	  if { chown root:input ${dev} }
    405 	  chmod 660 ${dev}
    406 	}
    407 	redirfd -r 0 /dev/tty${vtN}
    408 	redirfd -w 1 /dev/tty${vtN}
    409 	s6-setsid
    410 	s6-envuidgid xorg applyuidgid-caps -U ""
    411 	Xorg
    412 	  -displayfd 5
    413 	  -nolisten local
    414 	  -nolisten tcp
    415 	  -quiet
    416 	#  -logfile /dev/stdout
    417 	  -logfile ${XDG_RUNTIME_DIR}/log
    418 	  -auth ${XDG_RUNTIME_DIR}/Xauthority
    419 	  -tst
    420 	  -retro
    421 	  -novtswitch
    422 	  vt${vtN} :${vtN}
    423 	
    424 m755
    425 
    426 @for i in X_servers
    427 /{<i.svc>}	d	m750
    428 /{<i.svc>}/data	d	m750
    429 /{<i.svc>}/data/.keep	cN		m640
    430 /{<i.svc>}/env	d	m750
    431 /{<i.svc>}/env/vtN	cN	{<i.vtN>}	m640
    432 /{<i.svc>}/notification-fd	cN	3	m640
    433 /{<i.svc>}/run	l	../.scripts/X.run	m777
    434 /{<i.svc>}/type	cN	longrun	m640
    435 @endfor
    436 
    437 |}
    438 
    439 |print_bundles()
    440 |}