#!/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" # SUSEAGENT_USER=DISTDIR=/opt/avantra
SERVICE_NAME=avantra-agent
## -- install javasudo $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_VERSIONAfter=network.target[Service]ExecStart=$DISTDIR/agent/rc.agent startExecStop=$DISTDIR/agent/rc.agent stopUser=$AGENT_USERKillMode=processType=forkingPIDFile=$DISTDIR/agent/log/agent.pid[Install]WantedBy=multi-user.targetENDSVCFILE## -- 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_NAMEENDSUDOERSFILEsudo 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)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.