From 2f46870a3f799ebb3a23e23b02a9dbee3a33ff46 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 6 Jun 2023 14:55:14 +0200 Subject: [PATCH] Tools: setup-unit: added restart command. It restarts all running unitd instances. This is useful when recompiling unitd often, so that the latest build is running, without having to manually kill unitd instances and re-run with the same exact command line every time. Reviewed-by: Andrew Clayton Signed-off-by: Alejandro Colomar --- tools/setup-unit | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tools/setup-unit b/tools/setup-unit index c95d7b35..5baa5467 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -84,6 +84,7 @@ SYNOPSIS ├── os-probe [-h] ├── ps [-h] [-t TYPE] ├── repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] + ├── restart [-h] ├── sock [-h] SUBCOMMAND [ARGS] │   ├── filter [-chs] │   └── find [-h] @@ -1219,6 +1220,52 @@ __EOF__"; } +help_unit_restart() +{ + cat <<__EOF__ ; +SYNOPSIS + $0 restart [-h] + +DESCRIPTION + Restart all running unitd(8) instances. + +OPTIONS + -h, --help + Print this help. + +__EOF__ +} + + +unit_restart() +{ + while test $# -ge 1; do + case "$1" in + -h | --help) + help_unit_restart; + exit 0; + ;; + -*) + err "restart: $1: Unknown option."; + ;; + *) + err "restart: $1: Unknown argument."; + ;; + esac; + shift; + done; + + local cmds="$(unit_cmd)"; + + pkill -e unitd; + + printf '%s\n' "$cmds" \ + | while read -r cmd; do + eval $cmd; + done; +} + + help_unit_sock() { cat <<__EOF__ ; @@ -1478,6 +1525,10 @@ repo-config) shift; unit_repo_config $@; ;; +restart) + shift; + unit_restart $@; + ;; sock) shift; unit_sock $@;