Snippets

Avantra Dev Team Install Avantra Agent via SSH

Created by Heiko Mannherz last modified
#!/bin/sh -xe
# -----------------------------------------------------------
# Change the following variables according to your needs
#
# MASTERHOST    is the Avantra server's dns name or IP address
# AGENT_VERSION is the version of an Avantra Agent uploaded
#               to the UI
# JAVA_INSTALL  is the command to install Java 8. Adapt to
#               your distro
# AGENT_USER    is the OS user on the target system that runs
#               the Avantra agent, is accessible by SSH, and
#               can run sudo without a password.
# DISTDIR       is the directory the agent is going to be
#               installed to
# SERVICE_NAME  is the name of the service in systemd
#
# Run as:
# ssh <AGENT_USER>@<TARGET> 'sh -s' < deploy-avantra-agent.sh
# -----------------------------------------------------------
MASTERHOST=
AGENT_VERSION=
JAVA_INSTALL="yum install -y java-1.8.0-openjdk" # Red Hat, CentOS, Fedora
# JAVA_INSTALL="zypper install -y java-1_8_0-openjdk" # SUSE
AGENT_USER=
DISTDIR=/opt/avantra
SERVICE_NAME=avantra-agent
## -- install java
sudo $JAVA_INSTALL
## -- install agent --
sudo mkdir -p "$DISTDIR" \
    && sudo chown -R $AGENT_USER: "$DISTDIR" \
    && cd "$DISTDIR" \
    && sudo -u $AGENT_USER curl -s http://$MASTERHOST:9050/AgentUpdate/agent-$AGENT_VERSION.bin -o agent-$AGENT_VERSION.bin \
    && sudo -u $AGENT_USER chmod 755 ./agent-$AGENT_VERSION.bin \
    && sudo -u $AGENT_USER ./agent-$AGENT_VERSION.bin -- --silent --start=no
## -- create service file for systemd --
sudo cat <<ENDSVCFILE | sudo tee "/etc/systemd/system/$SERVICE_NAME.service" > /dev/null
[Unit]
Description=Avantra Agent $AGENT_VERSION
After=network.target

[Service]
ExecStart=$DISTDIR/agent/rc.agent start
ExecStop=$DISTDIR/agent/rc.agent stop
User=$AGENT_USER
KillMode=process
Type=forking
PIDFile=$DISTDIR/agent/log/agent.pid

[Install]
WantedBy=multi-user.target
ENDSVCFILE
## -- allow $AGENT_USER to sudo systemctl --
sudo cat <<ENDSUDOERSFILE | sudo tee "/etc/sudoers.d/$AGENT_USER" > /dev/null
$AGENT_USER ALL=NOPASSWD: /usr/bin/systemctl start $SERVICE_NAME
$AGENT_USER ALL=NOPASSWD: /usr/bin/systemctl stop $SERVICE_NAME
$AGENT_USER ALL=NOPASSWD: /usr/bin/systemctl restart $SERVICE_NAME
ENDSUDOERSFILE
sudo visudo -cf "/etc/sudoers.d/$AGENT_USER"
## -- enable service --
sudo systemctl enable "/etc/systemd/system/$SERVICE_NAME.service" \
    && sudo systemctl start $SERVICE_NAME

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.