mrrl

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

system-config-init (3404B)


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