Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update linux install to match mac install args #144

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 64 additions & 14 deletions scripts/install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ agent_binary_path="/usr/bin/observe-agent"
observeagent_config_dir="/etc/observe-agent"
tmp_dir="/tmp/observe-agent"

# Parse args
while [ $# -gt 0 ]; do
opt=$1
shift
arg=""
if [[ "$opt" == *"="* ]]; then
arg=$(echo $opt | cut -d'=' -f2)
opt=$(echo $opt | cut -d'=' -f1)
elif [ $# -gt 0 ]; then
arg="$1"
shift
fi
case "$opt" in
--token)
TOKEN="$arg"
;;
--observe_url)
OBSERVE_URL="$arg"
;;
--logs_enabled)
LOGS_ENABLED="$arg"
;;
--metrics_enabled)
METRICS_ENABLED="$arg"
;;
*)
echo "Unknown option: $opt"
exit 1
;;
esac
done

# If the observe-agent.yaml file already exists, leave it alone.
# Otherwise we need to know what the collection endpoint and token are.
if [ ! -f "$observeagent_config_dir/observe-agent.yaml" ]; then
Expand Down Expand Up @@ -48,26 +80,44 @@ sudo rm -rf $observeagent_config_dir/connections
sudo cp -fR $tmp_dir/connections $observeagent_config_dir/connections
sudo chown -R root:root $observeagent_config_dir

# Set up the systemd service if it doesn't exist already.
if ! systemctl list-unit-files observe-agent.service | grep observe-agent >/dev/null; then
echo "Installing observe-agent.service as a systemd service. This may ask for your password..."
sudo cp -f $tmp_dir/observe-agent.service /etc/systemd/system/observe-agent.service
sudo chown root:root /etc/systemd/system/observe-agent.service
sudo systemctl daemon-reload
sudo systemctl enable observe-agent.service
sudo systemctl start observe-agent
elif systemctl is-active --quiet observe-agent; then
echo "Restarting observe-agent.service. This may ask for your password..."
sudo systemctl restart observe-agent
fi

# Initialize the agent config file if it doesn't exist.
if [ -f "$observeagent_config_dir/observe-agent.yaml" ]; then
echo "Leaving existing observe-agent.yaml in place."
else
echo "Initializing observe-agent.yaml"
sudo $agent_binary_path init-config --token $TOKEN --observe_url $OBSERVE_URL --config_path $observeagent_config_dir/observe-agent.yaml
INIT_FLAGS="--config_path $observeagent_config_dir/observe-agent.yaml --token $TOKEN --observe_url $OBSERVE_URL --host_monitoring::enabled=true"
if [ -n "$LOGS_ENABLED" ]; then
if [[ "${LOGS_ENABLED,,}" == "true" ]]; then
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=true"
else
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=false"
fi
fi
if [ -n "$METRICS_ENABLED" ]; then
if [[ "${METRICS_ENABLED,,}" == "true" ]]; then
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=true"
else
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=false"
fi
fi
sudo $agent_binary_path init-config $INIT_FLAGS
sudo chown root:root $observeagent_config_dir/observe-agent.yaml
fi

# Check if systemd is available.
if [[ -d /run/systemd/system ]]; then
# Set up the systemd service if it doesn't exist already.
if ! systemctl list-unit-files observe-agent.service | grep observe-agent >/dev/null; then
echo "Installing observe-agent.service as a systemd service. This may ask for your password..."
sudo cp -f $tmp_dir/observe-agent.service /etc/systemd/system/observe-agent.service
sudo chown root:root /etc/systemd/system/observe-agent.service
sudo systemctl daemon-reload
sudo systemctl enable observe-agent.service
sudo systemctl start observe-agent
elif systemctl is-active --quiet observe-agent; then
echo "Restarting observe-agent.service. This may ask for your password..."
sudo systemctl restart observe-agent
fi
fi

echo "Observe agent successfully installed to $agent_binary_path with config in $observeagent_config_dir"
Loading