dot

packages and services management
Log | Files | Refs | README

commit b5aff7706ce5f25b8c21ffa9c88fc6d241d14837
parent 9548b24297d76db04a1c36176898d1c186f239c2
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat,  8 Dec 2018 14:03:31 +0100

bin/sevice-*: Keep a constant structure

base-service-1
 |  # bundle with all the variants
 |
 |-base-service-1,module-1,module-2
 |   |  # bundle with the longrun and the logger if any
 |   |
 |   |- base-service-1,module-1,module-2,x
 |   `- base-service-1,module-1,module-2,log
 |
 `-base-service-1,module-1,module-3
     |  # another service with different modules
     |
     |- base-service-1,module-1,module-3,x
     `- base-service-1,module-1,module-3,log

base-service-2
 |
 |-base-service-2,module-1,module-2
 |   |- base-service-1,module-1,module-2,x
 |   `- base-service-1,module-1,module-2,log
 |
 `-base-service-2,module-3
     |- base-service-1,module-3,x
     `- base-service-1,module-3,log

base-service-3
 |  # there may be no variant, it works as well
 |
 |- base-service-3,x
 `- base-service-3,log

Diffstat:
Mbin/service-build | 32+++++++++++++++++++-------------
Abin/service-bundle | 21+++++++++++++++++++++
Mbin/service-disable | 3++-
Mbin/service-enable | 14+++++++-------
Mbin/service-log | 3+--
Abin/service-save | 9+++++++++
Mbin/service-status | 7+++----
Aconf/service | 8++++++++
Ainit-script/OpenBSD | 10++++++++++
Ainit-script/openbsd | 8++++++++
As6/acme-client/h-o.st/env/DOMAIN | 1+
As6/acme-client/irc.h-o.st/env/DOMAIN | 1+
Ms6/host/glaphyrae/contents | 17++++++-----------
Rs6/httpfile/josuah.net/env/CERTFILE -> s6/httpfile/h-o.st/env/CERTFILE | 0
Rs6/httpfile/josuah.net/env/KEYFILE -> s6/httpfile/h-o.st/env/KEYFILE | 0
15 files changed, 96 insertions(+), 38 deletions(-)

diff --git a/bin/service-build b/bin/service-build @@ -16,30 +16,36 @@ 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 } +if { rm -rf ${sv},x ${sv},log } -ifte { } { if { rm -rf ${sv} ${sv},log } exit 1 } +ifte { } { if { rm -rf ${sv},x ${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} + forx -o 0 x { x ${mod} } importas x x + s6-hiercopy /etc/s6/${base}/${x} ${sv},x } -if { if -t { test $type = bundle } - backtick -i x { sed "s/^#.*//; /^[ \t]*$/ d" ${sv}/contents } +# build bundles recursively +if { + if -t { test ${type} = bundle } + backtick -i x { sed "s/^#.*//; /^[ \t]*$/ d" ${sv},x/contents } importas -s -d "\n" x x - service-build ${x} } -if { if -t { test ${type} = longrun } +# 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-rc/service-log ${sv},log } - if { redirfd -a 1 ${sv}/producer-for echo ${sv},log } - if { redirfd -w 1 ${sv},log/consumer-for echo ${sv} } - if { redirfd -w 1 ${sv},log/env/SERVICE echo ${sv} } + 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/env/SERVICE echo ${sv},x } } -cd ${sv} -if -t { test -e setup } ./setup +# run the setup script +cd ${sv},x +if -t { test -e setup } +./setup diff --git a/bin/service-bundle b/bin/service-bundle @@ -0,0 +1,21 @@ +#!/usr/bin/env execlineb +cd /var/s6 + +forbacktickx -n x { + pipeline { s6-ls . } + pipeline { sed "s/,.*//" } + sort -u +} +importas base x + +if { rm -rf ${base} } +if { mkdir ${base} } +if { + redirfd -w 1 ${base}/type + echo bundle +} +if { + redirfd -w 1 ${base}/contents + elglob -0s x ${base},* + printf "%s\n" ${x} +} diff --git a/bin/service-disable b/bin/service-disable @@ -2,7 +2,8 @@ cd /var/s6 elgetpositionals -P 1 -if { rm -rf ${@} ${@},log } +if { rm -rf ${@},x ${@},log } +if { service-bundle } backtick -n t { s6-clock } importas t t diff --git a/bin/service-enable b/bin/service-enable @@ -3,6 +3,7 @@ elgetpositionals -P 1 cd /var/s6 if { service-build $@ } +if { service-bundle } backtick -n x { s6-clock } importas time x @@ -10,10 +11,9 @@ importas time x if { s6-rc-compile .s6-rc/compiled${time} . } if { s6-rc-update -l /var/s6/.s6-rc/live /var/s6/.s6-rc/compiled${time} } -# bundle all variants of a base service together -forbacktickx -n x { pipeline { s6-ls . } pipeline { sed "s/,.*//" } sort -u } -importas base x - -if -n { test -d /var/s6/${base} } -elglob -0 x ${base},* -s6-rc-bundle -f -l .s6-rc/live add ${base} ${x} +# build a bundle with a service and its logger (if any) +forx x { $@ } +importas sv x +ifthenelse { test -d ${sv},log } + { s6-rc-bundle -f -l .s6-rc/live add ${sv} ${sv},x ${sv},log } + { s6-rc-bundle -f -l .s6-rc/live add ${sv} ${sv},x } diff --git a/bin/service-log b/bin/service-log @@ -3,8 +3,7 @@ elgetpositionals -P 1 backtick x { pipeline { s6-rc -l "/var/s6/.s6-rc/live" list $@ } - pipeline { sed "s/,log$//" } - sort -u + sed -n "s/,log$// p" } importas -ns -d "\n" sv x diff --git a/bin/service-save b/bin/service-save @@ -0,0 +1,9 @@ +#!/usr/bin/env execlineb + +backtick -n x { uname -n } +importas hostname x + +if { mkdir -p /etc/s6/host/${hostname} } +redirfd -w 1 /etc/s6/host/${hostname}/contents +pipeline { s6-ls /var/s6/ } +sed -n "s/,x// p" diff --git a/bin/service-status b/bin/service-status @@ -6,17 +6,16 @@ if { printf "\n" } fdmove -c 2 1 forbacktickx x { pipeline { s6-rc -l /var/s6/.s6-rc/live list $@ } - pipeline { sed "s/,log$//" } - sort -u + sed -n "s/,log$// 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} } +if { s6-svstat /run/s6/${sv},x } if { printf "\n" } if { - backtick -n x { s6-svstat -o pid /run/s6/${sv} } + backtick -n x { s6-svstat -o pid /run/s6/${sv},x } importas x x ptree -- ${x} } diff --git a/conf/service b/conf/service @@ -0,0 +1,8 @@ +#!/bin/sh -e + +cd "$(dirname "$0")" + +case "$(uname)" in +(OpenBSD) cp "../init-script/openbsd" /etc/rc.d/service ;; +(*) echo OS not supported, do it by hand or extend me ;; +esac diff --git a/init-script/OpenBSD b/init-script/OpenBSD @@ -0,0 +1,10 @@ +#!/bin/ksh + +daemon="$(which service-init)" + +. /etc/rc.d/rc.subr + +pexp="$(which service-init)" +rc_reload=NO + +rc_cmd $1 diff --git a/init-script/openbsd b/init-script/openbsd @@ -0,0 +1,8 @@ +#!/usr/bin/env execlineb +elgetpositionals + +ifelse { test $1 = start } { background { service-init } } +ifelse { test $1 = stop } { service-halt } +ifelse { test $1 = restart } { if { $0 stop } $0 start } +ifelse { test $1 = reload } { pkill -HUP service-init } +echo "usage: service {start,stop,restart,reload,check}" diff --git a/s6/acme-client/h-o.st/env/DOMAIN b/s6/acme-client/h-o.st/env/DOMAIN @@ -0,0 +1 @@ +h-o.st diff --git a/s6/acme-client/irc.h-o.st/env/DOMAIN b/s6/acme-client/irc.h-o.st/env/DOMAIN @@ -0,0 +1 @@ +irc.h-o.st diff --git a/s6/host/glaphyrae/contents b/s6/host/glaphyrae/contents @@ -1,13 +1,8 @@ -acme-client,git.josuah.net -acme-client,josuah.net -geomyidae,ipv4,josuah.net -geomyidae,ipv6,josuah.net -git-daemon -ii,tls,irc.freenode.net +ii,tcp,irc.freenode.net +tinydns,h-o.st ii,tls,irc.cyberia.is -ii,tls,irc.epitech.eu -ngircd,tls,josuah.net +httpfile,tcp +httpfile,tls,h-o.st +ii,tls,irc.freenode.net tinysshd -qmail-smtpd,tcp,josuah.net -qmail-smtpd,tls,josuah.net -qmail-send,tls,josuah.net +git-daemon diff --git a/s6/httpfile/josuah.net/env/CERTFILE b/s6/httpfile/h-o.st/env/CERTFILE diff --git a/s6/httpfile/josuah.net/env/KEYFILE b/s6/httpfile/h-o.st/env/KEYFILE