From 374e45f2c36dd65c1edd6922129439de06593e4c Mon Sep 17 00:00:00 2001 From: Srinivas Baride Date: Fri, 24 Feb 2023 18:50:33 +0530 Subject: [PATCH] Added status command to the script --- scripts/runner.sh | 23 ++++++++++++++++++++++- services/v2ray/types/config.go | 2 +- services/wireguard/types/config.go | 2 +- types/config.go | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/runner.sh b/scripts/runner.sh index 07721d6..898525d 100755 --- a/scripts/runner.sh +++ b/scripts/runner.sh @@ -20,8 +20,9 @@ function help { echo " attach Attach to the already running node" echo " help Print the help message" echo " init Initialize the configuration" - echo " setup Install the dependencies and setup the requirements" + echo " setup Install the dependencies and set up the requirements" echo " start Start the node" + echo " status Display the node's status along with the last 20 lines of the log" echo " stop Stop the node" echo " remove Remove the node container" echo " restart Restart the node" @@ -494,6 +495,22 @@ function start { fi } +function status { + id=$(docker ps --all --filter name="${CONTAINER_NAME}" --quiet) + if [[ -n "${id}" ]]; then + running=$(docker container inspect --format "{{ .State.Running }}" "${CONTAINER_NAME}") + if [[ "${running}" == "true" ]]; then + echo "Node is running..." + else + exit_code=$(docker container inspect --format "{{ .State.ExitCode }}" "${CONTAINER_NAME}") + echo "Node is not running and has exited with code ${exit_code}" + fi + docker logs --details --tail 20 "${CONTAINER_NAME}" + else + echo "Error: node container does not exist" + fi +} + function stop { id=$(docker ps --all --filter name="${CONTAINER_NAME}" --quiet) if [[ -n "${id}" ]]; then @@ -566,6 +583,10 @@ case "${1}" in shift start "${@}" ;; + "status") + shift + status "${@}" + ;; "stop") shift stop "${@}" diff --git a/services/v2ray/types/config.go b/services/v2ray/types/config.go index 8f18c4d..162abb5 100644 --- a/services/v2ray/types/config.go +++ b/services/v2ray/types/config.go @@ -94,7 +94,7 @@ func (c *Config) SaveToPath(path string) error { return err } - return os.WriteFile(path, buf.Bytes(), 0666) + return os.WriteFile(path, buf.Bytes(), 0644) } func (c *Config) String() string { diff --git a/services/wireguard/types/config.go b/services/wireguard/types/config.go index 97b91a4..d0b0a2c 100644 --- a/services/wireguard/types/config.go +++ b/services/wireguard/types/config.go @@ -80,7 +80,7 @@ func (c *Config) SaveToPath(path string) error { return err } - return os.WriteFile(path, buffer.Bytes(), 0666) + return os.WriteFile(path, buffer.Bytes(), 0644) } func (c *Config) String() string { diff --git a/types/config.go b/types/config.go index 96dc10e..249768b 100644 --- a/types/config.go +++ b/types/config.go @@ -403,7 +403,7 @@ func (c *Config) SaveToPath(path string) error { return err } - return os.WriteFile(path, buffer.Bytes(), 0666) + return os.WriteFile(path, buffer.Bytes(), 0644) } func (c *Config) String() string {