Last active
June 11, 2019 09:59
-
-
Save foospidy/20aa80b7cfa454424b5755d0aa466dfd to your computer and use it in GitHub Desktop.
Installs multiple service instances of the sigsci-agent (tcp listener only).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sigsci-agent-install-multi.sh | |
# Installs multiple service instances of the sigsci-agent (tcp listener only). | |
# Note: this does not modify the default sigsci-agent installation. | |
# | |
# This script takes two arguments: | |
# The first argument (required) specifies how many new service instances to create. | |
# The second argument (optional) sepcifies what port the first service instance | |
# should listen on. It will automaticly increment the port number for each new instance. | |
# | |
# Usage: | |
# ./sigsci-agent-install-multi.sh <number of service instances> [start port] | |
if [ -z $1 ]; | |
then | |
echo "You must specify how many agents you want to setup, 1 through 9." | |
exit | |
fi | |
if (( $1 > 9 )); | |
then | |
echo "For sanity, a max of 9 new instances is enforced." | |
echo "To override, modify this script." | |
exit | |
fi | |
exit | |
if [ -z $2 ]; | |
then | |
port=10000 | |
else | |
port=$2 | |
fi | |
if [ ! -f /usr/sbin/sigsci-agent ]; | |
then | |
echo "Agent 0 is not installed. Please install the sigsci-agent before running." | |
exit | |
fi | |
echo "Setting up $1 agent(s)..." | |
for ((i = 1; i <= $1; i++)); | |
do | |
echo "- Agent $i..." | |
# Create required files | |
config_file=/etc/sigsci/agent-$i.conf | |
touch $config_file | |
service_file=/lib/systemd/system/sigsci-agent-$i.service | |
touch $service_file | |
# Generate config file content | |
echo "-- Generating $config_file..." | |
echo "accesskeyid = \"changeme\"" > $config_file | |
echo "secretaccesskey = \"changeme\"" >> $config_file | |
echo "server-hostname = \"${HOSTNAME}-${port}\"" >> $config_file | |
echo "rpc-address = \"tcp://0.0.0.0:$port\"" >> $config_file | |
# Generate service file content | |
echo "-- Generating $service_file..." | |
echo "[Unit]" > $service_file | |
echo "Description=Signal Sciences Agent $i" >> $service_file | |
echo "After=network.target remote-fs.target nss-lookup.target" >> $service_file | |
echo "" >> $service_file | |
echo "[Service]" >> $service_file | |
echo "EnvironmentFile=/etc/default/sigsci-agent" >> $service_file | |
echo "ExecStart=/usr/sbin/sigsci-agent --config /etc/sigsci/agent-$i.conf" >> $service_file | |
echo "Restart=on-abort" >> $service_file | |
echo "TimeoutSec=15" >> $service_file | |
echo "" >> $service_file | |
echo "[Install]" >> $service_file | |
echo "WantedBy=multi-user.target" >> $service_file | |
# Enable sigsci-agent to start on boot | |
echo "Enabling sigsci-agent-$i on boot..." | |
systemctl enable sigsci-agent-$i | |
echo "Complete!" | |
((port++)) | |
done; | |
# Reload all units | |
systemctl daemon-reload | |
echo "Finished installing $1 agent(s). Remember to update each agent config file in /etc/sigsci" | |
ls /etc/sigsci |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment