mrrl

Minimal Reliable Reproducible Linux
git clone https://ccx.te2000.cz/git/mrrl
Log | Files | Refs | Submodules | README

system-config-init (3340B)


      1 {%- set src_dir="." -%}
      2 {% extends "genlinks" %}
      3 {%- do import_functions.update(["q", "qx"]) %}
      4 {% block package_deps -%}
      5 #+{{pkg_install_name("s6")}}
      6 #+{{pkg_install_name("s6-rc")}}
      7 #+{{pkg_install_name("s6-portable-utils")}}
      8 #+{{pkg_install_name("s6-linux-init")}}
      9 #+{{pkg_install_name("execline")}}
     10 #+{{pkg_install_name("system-config-rc")}}
     11 {% endblock %}
     12 {% block build_and_install -%}
     13 s6rcdb={{pkg_install_dir("system-config-rc")}}/config/s6-rc-db
     14 
     15 # Generate init (${dest} must not exist but parent dir does)
     16 mkdir -p "$pthbs_destdir/{{versions}}"
     17 s6-linux-init-maker \
     18 	-p "/run/current/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
     19 	-G "$(q "$prefix/deps/command/env") TERM=linux $(q "$prefix/deps/command/getty") 38400 tty9" \
     20 	-t 1 \
     21 	-N \
     22 	-c "$prefix" \
     23 	"${dest}"
     24 
     25 
     26 # Link deps that are passed to s6-l-i-m
     27 qx env
     28 qx getty
     29 
     30 # Link execlineb - can't quote shebang
     31 qx execlineb
     32 el=$prefix/deps/command/$name
     33 
     34 # Rewrite bin/init as it fails finding it's own s6-linux-init
     35 s6-cat >"${dest}/bin/init.new" <<EOF || exit $?
     36 #!$el -S0
     37 $(qx pthbs-enter)
     38 $(qx s6-envdir) -I /run/current/env
     39 EOF
     40 s6-cat >>"${dest}/bin/init.new" <"${dest}/bin/init"
     41 chmod +x "${dest}/bin/init.new"
     42 mv -v "${dest}/bin/init.new" "${dest}/bin/init"
     43 
     44 # Rewrite dynamically generated scripts
     45 s6-cat >"${dest}/scripts/rc.init" <<EOF || exit $?
     46 #!$el -S1
     47 $(qx export) TERM "linux"
     48 $(qx foreground) { $(qx s6-echo) "* Starting s6-rc from "$(q "$s6rcdb") }
     49 $(qx if) { $(qx s6-rc-init) -d -c $(q "$s6rcdb") /run/service }
     50 $prefix/scripts/runlevel \$1
     51 EOF
     52 
     53 s6-cat >"${dest}/scripts/rc.shutdown" <<EOF || exit $?
     54 #!$el -P
     55 
     56 ### Things to do before hardware halt/reboot/poweroff.
     57 ### Ideally, it should be a single call to the service manager,
     58 ### telling it to bring all the services down.
     59 
     60 $(qx redirfd) -w 1 /dev/console
     61 $(qx redirfd) -w 2 /dev/console
     62 $(qx s6-rc) -v2 -bDa change
     63 EOF
     64 
     65 s6-cat >"${dest}/scripts/runlevel" <<EOF || exit $?
     66 #!$el -S1
     67 export TERM "linux"
     68 
     69 # The requested runlevel is in "\$1" but currently ignored.
     70 
     71 # Run the service manager.
     72 # Call it twice because the first time may spuriously "timeout"
     73 # due to the clock jumping forward.
     74 
     75 $(qx ifelse) -X {
     76 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty 
     77 } {
     78 	# no timeout, start ttys properly
     79 	$(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
     80 	$(qx foreground) { sleep 0.3 }
     81 	$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
     82 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all
     83 }
     84 $(qx foreground) { $(qx s6-echo) "* System startup failure: retry" }
     85 # try again without tty and then with
     86 $(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
     87 $(qx foreground) { $(qx sleep) 0.1 }
     88 $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
     89 $(qx s6-rc) -v 2 -t 600000 -- change ok-all
     90 EOF
     91 
     92 s6-mkdir "${dest}/run-image/service/console-log-tail" || exit $?
     93 s6-cat >"${dest}/run-image/service/console-log-tail/run" <<EOF || exit $?
     94 #!$el -P
     95 $(qx redirfd) -w 1 /dev/console
     96 $(qx fdmove) -c 2 1
     97 $(qx pipeline) -w { $(qx s6-tai64nlocal) }
     98 $(qx tail) -F -n +1 /run/uncaught-logs/current
     99 EOF
    100 s6-chmod 755 "${dest}/run-image/service/console-log-tail/run" exit $?
    101 
    102 {% endblock %}
    103 {% block genlinks_begin %}
    104 	x["./bin/init"]=1
    105 	x["./bin/halt"]=1
    106 	x["./bin/poweroff"]=1
    107 	x["./bin/reboot"]=1
    108 {% endblock %}