diff options
author | Alejandro Colomar <alx@nginx.com> | 2023-06-06 16:19:04 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@nginx.com> | 2023-06-27 17:45:49 +0200 |
commit | d73526d27ca296400fa8f08aa0a23b8ea3ab7a15 (patch) | |
tree | 81778d1eac14ab8e785ccb8c1fbeb80e33a9d459 /tools | |
parent | 2f46870a3f799ebb3a23e23b02a9dbee3a33ff46 (diff) | |
download | unit-d73526d27ca296400fa8f08aa0a23b8ea3ab7a15.tar.gz unit-d73526d27ca296400fa8f08aa0a23b8ea3ab7a15.tar.bz2 |
Tools: setup-unit: restart: added -l and -s flags.
Add flags for cleaning the log file and state dir.
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/setup-unit | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tools/setup-unit b/tools/setup-unit index 5baa5467..d2cb127c 100755 --- a/tools/setup-unit +++ b/tools/setup-unit @@ -84,7 +84,7 @@ SYNOPSIS ├── os-probe [-h] ├── ps [-h] [-t TYPE] ├── repo-config [-hn] [PKG-MANAGER OS-NAME OS-VERSION] - ├── restart [-h] + ├── restart [-hls] ├── sock [-h] SUBCOMMAND [ARGS] │ ├── filter [-chs] │ └── find [-h] @@ -1224,7 +1224,7 @@ help_unit_restart() { cat <<__EOF__ ; SYNOPSIS - $0 restart [-h] + $0 restart [-hls] DESCRIPTION Restart all running unitd(8) instances. @@ -1233,6 +1233,17 @@ OPTIONS -h, --help Print this help. + -l, --log + Reset log file. + + -s, --statedir + Reset \$statedir. + +CAVEATS + This command will ask for confirmation before removing + directories; please review those prompts with care, as unknown + bugs in the command may attempt to wipe your file system. + __EOF__ } @@ -1245,6 +1256,12 @@ unit_restart() help_unit_restart; exit 0; ;; + -l | --log) + local log_flag='yes'; + ;; + -s | --statedir) + local state_flag='yes'; + ;; -*) err "restart: $1: Unknown option."; ;; @@ -1261,6 +1278,33 @@ unit_restart() printf '%s\n' "$cmds" \ | while read -r cmd; do + if test -v log_flag; then + ( + echo "$cmd" \ + | grep '\--log' \ + | sed 's/.*--log \+\([^ ]\+\).*/\1/' \ + || eval $cmd --help \ + | grep -A1 '\--log FILE' \ + | grep 'default:' \ + | sed 's/.*"\(.*\)".*/\1/'; + ) \ + | xargs rm -f; + fi; + + if test -v state_flag; then + ( + echo "$cmd" \ + | grep '\--statedir' \ + | sed 's/.*--statedir \+\([^ ]\+\).*/\1/' \ + || eval $cmd --help \ + | grep -A1 '\--statedir DIR' \ + | grep 'default:' \ + | sed 's/.*"\(.*\)".*/\1/'; + ) \ + | xargs -I {} find {} -mindepth 1 -maxdepth 1 \ + | xargs rm -rfi; + fi; + eval $cmd; done; } |