carbon-config

config submodule of carbon-core-system
git clone https://ccx.te2000.cz/git/carbon-config
Log | Files | Refs

s6-rc.aat (9766B)


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