Skip to content

Commit 8134379

Browse files
feat: add linux install script for manual installation support (#137)
### Description Add linux install script for manual installation support. This can install from a local zip or from our release downloads. Examples: ``` $ bash ./scripts/install_linux.sh Downloading latest release from GitHub % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 34.0M 100 34.0M 0 0 42.6M 0 --:--:-- --:--:-- --:--:-- 42.6M Creating system install folders. This may ask for your password... Leaving existing observe-agent.yaml in place. Observe agent successfully installed to /etc/observe-agent $ observe-agent version Using config file: /etc/observe-agent/observe-agent.yaml observe-agent version: 1.4.0 $ ZIP_DIR=dist/linux_amd64_v1/observe-agent_Linux_x86_64.tar.gz bash ./scripts/install_linux.sh Installing from provided zip file: dist/linux_amd64_v1/observe-agent_Linux_x86_64.tar.gz Creating system install folders. This may ask for your password... Leaving existing observe-agent.yaml in place. Observe agent successfully installed to /etc/observe-agent $ observe-agent version observe-agent version: 1.4.0-SNAPSHOT-48bafce6 observe-agent config file: /etc/observe-agent/observe-agent.yaml ``` ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
1 parent b33a3e8 commit 8134379

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/install_linux.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
agent_binary_path="/usr/bin/observe-agent"
6+
observeagent_config_dir="/etc/observe-agent"
7+
tmp_dir="/tmp/observe-agent"
8+
9+
# If the observe-agent.yaml file already exists, leave it alone.
10+
# Otherwise we need to know what the collection endpoint and token are.
11+
if [ ! -f "$observeagent_config_dir/observe-agent.yaml" ]; then
12+
if [ -z "$OBSERVE_URL" ]; then
13+
echo "OBSERVE_URL env var is not set"
14+
exit 1
15+
fi
16+
17+
if [ -z "$TOKEN" ]; then
18+
echo "TOKEN env var is not set"
19+
exit 1
20+
fi
21+
fi
22+
23+
# If the zip file is not provided, download the latest release from GitHub.
24+
if [ -z "$ZIP_DIR" ]; then
25+
echo "Downloading latest release from GitHub..."
26+
curl -s -L -o /tmp/observe-agent.tar.gz https://github.com/observeinc/observe-agent/releases/latest/download/observe-agent_Linux_$(arch).tar.gz
27+
ZIP_DIR="/tmp/observe-agent.tar.gz"
28+
else
29+
echo "Installing from provided zip file: $ZIP_DIR"
30+
fi
31+
32+
# Set up the temp dir and extract files.
33+
rm -rf $tmp_dir
34+
mkdir -p $tmp_dir
35+
tar -xzf $ZIP_DIR -C $tmp_dir
36+
37+
# Create the needed directories.
38+
echo "Creating system install folders. This may ask for your password..."
39+
sudo mkdir -p $observeagent_config_dir /var/lib/observe-agent/filestorage
40+
sudo chmod +rw /var/lib/observe-agent/filestorage
41+
42+
# Move the binary to the proper path.
43+
cp -f $tmp_dir/observe-agent $agent_binary_path
44+
45+
# Copy all config files to the proper dir.
46+
sudo cp -f $tmp_dir/otel-collector.yaml $observeagent_config_dir/otel-collector.yaml
47+
sudo rm -rf $observeagent_config_dir/connections
48+
sudo cp -fR $tmp_dir/connections $observeagent_config_dir/connections
49+
sudo chown -R root:root $observeagent_config_dir
50+
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+
64+
# Initialize the agent config file if it doesn't exist.
65+
if [ -f "$observeagent_config_dir/observe-agent.yaml" ]; then
66+
echo "Leaving existing observe-agent.yaml in place."
67+
else
68+
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
70+
sudo chown root:root $observeagent_config_dir/observe-agent.yaml
71+
fi
72+
73+
echo "Observe agent successfully installed to $agent_binary_path with config in $observeagent_config_dir"

0 commit comments

Comments
 (0)