dot

packages and services management
Log | Files | Refs | README

commit e5a594c3ef02d5111f90898b135803a09c1ebe25
parent 94ba5ec88ab2a02e90a04b1f7c9ed04555135761
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 16 Dec 2018 21:27:57 +0100

calling for a revolution

Diffstat:
Dbin/service-build | 50--------------------------------------------------
Dbin/service-bundle | 18------------------
Mbin/service-compile | 34++++++++++++++++++++++++++++------
Mbin/service-disable | 8+++-----
Mbin/service-enable | 54+++++++++++++++++++++++++++++++++++++++++++++++++-----
Mbin/service-init | 54++++++++++++++++++++++++++++++++++--------------------
Mbin/service-list | 10+++++-----
Mbin/service-log | 2+-
Dbin/service-reload | 6------
Dbin/service-shutdown | 3---
Mbin/service-status | 9+++------
Mconf/etc | 1-
12 files changed, 123 insertions(+), 126 deletions(-)

diff --git a/bin/service-build b/bin/service-build @@ -1,50 +0,0 @@ -#!/usr/bin/env execlineb -elgetpositionals -if { mkdir -p /var/s6 } cd /var/s6 - -forx -o 0 x { ${@} } -importas sv x - -backtick -n x { heredoc 0 ${sv} cut -d , -f 1 } -importas base x - -backtick -n x { heredoc 0 ${sv} cut -s -d , -f 2- } -importas -s -d , mod x - -redirfd -r 0 /etc/s6/${base}/x/type -withstdinas x -importas -n type x - -if { cd /etc/s6/${base} redirfd -w 1 /dev/null ls -d ${mod} } -if { rm -rf ${sv} ${sv},log } - -ifte { } { if { rm -rf ${sv} ${sv},log } exit 1 } - -# copy all the modules -if { - forx -o 0 x { x ${mod} } importas x x - s6-hiercopy /etc/s6/${base}/${x} ${sv} -} - -# build bundles recursively -if { - if -t { test ${type} = bundle } - backtick -i x { sed "s/^#.*//; /^[ \t]*$/ d" ${sv}/contents } - importas -s -d "\n" x x - service-build ${x} -} - -# setup the logger for longruns -if { - if -t { test ${type} = longrun } - ifthenelse { test -d /etc/s6/${sv}/log } - { s6-hiercopy /etc/s6/${sv}/log ${sv},log } - { s6-hiercopy /etc/s6/.s6-log ${sv},log } - if { redirfd -a 1 ${sv}/producer-for echo ${sv},log } - if { redirfd -w 1 ${sv},log/env/SERVICE echo ${sv} } - if { redirfd -w 1 ${sv},log/consumer-for echo ${sv} } -} - -cd ${sv} -if -t { test -e setup } -./setup diff --git a/bin/service-bundle b/bin/service-bundle @@ -1,18 +0,0 @@ -#!/usr/bin/env execlineb -cd /var/s6 - -# make a bundle for base service with all variants -forbacktickx -n x { - pipeline { s6-ls . } - pipeline { sed "s/,.*//" } - sort -u -} -importas base x - -if -t { if -t { test -f ${base}/type } if { grep bundle -Fxq ${base}/type } } -if { mkdir -p ${base} } -if { redirfd -w 1 ${base}/type echo bundle } - -redirfd -w 1 ${base}/contents -elglob -0s x ${base},* -printf "%s\n" ${x} diff --git a/bin/service-compile b/bin/service-compile @@ -1,11 +1,33 @@ #!/usr/bin/env execlineb +cd /var/s6 + +# bundle service by base (% in %,module-1,module-2) +if { + cd source + + forbacktickx -n -o 0 x { + pipeline { ls } + pipeline { sed "s/,.*//" } + sort -u + } + importas base x + + if -t { + if -n { test -f ${base}/type } + if -n { grep -Fxq bundle ${base}/type } + } + if { mkdir -p ${base} } + if { redirfd -w 1 ${base}/type echo bundle } + redirfd -w 1 ${base}/contents + elglob -0s x ${base},* + printf "%s\n" ${x} +} + backtick -n x { s6-clock } importas time x -backtick -n x { pwd } -importas pwd x - -if { mkdir -p /var/s6 /var/s6-rc/compiled } -if { s6-rc-compile /var/s6-rc/compiled/${time} /var/s6 } -if { s6-rc-update -l /run/s6-rc /var/s6-rc/${time} } +if { mkdir -p source compiled } +if { s6-rc-compile compiled/${time} source } +if { s6-ln -nsf compiled/${time} current } +s6-rc-update -l /var/s6/live /var/s6/compiled/${time} diff --git a/bin/service-disable b/bin/service-disable @@ -1,7 +1,5 @@ #!/usr/bin/env execlineb -cd /var/s6 -elgetpositionals -P 1 +elgetpositionals -if { rm -rf ${@} ${@},log } -if { service-bundle } -if { service-compile } +if { rm -rf /var/s6/source/${@} /var/s6/source/${@},log } +service-compile diff --git a/bin/service-enable b/bin/service-enable @@ -1,7 +1,51 @@ #!/usr/bin/env execlineb -elgetpositionals -P 1 -cd /var/s6 +elgetpositionals -if { service-build $@ } -if { service-bundle } -if { service-compile } +if { mkdir -p /var/s6/source } +cd /var/s6/source + +forx -o 0 x { ${@} } +importas sv x + +backtick -n x { heredoc 0 ${sv} cut -d , -f 1 } +importas base x + +backtick -n x { heredoc 0 ${sv} cut -s -d , -f 2- } +importas -s -d , mod x + +redirfd -r 0 /etc/s6/${base}/x/type +withstdinas x +importas -n type x + +if { cd /etc/s6/${base} redirfd -w 1 /dev/null ls -d ${mod} } +if { rm -rf ${sv} ${sv},log } + +ifte { } { if { rm -rf ${sv} ${sv},log } exit 1 } + +# copy all the modules +if { + forx -o 0 x { x ${mod} } importas x x + s6-hiercopy /etc/s6/${base}/${x} ${sv} +} + +# build bundles recursively +if { + if -t { test ${type} = bundle } + backtick -i x { sed "s/^#.*//; /^[ \t]*$/ d" ${sv}/contents } + importas -s -d "\n" x x + service-build ${x} +} + +# setup the logger for longruns +if { + if -t { test ${type} = longrun } + ifthenelse { test -d /etc/s6/${sv}/log } + { s6-hiercopy /etc/s6/${sv}/log ${sv},log } + { s6-hiercopy /etc/s6/.s6-log ${sv},log } + if { redirfd -a 1 ${sv}/producer-for echo ${sv},log } + if { redirfd -w 1 ${sv},log/env/SERVICE echo ${sv} } + if { redirfd -w 1 ${sv},log/consumer-for echo ${sv} } +} + +if { cd ${sv} if -t { test -x setup } ./setup } +service-compile diff --git a/bin/service-init b/bin/service-init @@ -1,35 +1,49 @@ #!/usr/bin/env execlineb -if { s6-rmrf /run/s6 /run/s6-rc } -if { s6-mkdir -p /etc/s6-rc /var/s6-rc /run/s6-rc } +if { s6-mkdir -p /var/s6/source /var/s6/compiled /var/s6/scandir } +cd /var/s6 -# write a logger service -if { s6-hiercopy /etc/s6-rc/log } -if { s6-mkdir -p /run/s6/log } -if { s6-mkfifo /run/s6/log/fifo } -if { redirfd -w 0 /var/s6/log/run echo "#!/usr/bin/env execlineb -fdmove -c 2 1 redirfd -rnb 0 /var/s6/log/fifo s6-log -bp t /var/log/s6" } -if { redirfd -w 0 /run/s6/log/type echo "longrun" } +if { elglob -0 x scandir/* rm -rf ${x} } +if { elglob -0 x live* rm -rf ${x} } + +# logger +if { s6-mkdir -p scandir/logger } +if { s6-mkfifo scandir/logger/fifo } +if { redirfd -w 1 scandir/logger/run printf "%s\n" + "#!/usr/bin/env execlineb" + "fdmove -c 2 1" + "redirfd -rnb 0 fifo" + "s6-log -bp t /var/log/s6" +} +if { s6-chmod 0755 scandir/logger/run } +if { redirfd -w 1 scandir/logger/type echo "longrun" } + +# ok-all +if { s6-mkdir -p source/ok-all } +if { touch source/ok-all/contents } +if { redirfd -w 1 source/ok-all/type echo "bundle" } background { backtick -n x { s6-clock } importas t x - if { if -nt { test -k /etc/s6-rc/compiled } - if { s6-rc-compile /var/s6-rc/${t} /var/s6 } - if { s6-ln -sfn /var/s6-rc/${t} /etc/s6-rc/compiled } - } + ifthenelse { test ! -h current } { + if { s6-rc-compile compiled/${t} source } + if { s6-ln -sfn compiled/${t} current } + } { } # wait that s6-svscan starts - redirfd -w 1 /var/s6-rc/log + redirfd -w 1 scandir/logger/log - if { s6-rc-init -c /var/s6-rc/${t} /run/s6 } - if { s6-rc -u change s6rc-fdholder } - if { s6-rc -u change s6rc-oneshot-runner } - if { echo service-init started } + if { s6-rc-init -d -c current -l /var/s6/live /var/s6/scandir } + if { s6-rc -l live -u change s6rc-fdholder } + if { s6-rc -l live -u change s6rc-oneshot-runner } + if { s6-rc -l live -u change ok-all } + if { s6-ln -sf /var/s6/live /run/s6-rc } + if { echo srv-init finished to boot } } redirfd -r 0 /dev/null -redirfd -wnb 1 /run/s6/log/fifo +redirfd -wnb 1 /var/s6/scandir/logger/fifo fdmove -c 2 1 -s6-svscan -t0 /run/s6 +s6-svscan -t0 /var/s6/scandir diff --git a/bin/service-list b/bin/service-list @@ -4,16 +4,16 @@ elgetpositionals forbacktickx -n -o 0 x { pipeline { ifthenelse { test ${#} = 0 } - { s6-rc-db -l /var/s6-rc/live/live list all } - { s6-rc -l /var/s6-rc/live/live list $@ } + { s6-rc-db -l /var/s6/live list longruns } + { s6-rc -l /var/s6/live list $@ } } - pipeline { sed -n "s/,log$// p" } + pipeline { grep -v ",log$" } sort } importas service x backtick -n x { - pipeline { s6-svstat -o up,wantedup /run/s6/${service} } + pipeline { s6-svstat -o up,wantedup /var/s6/scandir/${service} } sed " s/true true/+/ s/true false/?/ @@ -23,7 +23,7 @@ backtick -n x { } importas flag x -backtick -n x { s6-svstat -o updownfor /run/s6/${service} } +backtick -n x { s6-svstat -o updownfor /var/s6/scandir/${service} } importas updownfor x printf " %s %-40s %10ds\n" ${flag} ${service} ${updownfor} diff --git a/bin/service-log b/bin/service-log @@ -4,7 +4,7 @@ elgetpositionals if -n { test ${#} = 0 } backtick x { - pipeline { s6-rc -l /var/s6-rc/live/live list ${@} } + pipeline { s6-rc -l /var/s6/live list ${@} } pipeline { sed -n "s/,log$// p" } sort } diff --git a/bin/service-reload b/bin/service-reload @@ -1,6 +0,0 @@ -#!/usr/bin/env execlineb - -backtick x { dollarat -n -d , } -importas name x - -s6-svc -h /run/s6/$name diff --git a/bin/service-shutdown b/bin/service-shutdown @@ -1,3 +0,0 @@ -#!/usr/bin/env execlineb - -s6-rc -l /var/s6/.s6-rc/live -d -a change diff --git a/bin/service-status b/bin/service-status @@ -4,18 +4,15 @@ elgetpositionals -P 1 if { printf "\n" } fdmove -c 2 1 -forbacktickx x { - pipeline { s6-rc -l /var/s6/.s6-rc/live list $@ } - sed -n "s/,log$// p" -} +forbacktickx x { pipeline { s6-rc -l /var/s6/live list $@ } grep -v ",log$" } importas -n -d "\n" sv x if { heredoc 0 ${sv} sed -r "s/([^,]*),?(.*)/ \033[1m\\1\033[m (\\2)/; s/\\(\\)/(x)/" } if { printf " " } -if { s6-svstat /run/s6/${sv} } +if { s6-svstat /var/s6/scandir/${sv} } if { printf "\n" } if { - backtick -n x { s6-svstat -o pid /run/s6/${sv} } + backtick -n x { s6-svstat -o pid /var/s6/scandir/${sv} } importas x x pipeline { ps -ax -o ppid,user,pid,stat,comm,args } ptree -- ${x} diff --git a/conf/etc b/conf/etc @@ -7,4 +7,3 @@ ln -sf "$PWD/etc/profile.d/"* /etc/profile.d ln -sf "$PWD/etc/profile" /etc ln -sf "$PWD/etc/pack" /etc ln -sf "$PWD/etc/s6" /etc -ln -sf "$PWD/etc/s6-rc" /etc