From a2b399246217101277fb8fd8922f2717443e81a1 Mon Sep 17 00:00:00 2001 From: Liam Crilly Date: Mon, 19 Dec 2022 15:03:55 +0000 Subject: Tools: unitc avoid interactive rm(1) invocations. --- tools/unitc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/unitc') diff --git a/tools/unitc b/tools/unitc index 838f7ebf..bf12f111 100755 --- a/tools/unitc +++ b/tools/unitc @@ -161,7 +161,7 @@ if [ $REMOTE -eq 0 ]; then # Cache the discovery for this unit PID (and cleanup any old files) # - rm /tmp/${0##*/}.* 2> /dev/null + rm -f /tmp/${0##*/}.* 2> /dev/null echo UNIT_CTRL=\"${UNIT_CTRL}\" > /tmp/${0##*/}.$PID.env echo ERROR_LOG=${ERROR_LOG} >> /tmp/${0##*/}.$PID.env fi @@ -221,11 +221,11 @@ if [ $CURL_STATUS -ne 0 ]; then echo "${0##*/}: Check that you have permission to access the Unit control socket, or try again with sudo(8)" else echo "${0##*/}: Trying to access $UNIT_CTRL$URI" - cat /tmp/${0##*/}.$$ && rm /tmp/${0##*/}.$$ + cat /tmp/${0##*/}.$$ && rm -f /tmp/${0##*/}.$$ fi exit 4 fi -rm /tmp/${0##*/}.$$ 2> /dev/null +rm -f /tmp/${0##*/}.$$ 2> /dev/null if [ $SHOW_LOG -gt 0 ] && [ $NOLOG -eq 0 ] && [ $QUIET -eq 0 ]; then echo -n "${0##*/}: Waiting for log..." -- cgit From bbeccabe0a40c689466d97570e44829e3c1ddb3b Mon Sep 17 00:00:00 2001 From: Liam Crilly Date: Mon, 27 Feb 2023 14:25:58 +0000 Subject: Tools: improved detection of unitd control socket. Now unitc obtains the path to the unitd binary from information contained in the unitd: main process. If unitd was started with an explicit path then that path will be used to obtain the default control socket, instead of using the unitd binary in $PATH. --- tools/unitc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tools/unitc') diff --git a/tools/unitc b/tools/unitc index bf12f111..71fef314 100755 --- a/tools/unitc +++ b/tools/unitc @@ -43,7 +43,7 @@ while [ $# -gt 0 ]; do ;; *) - if [ -r $1 ]; then + if [ -f $1 ] && [ -r $1 ]; then CONF_FILES+=($1) elif [ "${1:0:1}" = "/" ] || [ "${1:0:4}" = "http" ] && [ "$URI" = "" ]; then URI=$1 @@ -121,9 +121,9 @@ if [ $REMOTE -eq 0 ]; then if [ -r /tmp/${0##*/}.$PID.env ]; then source /tmp/${0##*/}.$PID.env else - # Check we have unitd in $PATH (and all the other tools we will need) + # Check we have all the tools we will need (that we didn't already use) # - MISSING=$(hash unitd curl ps grep tr cut sed tail sleep 2>&1 | cut -f4 -d: | tr -d '\n') + MISSING=$(hash curl tr cut sed tail sleep 2>&1 | cut -f4 -d: | tr -d '\n') if [ "$MISSING" != "" ]; then echo "${0##*/}: ERROR: cannot find$MISSING: please install or add to \$PATH" exit 1 @@ -131,10 +131,10 @@ if [ $REMOTE -eq 0 ]; then # Get control address # - PARAMS=$(ps $PID | grep unitd | cut -f2- -dv | tr '[]' ' ' | cut -f4- -d ' ' | sed -e 's/ --/\n--/g') + PARAMS=$(ps $PID | grep unitd | cut -f2- -dv | tr '[]' ' ' | cut -f3- -d ' ' | sed -e 's/ --/\n--/g') CTRL_ADDR=$(echo "$PARAMS" | grep '\--control' | cut -f2 -d' ') if [ "$CTRL_ADDR" = "" ]; then - CTRL_ADDR=$(unitd --help | grep -A1 '\--control' | tail -1 | cut -f2 -d\") + CTRL_ADDR=$(`echo "$PARAMS" | grep unitd` --help | grep -A1 '\--control' | tail -1 | cut -f2 -d\") fi # Prepare for network or Unix socket addressing -- cgit From c54331fa3d9597ba6bc85e7b7242981f00ed25c2 Mon Sep 17 00:00:00 2001 From: Liam Crilly Date: Tue, 4 Apr 2023 11:29:53 +0100 Subject: Tools: use control socket and log file from running instance. If unitd was started with an explicit path then unitc will use that binary instead of the default PATH to obtain the default control socket and log file locations. --- tools/unitc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/unitc') diff --git a/tools/unitc b/tools/unitc index 71fef314..9973e62d 100755 --- a/tools/unitc +++ b/tools/unitc @@ -134,7 +134,7 @@ if [ $REMOTE -eq 0 ]; then PARAMS=$(ps $PID | grep unitd | cut -f2- -dv | tr '[]' ' ' | cut -f3- -d ' ' | sed -e 's/ --/\n--/g') CTRL_ADDR=$(echo "$PARAMS" | grep '\--control' | cut -f2 -d' ') if [ "$CTRL_ADDR" = "" ]; then - CTRL_ADDR=$(`echo "$PARAMS" | grep unitd` --help | grep -A1 '\--control' | tail -1 | cut -f2 -d\") + CTRL_ADDR=$($(echo "$PARAMS" | grep unitd) --help | grep -A1 '\--control' | tail -1 | cut -f2 -d\") fi # Prepare for network or Unix socket addressing @@ -156,7 +156,7 @@ if [ $REMOTE -eq 0 ]; then # ERROR_LOG=$(echo "$PARAMS" | grep '\--log' | cut -f2 -d' ') if [ "$ERROR_LOG" = "" ]; then - ERROR_LOG=$(unitd --help | grep -A1 '\--log' | tail -1 | cut -f2 -d\") + ERROR_LOG=$($(echo "$PARAMS" | grep unitd) --help | grep -A1 '\--log' | tail -1 | cut -f2 -d\") fi # Cache the discovery for this unit PID (and cleanup any old files) -- cgit