Skip to content

Commit 978aae9

Browse files
fix: update linux install to match mac install args (#144)
### Description Update linux install to match mac install args. Also only run the `systemd` setup when `systemd` is available. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
1 parent 780ec50 commit 978aae9

File tree

1 file changed

+64
-14
lines changed

1 file changed

+64
-14
lines changed

scripts/install_linux.sh

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ agent_binary_path="/usr/bin/observe-agent"
66
observeagent_config_dir="/etc/observe-agent"
77
tmp_dir="/tmp/observe-agent"
88

9+
# Parse args
10+
while [ $# -gt 0 ]; do
11+
opt=$1
12+
shift
13+
arg=""
14+
if [[ "$opt" == *"="* ]]; then
15+
arg=$(echo $opt | cut -d'=' -f2)
16+
opt=$(echo $opt | cut -d'=' -f1)
17+
elif [ $# -gt 0 ]; then
18+
arg="$1"
19+
shift
20+
fi
21+
case "$opt" in
22+
--token)
23+
TOKEN="$arg"
24+
;;
25+
--observe_url)
26+
OBSERVE_URL="$arg"
27+
;;
28+
--logs_enabled)
29+
LOGS_ENABLED="$arg"
30+
;;
31+
--metrics_enabled)
32+
METRICS_ENABLED="$arg"
33+
;;
34+
*)
35+
echo "Unknown option: $opt"
36+
exit 1
37+
;;
38+
esac
39+
done
40+
941
# If the observe-agent.yaml file already exists, leave it alone.
1042
# Otherwise we need to know what the collection endpoint and token are.
1143
if [ ! -f "$observeagent_config_dir/observe-agent.yaml" ]; then
@@ -48,26 +80,44 @@ sudo rm -rf $observeagent_config_dir/connections
4880
sudo cp -fR $tmp_dir/connections $observeagent_config_dir/connections
4981
sudo chown -R root:root $observeagent_config_dir
5082

51-
# Set up the systemd service if it doesn't exist already.
52-
if ! systemctl list-unit-files observe-agent.service | grep observe-agent >/dev/null; then
53-
echo "Installing observe-agent.service as a systemd service. This may ask for your password..."
54-
sudo cp -f $tmp_dir/observe-agent.service /etc/systemd/system/observe-agent.service
55-
sudo chown root:root /etc/systemd/system/observe-agent.service
56-
sudo systemctl daemon-reload
57-
sudo systemctl enable observe-agent.service
58-
sudo systemctl start observe-agent
59-
elif systemctl is-active --quiet observe-agent; then
60-
echo "Restarting observe-agent.service. This may ask for your password..."
61-
sudo systemctl restart observe-agent
62-
fi
63-
6483
# Initialize the agent config file if it doesn't exist.
6584
if [ -f "$observeagent_config_dir/observe-agent.yaml" ]; then
6685
echo "Leaving existing observe-agent.yaml in place."
6786
else
6887
echo "Initializing observe-agent.yaml"
69-
sudo $agent_binary_path init-config --token $TOKEN --observe_url $OBSERVE_URL --config_path $observeagent_config_dir/observe-agent.yaml
88+
INIT_FLAGS="--config_path $observeagent_config_dir/observe-agent.yaml --token $TOKEN --observe_url $OBSERVE_URL --host_monitoring::enabled=true"
89+
if [ -n "$LOGS_ENABLED" ]; then
90+
if [[ "${LOGS_ENABLED,,}" == "true" ]]; then
91+
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=true"
92+
else
93+
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=false"
94+
fi
95+
fi
96+
if [ -n "$METRICS_ENABLED" ]; then
97+
if [[ "${METRICS_ENABLED,,}" == "true" ]]; then
98+
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=true"
99+
else
100+
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=false"
101+
fi
102+
fi
103+
sudo $agent_binary_path init-config $INIT_FLAGS
70104
sudo chown root:root $observeagent_config_dir/observe-agent.yaml
71105
fi
72106

107+
# Check if systemd is available.
108+
if [[ -d /run/systemd/system ]]; then
109+
# Set up the systemd service if it doesn't exist already.
110+
if ! systemctl list-unit-files observe-agent.service | grep observe-agent >/dev/null; then
111+
echo "Installing observe-agent.service as a systemd service. This may ask for your password..."
112+
sudo cp -f $tmp_dir/observe-agent.service /etc/systemd/system/observe-agent.service
113+
sudo chown root:root /etc/systemd/system/observe-agent.service
114+
sudo systemctl daemon-reload
115+
sudo systemctl enable observe-agent.service
116+
sudo systemctl start observe-agent
117+
elif systemctl is-active --quiet observe-agent; then
118+
echo "Restarting observe-agent.service. This may ask for your password..."
119+
sudo systemctl restart observe-agent
120+
fi
121+
fi
122+
73123
echo "Observe agent successfully installed to $agent_binary_path with config in $observeagent_config_dir"

0 commit comments

Comments
 (0)