#cloud-config
repo_update: true
repo_upgrade: critical

packages:
  - screen
  - htop

# When testing load generation in the 1,000,000+ range, this configures a web server on
# the load generator, keeping I/O local and thus cheap to test. (Must also start nginx as
# a service, see below.)
#  - nginx

users:
  - default
  - name: engine
    sudo: ALL=(ALL) NOPASSWD:ALL
    gecos: Web Performance Load Engine

runcmd:
 - wget --tries 3 '$INSTALLER_URL' --output-document /home/engine/load-engine.tar.gz
 - mkdir -p /home/engine/.ssh
 - cp /home/ec2-user/.ssh/authorized_keys /home/engine/.ssh/authorized_keys
 - tar -C /home/engine/ -xzf /home/engine/load-engine.tar.gz --strip 1
 # Note: set-memory.sh is no longer needed - Maven assembly now excludes wrong architecture memory config
 - printf '#!/bin/sh\nkillall java; cd; screen -dmS cloudengine ./Start --angel\n' >> /home/engine/cloud-restart.sh
 - chown engine:engine -R /home/engine
 - chmod u+rw -R /home/engine
 - chmod go-wx -R /home/engine
 - chmod go-rwx -R /home/engine/.ssh
 - chmod u+x /home/engine/cloud-restart.sh
 - chmod u+x /home/engine/bin/*.sh
 - /home/engine/bin/set-autoshutdown.sh
# Used for testing large number of load generators
# - [ service, nginx, start ]
 - printf 'engine hard nofile 200000\n'                       >> /etc/security/limits.conf
 - printf 'engine soft nofile 200000\n'                       >> /etc/security/limits.conf
 - printf 'engine hard nproc unlimited\n'                     >> /etc/security/limits.conf
 - printf 'engine soft nproc unlimited\n'                     >> /etc/security/limits.conf
 - printf 'net.ipv4.tcp_tw_recycle=1\n'                       >> /etc/sysctl.conf
 - printf 'net.ipv4.ip_local_port_range = 1025 65535\n'       >> /etc/sysctl.conf
 - printf 'su -l engine -c /home/engine/cloud-restart.sh &\n' >> /etc/rc.d/rc.local
 - su -l engine -c /home/engine/cloud-restart.sh
