mrrl

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

system-config-init (4153B)


      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")}}/{{configdir}}/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/{{bindir}}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
     21 	-G "$(q "$prefix/deps/{{bindir}}/env") TERM=linux $(q "$prefix/deps/{{bindir}}/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/{{bindir}}/$name
     35 
     36 # Rewrite bin/init as it fails finding it's own s6-linux-init
     37 s6-cat >"${dest}/bin/init" <<EOF || exit $?
     38 #!$el -S0
     39 $(qx importas) -D "/run/current/{{bindir}}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -S PATH
     40 $(qx s6-linux-init) -v 1 -m 0022 -c $(q "$prefix") -p \$PATH -N -- "\$@"
     41 EOF
     42 chmod +x "${dest}/bin/init"
     43 
     44 qx sh
     45 sh=$prefix/deps/{{bindir}}/$name
     46 # Wrapper for setting up current environment and then running init
     47 s6-cat >"${dest}/bin/init-in-pthbs-environment" <<EOF || exit $?
     48 #!$sh -x
     49 die() {
     50   set +x
     51   printf '*** error occured, dropping into interactive shell ***\\n'
     52   exec /sbin/sulogin -p
     53 }
     54 which install-as-current-environment || die
     55 which init || die
     56 which modprobe || die
     57 rm -v /run/current
     58 install-as-current-environment || die
     59 exec /run/current/command/init || die
     60 EOF
     61 chmod +x "${dest}/bin/init-in-pthbs-environment"
     62 
     63 # Rewrite dynamically generated scripts
     64 s6-cat >"${dest}/scripts/rc.init" <<EOF || exit $?
     65 #!$el -S1
     66 $(qx importas) -D linux -S TERM
     67 $(qx importas) -D $(q "$s6rcdb") -S pthbs_s6_rc_db
     68 $(qx export) TERM \$TERM
     69 $(qx foreground) { $(qx s6-echo) "* Starting s6-rc from \$pthbs_s6_rc_db" }
     70 $(qx if) { $(qx s6-rc-init) -d -c \$pthbs_s6_rc_db /run/service }
     71 $(q "$prefix/scripts/runlevel") \$1
     72 EOF
     73 
     74 s6-cat >"${dest}/scripts/rc.shutdown" <<EOF || exit $?
     75 #!$el -P
     76 
     77 ### Things to do before hardware halt/reboot/poweroff.
     78 ### Ideally, it should be a single call to the service manager,
     79 ### telling it to bring all the services down.
     80 
     81 $(qx redirfd) -w 1 /dev/console
     82 $(qx redirfd) -w 2 /dev/console
     83 $(qx s6-rc) -v2 -bDa change
     84 EOF
     85 
     86 s6-cat >"${dest}/scripts/runlevel" <<EOF || exit $?
     87 #!$el -S1
     88 $(qx importas) -D linux -S TERM
     89 $(qx importas) -D $(q "$s6rcdb") -S pthbs_s6_rc_db
     90 $(qx export) TERM \$TERM
     91 
     92 # The requested runlevel is in "\$1" but currently ignored.
     93 
     94 # Run the service manager.
     95 # Call it twice because the first time may spuriously "timeout"
     96 # due to the clock jumping forward.
     97 
     98 $(qx ifelse) -X {
     99 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty 
    100 } {
    101 	# no timeout, start ttys properly
    102 	$(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
    103 	$(qx foreground) { sleep 0.3 }
    104 	$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    105 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all
    106 }
    107 $(qx foreground) { $(qx s6-echo) "* System startup failure: retry" }
    108 # try again without tty and then with
    109 $(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
    110 $(qx foreground) { $(qx sleep) 0.1 }
    111 $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    112 $(qx s6-rc) -v 2 -t 600000 -- change ok-all
    113 EOF
    114 
    115 s6-mkdir "${dest}/run-image/service/console-log-tail" || exit $?
    116 s6-cat >"${dest}/run-image/service/console-log-tail/run" <<EOF || exit $?
    117 #!$el -P
    118 $(qx redirfd) -w 1 /dev/console
    119 $(qx fdmove) -c 2 1
    120 $(qx pipeline) -w { $(qx s6-tai64nlocal) }
    121 $(qx tail) -F -n +1 /run/uncaught-logs/current
    122 EOF
    123 s6-chmod 755 "${dest}/run-image/service/console-log-tail/run" exit $?
    124 
    125 {% endblock %}
    126 {% block genlinks_begin %}
    127 	x["./bin/init"]=1
    128 	x["./bin/halt"]=1
    129 	x["./bin/poweroff"]=1
    130 	x["./bin/reboot"]=1
    131 {% endblock %}