From f3ab99b5d9e603a7bc4e8e3c58dcd968be632552 Mon Sep 17 00:00:00 2001 From: Darko Draskovic Date: Fri, 18 Aug 2023 13:58:04 +0200 Subject: [PATCH] Add configure-agent.sh script Signed-off-by: Darko Draskovic --- systemd/cocos-agent.service | 7 +------ systemd/configure-agent.sh | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100755 systemd/configure-agent.sh diff --git a/systemd/cocos-agent.service b/systemd/cocos-agent.service index 92fb0a4..5b0ca80 100644 --- a/systemd/cocos-agent.service +++ b/systemd/cocos-agent.service @@ -6,13 +6,8 @@ After=network.target StandardOutput=file:/var/log/cocos/agent.stdout StandardError=file:/var/log/cocos/agent.stderr -Environment=NETWORK_INTERFACE=enp0s3 -Environment=AGENT_GRPC_ADDR=10.0.2.15:7002 -Environment=AGENT_LOG_LEVEL=info - -ExecStartPre=ip link set dev $NETWORK_INTERFACE up -ExecStartPre=dhclient $NETWORK_INTERFACE ExecStartPre=mkdir -p /var/log/cocos +ExecStartPre=source /cocos/configure-agent.sh ExecStart=/cocos/agent diff --git a/systemd/configure-agent.sh b/systemd/configure-agent.sh new file mode 100755 index 0000000..9d71e3f --- /dev/null +++ b/systemd/configure-agent.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Determine the network interface's name +NETWORK_INTERFACE=$(ip addr | awk '/^2: /{sub(/:/, "", $2); print $2}') + +# Determine the IP address of the network interface +AGENT_GRPC_ADDR=$(ip addr show dev "$NETWORK_INTERFACE" | awk '/inet / { print $2 }' | cut -d/ -f1):7002 + +# Set the environment variables +export NETWORK_INTERFACE +export AGENT_GRPC_ADDR