dot

packages and services management
Log | Files | Refs | README

commit cc10d62ce4618856fba48b1f91d3df0fd419655f
parent f0360fb78295db85d7d4e6a81539fa82ce3e6932
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 27 Jan 2019 16:17:16 +0100

renew the service scripts for a simpler scheme

Diffstat:
Dbin/rfc | 16----------------
Dbin/s6-mk | 58----------------------------------------------------------
Abin/s6-mk-add | 10++++++++++
Abin/s6-mk-bundle | 15+++++++++++++++
Mbin/s6-mk-compile | 32++++++--------------------------
Abin/s6-mk-env | 11+++++++++++
Abin/s6-mk-new | 19+++++++++++++++++++
Mbin/s6-rc-list | 36++++++++++++++++--------------------
Mbin/s6-rc-status | 21+++++++++++----------
Mconf/init | 11+++++++----
Ahome/.config/open/protocol/irc | 4++++
Ahome/.config/open/protocol/ircs | 4++++
Mhome/.config/open/protocol/ssh | 20++++++++++----------
13 files changed, 113 insertions(+), 144 deletions(-)

diff --git a/bin/rfc b/bin/rfc @@ -1,16 +0,0 @@ -#!/9/bin/rc -# from a rfc number: fetch, cleanup, open in pager - -if (! ~ $#* 1) - echo 'usage: rfc {rfc####,####}' - -rfc=`{echo $1 | sed -r 's,.*/,,; s,[^0-9]*([1-9][0-9]*).*,\1,'} -echo $rfc - -dir=$home/tmp/text/rfc -mkdir -p $dir - -if (! test -f $dir/$rfc.txt) - wget -O $dir/$rfc.txt https://tools.ietf.org/rfc/rfc$rfc.txt - -exec $PAGER $dir/$rfc.txt diff --git a/bin/s6-mk b/bin/s6-mk @@ -1,58 +0,0 @@ -#!/usr/bin/env execlineb -elgetpositionals - -if { mkdir -p /etc/s6-rc } -cd /etc/s6-rc - -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 , modules x - -redirfd -r 0 /etc/s6-mk/${base}/default/type -withstdinas x -importas -n type x - -backtick -n x { if { printf %s ${sv} } if -t { test ${type} = longrun } echo ,x } -importas svname x - -if { rm -rf ${sv} ${sv},x ${sv},log } - -# in case of fire, abandon the ship -ifte { } { if { rm -rf ${sv} ${sv},x ${sv},log } exit 1 } - -# copy each module -if { - forx -o 0 x { default ${modules} } - importas mod x - s6-hiercopy /etc/s6-mk/${base}/${mod} ${svname} -} - -# build bundles recursively -ifthenelse { test ${type} = bundle } { - backtick -i x { sed "s/^#.*//; /^[ \t]*$/ d; s/,x$//" ${sv}/contents } - importas -s -d "\n" x x - s6-mk ${x} -} { } - -# setup the logger for longruns -ifthenelse { test ${type} = longrun } { - ifthenelse { test -d /etc/s6-mk/${sv}/log } - { s6-hiercopy /etc/s6-mk/${sv}/log ${sv},log } - { s6-hiercopy /etc/s6-mk/.log ${sv},log } - if { redirfd -a 1 ${sv},x/producer-for echo ${sv},log } - if { redirfd -w 1 ${sv},log/consumer-for echo ${sv},x } - if { redirfd -w 1 ${sv},log/pipeline-name echo ${sv} } - if { redirfd -w 1 ${sv},log/env/SERVICE echo ${sv} } -} { } - -# run setup scripts -cd ${svname} -forx -o 0 x { default ${modules} } -importas mod x -if -t { test -f /etc/s6-mk/${base}/${mod}/setup } -/etc/s6-mk/${base}/${mod}/setup diff --git a/bin/s6-mk-add b/bin/s6-mk-add @@ -0,0 +1,10 @@ +#!/usr/bin/env execlineb + +elgetpositionals + +if { s6-mk-new ${1} } +if { s6-mk-env ${@} } +if { cd /etc/s6-rc/${1} if -t { test -f setup } ./setup } +if { s6-mk-compile } +if { s6-mk-bundle } +if { s6-rc -u change ${1} } diff --git a/bin/s6-mk-bundle b/bin/s6-mk-bundle @@ -0,0 +1,15 @@ +#!/usr/bin/env execlineb + +# bundle all services with the same base sv (sv:name) + +cd /etc/s6-rc + +forbacktickx -n -d "\n" -o 0 x { + pipeline { ls } + pipeline { sed -rn "s/:.*// p" } + sort -u +} +importas base x + +elglob -0 x ${base}:* +s6-rc-bundle -f add ${base} ${x} diff --git a/bin/s6-mk-compile b/bin/s6-mk-compile @@ -1,28 +1,8 @@ #!/usr/bin/env execlineb -if { mkdir -p /var/s6-mk /var/s6-rc } - -# bundle all services with the same base -if { - cd /var/s6-mk - forbacktickx -n -d "\n" -o 0 x { - pipeline { ls } - pipeline { sed "s/,.*//" } - sort -u - } - importas base x - 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} -} - -# compile the live database -if { - backtick -n x { s6-clock } - importas clock x - if { s6-rc-compile /var/s6-rc/${clock} /var/s6-mk } - if { s6-rc-update /var/s6-rc/${clock} } - if { s6-ln -nsf ${clock} /var/s6-rc/current } -} +# compile the service +backtick -n x { s6-clock } +importas clock x +if { s6-rc-compile /var/s6-rc/${clock} /etc/s6-rc } +if { s6-rc-update /var/s6-rc/${clock} } +if { s6-ln -nsf ${clock} /var/s6-rc/current } diff --git a/bin/s6-mk-env b/bin/s6-mk-env @@ -0,0 +1,11 @@ +#!/usr/bin/env execlineb +importas -i sv:name 1 +importas -i key 2 +importas -i val 3 +shift -n 3 +elgetpositionals + +if { mkdir -p /etc/s6-rc/${sv:name}/env } +if { redirfd -w 1 /etc/s6-rc/${sv:name}/env/${key} printf "%s\n" ${val} } +if -t { test ${#} -gt 0 } +${0} ${sv:name} ${@} diff --git a/bin/s6-mk-new b/bin/s6-mk-new @@ -0,0 +1,19 @@ +#!/usr/bin/env execlineb + +importas -i sv:name 1 +backtick -n x { heredoc 0 ${sv:name} cut -d : -f 1 } +importas -i sv x + +# copy the service +if { mkdir -p /etc/s6-rc/ } +if { rm -rf /etc/s6-rc/${sv:name} } +if { cp -R /etc/s6-mk/${sv} /etc/s6-rc/${sv:name} } + +# add a logger to the service +if -t { redirfd -w 2 /dev/null grep -qFx longrun /etc/s6-mk/${sv}/type } +ifthenelse { test -d /etc/s6-mk/${sv}/log } + { cp -r /etc/s6-mk/${sv}/log /etc/s6-rc/${sv:name}:log } + { cp -r /etc/s6-mk/s6-log /etc/s6-rc/${sv:name}:log } +if { redirfd -w 1 /etc/s6-rc/${sv:name}:log/env/SERVICE echo ${sv:name} } +if { redirfd -w 1 /etc/s6-rc/${sv:name}:log/consumer-for echo ${sv:name} } +if { redirfd -w 1 /etc/s6-rc/${sv:name}/producer-for echo ${sv:name}:log } diff --git a/bin/s6-rc-list b/bin/s6-rc-list @@ -1,26 +1,22 @@ #!/usr/bin/env execlineb elgetpositionals -pipeline { - forbacktickx -n -o 0 x { - pipeline { - ifthenelse { test ${#} = 0 } - { s6-rc-db list longruns } - { s6-rc list $@ } - } - pipeline { sed -n "s/,x$// p" } - sort - } - importas service x +if { printf "%-40s %-9s %-5s %9s\n" "service" "enabled" "running" "since" } - backtick -n x { s6-svstat -o up,wantedup /run/s6/${service},x } - importas up x +forbacktickx -n -o 0 x { pipeline { + ifthenelse { test ${#} = 0 } + { s6-rc-db list longruns } + { s6-rc list $@ } +} sort } +importas service x - backtick -n x { s6-svstat -o updownfor /run/s6/${service},x } - importas since x +backtick -n x { s6-svstat -o updownfor /run/s6/${service} } +importas since x - if { printf "%8ds %s %s\n" ${since} ${up} ${service} } -} sed " - s/true true/ up /; s/true false/kill/g; - s/false true/fail/; s/false false/down/g; -" +backtick -n x { s6-svstat -o wantedup /run/s6/${service} } +importas enabled x + +backtick -n x { s6-svstat -o up /run/s6/${service} } +importas running x + +printf " %-40s %-9s %-5s %9ds\n" ${service} ${enabled} ${running} ${since} diff --git a/bin/s6-rc-status b/bin/s6-rc-status @@ -1,22 +1,23 @@ #!/usr/bin/env execlineb elgetpositionals -P 1 - -if { printf "\n" } - fdmove -c 2 1 -forbacktickx x { pipeline { s6-rc list $@ } sed -n "s/,x$// p" } -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},x } +if { printf "\n" } +forbacktickx -n x { pipeline { s6-rc list $@ } grep -v ":log$" } +importas sv x +if { printf "\033[1m%s \033[m " ${sv} } +if { s6-svstat /run/s6/${sv} } if { printf "\n" } if { - backtick -n x { s6-svstat -o pid /run/s6/${sv},x } + backtick -n x { s6-svstat -o pid /run/s6/${sv} } importas pid x pipeline { ps -ax -o ppid,user,pid,stat,comm,args } ptree -- ${pid} } if { printf "\n" } -if { pipeline { tail /var/log/${sv}/current } s6-tai64nlocal } +if { + pipeline { tail /var/log/${sv}/current } + pipeline { s6-tai64nlocal } + sed "s/^/ /" +} if { printf "\n" } diff --git a/conf/init b/conf/init @@ -1,7 +1,9 @@ #!/usr/bin/env execlineb -if { rm -rf /run/s6 /run/s6-rc } -if { mkdir -p /etc/s6-rc /var/s6-rc /run/s6 } +if { s6-rmrf /run/s6 /run/s6-rc } +if { s6-mkdir -p /etc/s6-rc /var/s6-rc /run/s6 } +if { s6-hiercopy /etc/s6-mk/s6rc-logger /run/s6/s6rc-logger } +if { s6-mkfifo /run/s6/s6rc-logger/fifo } background { ifthenelse { test ! -h current } { @@ -12,14 +14,15 @@ background { } { } # wait that s6-svscan starts - redirfd -w 1 /run/s6/logger/log + redirfd -w 1 /run/s6/s6rc-logger/fifo if { s6-rc-init -d -c /var/s6-rc/current /run/s6 } if { s6-rc -u change ok-all } + if { s6-mk-bundle } echo "=== s6-rc ready ===" } redirfd -r 0 /dev/null -redirfd -wnb 1 /run/s6/logger/fifo +redirfd -wnb 1 /run/s6/s6rc-logger/fifo fdmove -c 2 1 s6-svscan -t0 /run/s6 diff --git a/home/.config/open/protocol/irc b/home/.config/open/protocol/irc @@ -0,0 +1,4 @@ +#!/usr/bin/env execlineb +elgetpositionals + +s6-mk-add ii:${3} NICK ${2} HOST ${3} PORT ${4} PROTO tcp diff --git a/home/.config/open/protocol/ircs b/home/.config/open/protocol/ircs @@ -0,0 +1,4 @@ +#!/usr/bin/env execlineb +elgetpositionals + +s6-mk-add ii:${3} NICK ${2} HOST ${3} PORT ${4} PROTO tls diff --git a/home/.config/open/protocol/ssh b/home/.config/open/protocol/ssh @@ -1,14 +1,14 @@ #!/usr/bin/env execlineb multisubstitute { - importas uri 1 - importas user 2 - importas host 3 - importas port 4 - importas path 5 - importas frag 6 + importas uri 1 + importas user 2 + importas host 3 + importas port 4 + importas path 5 + importas frag 6 } -ifelse { if { test ${port} } if { test ${user} } { exec ssh -p ${port} ${user}@${host} } -ifelse { if -n { test ${port} } if { test ${user} } { exec ssh ${user}@${host} } -ifelse { if { test ${port} } if -n { test ${user} } { exec ssh -p ${port} ${host} } -ifelse { if -n { test ${port} } if -n { test ${user} } { exec ssh ${host} } +ifelse { if { test ${port} } test ${user} } { exec ssh -p ${port} ${user}@${host} } +ifelse { if { test ! ${port} } test ${user} } { exec ssh ${user}@${host} } +ifelse { if { test ${port} } test ! ${user} } { exec ssh -p ${port} ${host} } +ifelse { if { test ! ${port} } test ! ${user} } { exec ssh ${host} }