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