All Downloads are FREE. Search and download functionalities are using the official Maven repository.

r5.2.2.0.source-code.worker.sh Maven / Gradle / Ivy

#!/bin/bash
# Downloads and runs an analyst worker.
# This shell script will undergo variable substitution via the Java MessageFormat class before it is run on newly started
# worker machines. MessageFormat will replace special tokens (consisting of numbers inside curly braces) with
# configuration information specific to the worker being started. These are:
# 0: the URL to grab the worker JAR from
# 1: the AWS log group to use
# 2: the worker configuration to use

# prep the system: install log agent, java
yum -y install awslogs java-1.8.0-openjdk

# first things first: set up logging
LOGFILE=/var/log/analyst-worker.log

echo Starting analyst worker at `date` > $LOGFILE

# make it so that the worker can write to the logfile
chown ec2-user:ec2-user $LOGFILE
chmod 664 $LOGFILE # Log agent needs to read log file

# using a shell "herefile" or "heredoc", pipe the data between < /etc/awslogs/awslogs.conf < /etc/awslogs/awscli.conf < ~ec2-user/worker.conf <> $LOGFILE 2>&1

# Figure out how much memory to give the worker
# figure out how much memory to use
TOTAL_MEM=`grep MemTotal /proc/meminfo | sed 's/[^0-9]//g'`
# 2097152 kb is 2GB, leave that much for the OS
MEM=`echo $TOTAL_MEM - 2097152 | bc`

# Start the worker
# run in ec2-user's home directory, in the subshell
{
    cd ~ec2-user
    sudo -u ec2-user java8 -jar r5.jar worker worker.conf >> $LOGFILE 2>&1

    # If the worker exits or doesn't start, wait a few minutes so that the CloudWatch log agent grabs
    # the logs
    sleep 120
    halt -p
} &




© 2015 - 2024 Weber Informatics LLC | Privacy Policy