Skip to content

Instantly share code, notes, and snippets.

@untergeek
Created March 22, 2023 18:31
Show Gist options
  • Save untergeek/f4f776b901acf4400d9bd8c41c8be3c4 to your computer and use it in GitHub Desktop.
Save untergeek/f4f776b901acf4400d9bd8c41c8be3c4 to your computer and use it in GitHub Desktop.
UDM Pro 2.x redeployer for existing Elastic Agent after fw/sw upgrade removes some files
#!/bin/sh
exec /opt/Elastic/Agent/elastic-agent $@
[Unit]
Description=Elastic Agent is a unified agent to observe, monitor and protect your system.
ConditionFileIsExecutable=/usr/bin/elastic-agent
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/bin/elastic-agent
WorkingDirectory=/opt/Elastic/Agent
Restart=always
RestartSec=120
EnvironmentFile=-/etc/sysconfig/elastic-agent
[Install]
WantedBy=multi-user.target
#!/bin/bash
# Save original execution path
EXECPATH=$(pwd)
# Extract the path for the script
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Navigate to the script, regardless of whether we were there
cd $SCRIPTPATH
BINFILE=elastic-agent
BINPATH=/usr/bin
SVCFILE=elastic-agent.service
SVCPATH=/etc/systemd/system
LNKFILE=/opt/Elastic
LNKPATH=/volume1/Elastic
if [ ! -f "$BINPATH/$BINFILE" ]; then
echo "$BINPATH/$BINFILE not found!"
echo "Copying $BINFILE to $BINPATH..."
cp $BINFILE $BINPATH/
else
echo "$BINPATH/$BINFILE already present."
fi
if [ ! -f "$SVCPATH/$SVCFILE" ]; then
echo "$SVCPATH/$SVCFILE not found!"
echo "Copying $SVCFILE to $SVCPATH..."
cp $SVCFILE $SVCPATH/
else
echo "$SVCPATH/$SVCFILE already present."
fi
if [ ! -L "$LNKFILE" ]; then
echo "Symlink $LNKFILE not found!"
echo "Symlinking $LNKFILE to point to $LNKPATH..."
ln -s $LNKPATH $LNKFILE
else
echo "Symlink $LNKFILE already present."
fi
STATUS=$(OUTPUT=`/bin/systemctl status $SVCFILE`; echo $OUTPUT | awk -F\Active\:\ '{print $2}' | awk '{print $1,$2}')
if [ "$STATUS" != "active (running)" ]; then
echo "Elastic Agent is not running. Restarting..."
/bin/systemctl restart $SVCFILE
else
echo "Elastic Agent is already properly running."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment