Skip to content

Commit c2de454

Browse files
committed
more fixes
1 parent 1a7220e commit c2de454

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

extensions/network-namespace/network-namespace-wrapper.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,20 @@
7878

7979
set -e
8080

81-
LOG_FILE="/var/log/cloudstack/network-namespace.log"
82-
STATE_DIR="/var/lib/cloudstack/network-namespace"
81+
# ---------------------------------------------------------------------------
82+
# Derive log path from this wrapper's own directory name so that each
83+
# renamed deployment writes to its own log file.
84+
# /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
85+
# → /var/log/cloudstack/extensions/<name>/<name>.log
86+
# ---------------------------------------------------------------------------
87+
_WRAPPER_SELF="$(readlink -f "$0" 2>/dev/null \
88+
|| realpath "$0" 2>/dev/null \
89+
|| echo "$0")"
90+
_WRAPPER_EXT_DIR="$(basename "$(dirname "${_WRAPPER_SELF}")")"
91+
LOG_FILE="/var/log/cloudstack/extensions/${_WRAPPER_EXT_DIR}/${_WRAPPER_EXT_DIR}.log"
92+
mkdir -p "$(dirname "${LOG_FILE}")" 2>/dev/null || true
93+
94+
STATE_DIR="/var/lib/cloudstack/${_WRAPPER_EXT_DIR}"
8395

8496
# ---------------------------------------------------------------------------
8597
# JSON helpers (no jq dependency)

extensions/network-namespace/network-namespace.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,33 @@ DEFAULT_SSH_PORT=22
7979
DEFAULT_SSH_USER=root
8080

8181
# ---------------------------------------------------------------------------
82-
# The KVM wrapper script is deployed to the **same path** as this entry-point
83-
# on the management server. Resolve $0 to an absolute path so that the
84-
# remote SSH call uses the correct location regardless of how this script was
85-
# invoked (relative path, symlink, etc.).
82+
# Resolve this entry-point's absolute path so we can derive both the KVM
83+
# wrapper path and the log file name from the extension directory name.
84+
#
85+
# Layout:
86+
# management server: /usr/share/cloudstack-management/extensions/<name>/<name>.sh
87+
# KVM host (wrapper): /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
88+
#
89+
# _EXT_DIR_NAME is the basename of the directory containing this script,
90+
# which equals the extension name assigned by CloudStack (e.g.
91+
# "extnet-isolated-gk3yys"). Both the wrapper path and the log file are
92+
# derived from it so that renamed deployments work automatically.
8693
#
8794
# Callers may still override the remote path via CS_NET_SCRIPT_PATH:
8895
# CS_NET_SCRIPT_PATH=/custom/path/wrapper.sh network-namespace.sh <cmd> ...
8996
# ---------------------------------------------------------------------------
9097
_SELF="$(readlink -f "$0" 2>/dev/null \
9198
|| realpath "$0" 2>/dev/null \
9299
|| echo "$0")"
93-
DEFAULT_SCRIPT_PATH="${_SELF}"
94-
95-
# Derive the log file name from this script's own basename so that a renamed
96-
# deployment (e.g. "my-extension.sh") writes to its own log file instead of
97-
# a hardcoded "network-namespace.log".
98100
_SCRIPT_BASENAME="$(basename "${_SELF}" .sh)"
99-
LOG_FILE="/var/log/cloudstack/management/${_SCRIPT_BASENAME}.log"
101+
_EXT_DIR_NAME="$(basename "$(dirname "${_SELF}")")"
102+
103+
# Remote wrapper path on each KVM host.
104+
DEFAULT_SCRIPT_PATH="/etc/cloudstack/extensions/${_EXT_DIR_NAME}/${_SCRIPT_BASENAME}-wrapper.sh"
105+
106+
# Log file — under /var/log/cloudstack/extensions/ named after the extension.
107+
LOG_FILE="/var/log/cloudstack/extensions/${_EXT_DIR_NAME}.log"
108+
mkdir -p "$(dirname "${LOG_FILE}")" 2>/dev/null || true
100109
TMPDIR_BASE=/tmp
101110

102111
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)