Created
September 9, 2020 12:06
-
-
Save Profpatsch/a0a0664a99737de3e9272aaa82b50a8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs }: | |
{ service-dir }: | |
let sd = pkgs.lib.escapeShellArg service-dir; | |
in pkgs.writers.writeDash "service" '' | |
set -e | |
CMD=''${1:?please specify command as first argument} | |
case "$CMD" in | |
# svscan is put in the background, | |
# afterwards services can be started and stopped | |
init) | |
${pkgs.s6}/bin/s6-svscan ${sd} & | |
echo "started service supervisor" >&2 | |
exit 0 | |
;; | |
# stop the service manager and terminate services | |
quit) | |
${pkgs.s6}/bin/s6-svscanctl -t ${sd} | |
echo "stopped service supervisor and services" >&2 | |
exit 0 | |
;; | |
esac | |
WHAT=''${2:?please specify which service as second argument; "all" is everything} | |
ALL="docker hoogle server forest" | |
case "$CMD" in | |
up|start) | |
case "$WHAT" in | |
all) | |
echo "starting services: $ALL" >&2 | |
for s in $ALL; do | |
${pkgs.s6}/bin/s6-svc -u ${sd}/"$s" | |
done | |
;; | |
*) ${pkgs.s6}/bin/s6-svc -u ${sd}/"$WHAT" ;; | |
esac | |
;; | |
down|stop) | |
case "$WHAT" in | |
all) | |
echo "stopping services: $ALL" >&2 | |
for s in $ALL; do | |
${pkgs.s6}/bin/s6-svc -d ${sd}/"$s" | |
done | |
;; | |
*) ${pkgs.s6}/bin/s6-svc -d ${sd}/"$WHAT" ;; | |
esac | |
;; | |
restart) | |
case "$WHAT" in | |
all) echo "restart not implemented for \"all\"" >&2 ;; | |
*) ${pkgs.s6}/bin/s6-svc -r ${sd}/"$WHAT" ;; | |
esac | |
;; | |
*) echo "don’t know command $CMD" >&2 | |
;; | |
esac | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment