|
| 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