diff --git a/modules/install-nomad/install-nomad b/modules/install-nomad/install-nomad index 5768fe5..e40666e 100755 --- a/modules/install-nomad/install-nomad +++ b/modules/install-nomad/install-nomad @@ -3,7 +3,7 @@ # operating systems: # # 1. Ubuntu 16.04 -# 1. Amazon Linux +# 1. Amazon Linux 2 set -e @@ -13,16 +13,13 @@ readonly DEFAULT_NOMAD_USER="nomad" readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly SYSTEM_BIN_DIR="/usr/local/bin" -readonly SUPERVISOR_DIR="/etc/supervisor" -readonly SUPERVISOR_CONF_DIR="$SUPERVISOR_DIR/conf.d" - readonly SCRIPT_NAME="$(basename "$0")" function print_usage { echo echo "Usage: install-nomad [OPTIONS]" echo - echo "This script can be used to install Nomad and its dependencies. This script has been tested with Ubuntu 16.04 and Amazon Linux." + echo "This script can be used to install Nomad and its dependencies. This script has been tested with Ubuntu 16.04 and Amazon Linux 2." echo echo "Options:" echo @@ -68,41 +65,6 @@ function assert_not_empty { fi } -# Install steps are based on: http://unix.stackexchange.com/a/291098/215969 -function install_supervisord_debian { - sudo apt-get install -y supervisor - sudo update-rc.d supervisor defaults - - create_supervisor_config - sudo systemctl enable supervisor -} - -# Install steps are based on: http://stackoverflow.com/a/31576473/483528 -function install_supervisord_amazon_linux { - sudo pip install supervisor - - # On Amazon Linux, /usr/local/bin is not in PATH for the root user, so we add symlinks to /usr/bin, which is in PATH - if [[ ! -f "/usr/bin/supervisorctl" ]]; then - sudo ln -s /usr/local/bin/supervisorctl /usr/bin/supervisorctl - fi - if [[ ! -f "/usr/bin/supervisord" ]]; then - sudo ln -s /usr/local/bin/supervisord /usr/bin/supervisord - fi - - sudo cp "$SCRIPT_DIR/supervisor-initd-script.sh" "/etc/init.d/supervisor" - sudo chmod a+x /etc/init.d/supervisor - sudo mkdir -p /var/log/supervisor - - create_supervisor_config - sudo chkconfig --add supervisor - sudo chkconfig supervisor on -} - -function create_supervisor_config { - sudo mkdir -p "$SUPERVISOR_CONF_DIR" - sudo cp "$SCRIPT_DIR/supervisord.conf" "$SUPERVISOR_DIR/supervisord.conf" -} - function has_yum { [ -n "$(command -v yum)" ] } @@ -117,11 +79,9 @@ function install_dependencies { if $(has_apt_get); then sudo apt-get update -y sudo apt-get install -y awscli curl unzip jq - install_supervisord_debian elif $(has_yum); then sudo yum update -y sudo yum install -y aws curl unzip jq - install_supervisord_amazon_linux else log_error "Could not find apt-get or yum. Cannot install dependencies on this OS." exit 1 diff --git a/modules/install-nomad/supervisor-initd-script.sh b/modules/install-nomad/supervisor-initd-script.sh deleted file mode 100755 index 171b916..0000000 --- a/modules/install-nomad/supervisor-initd-script.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash -# -# supervisord Startup script for the Supervisor process control system -# -# Author: Mike McGrath (based off yumupdatesd) -# Jason Koppe adjusted to read sysconfig, -# use supervisord tools to start/stop, conditionally wait -# for child processes to shutdown, and startup later -# Erwan Queffelec -# make script LSB-compliant -# -# chkconfig: 345 83 04 -# description: Supervisor is a client/server system that allows \ -# its users to monitor and control a number of processes on \ -# UNIX-like operating systems. -# processname: supervisord -# config: /etc/supervisord.conf -# config: /etc/sysconfig/supervisord -# pidfile: /var/run/supervisord.pid -# -### BEGIN INIT INFO -# Provides: supervisord -# Required-Start: $all -# Required-Stop: $all -# Short-Description: start and stop Supervisor process control system -# Description: Supervisor is a client/server system that allows -# its users to monitor and control a number of processes on -# UNIX-like operating systems. -### END INIT INFO - -# Source function library -. /etc/rc.d/init.d/functions - -# Source system settings -if [ -f /etc/sysconfig/supervisord ]; then - . /etc/sysconfig/supervisord -fi - -# Path to the supervisorctl script, server binary, -# and short-form for messages. -supervisorctl=/usr/local/bin/supervisorctl -supervisord=${SUPERVISORD-/usr/local/bin/supervisord} -prog=supervisord -pidfile=${PIDFILE-/tmp/supervisord.pid} -lockfile=${LOCKFILE-/var/lock/subsys/supervisord} -STOP_TIMEOUT=${STOP_TIMEOUT-60} -OPTIONS="${OPTIONS--c /etc/supervisor/supervisord.conf}" -RETVAL=0 - -start() { - echo -n $"Starting $prog: " - daemon --pidfile=${pidfile} $supervisord $OPTIONS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - touch ${lockfile} - $supervisorctl $OPTIONS status - fi - return $RETVAL -} - -stop() { - echo -n $"Stopping $prog: " - killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile} -} - -reload() { - echo -n $"Reloading $prog: " - LSB=1 killproc -p $pidfile $supervisord -HUP - RETVAL=$? - echo - if [ $RETVAL -eq 7 ]; then - failure $"$prog reload" - else - $supervisorctl $OPTIONS status - fi -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status -p ${pidfile} $supervisord - RETVAL=$? - [ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status - ;; - restart) - restart - ;; - condrestart|try-restart) - if status -p ${pidfile} $supervisord >&/dev/null; then - stop - start - fi - ;; - force-reload|reload) - reload - ;; - *) - echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}" - RETVAL=2 - esac - - exit $RETVAL \ No newline at end of file diff --git a/modules/install-nomad/supervisord.conf b/modules/install-nomad/supervisord.conf deleted file mode 100644 index d96beb0..0000000 --- a/modules/install-nomad/supervisord.conf +++ /dev/null @@ -1,39 +0,0 @@ -; supervisor config file -; -; For more information on the config file, please see: -; http://supervisord.org/configuration.html -; -; Notes: -; - Shell expansion ("~" or "$HOME") is not supported. Environment -; variables can be expanded using this syntax: "%(ENV_HOME)s". -; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". - -[unix_http_server] -file=/var/run/supervisor.sock ; (the path to the socket file) -chmod=0700 ; sockef file mode (default 0700) - -[supervisord] -logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) -pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) -childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) -logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) -logfile_backups=10 ; (num of main logfile rotation backups;default 10) -loglevel=info ; (log level;default info; others: debug,warn,trace) - -; the below section must remain in the config file for RPC -; (supervisorctl/web interface) to work, additional interfaces may be -; added by defining them in separate rpcinterface: sections -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket - -; The [include] section can just contain the "files" setting. This -; setting can list multiple files (separated by whitespace or -; newlines). It can also contain wildcards. The filenames are -; interpreted as relative to this file. Included files *cannot* -; include files themselves. - -[include] -files = /etc/supervisor/conf.d/*.conf diff --git a/modules/run-nomad/run-nomad b/modules/run-nomad/run-nomad index 0216b17..2365cd5 100755 --- a/modules/run-nomad/run-nomad +++ b/modules/run-nomad/run-nomad @@ -4,7 +4,7 @@ set -e readonly NOMAD_CONFIG_FILE="default.hcl" -readonly SUPERVISOR_CONFIG_PATH="/etc/supervisor/conf.d/run-nomad.conf" +readonly SYSTEMD_CONFIG_PATH="/etc/systemd/system/nomad.service" readonly EC2_INSTANCE_METADATA_URL="http://169.254.169.254/latest/meta-data" readonly EC2_INSTANCE_DYNAMIC_DATA_URL="http://169.254.169.254/latest/dynamic" @@ -26,7 +26,6 @@ function print_usage { echo -e " --config-dir\t\tThe path to the Nomad config folder. Optional. Default is the absolute path of '../config', relative to this script." echo -e " --data-dir\t\tThe path to the Nomad data folder. Optional. Default is the absolute path of '../data', relative to this script." echo -e " --bin-dir\t\tThe path to the folder with Nomad binary. Optional. Default is the absolute path of the parent folder of this script." - echo -e " --log-dir\t\tThe path to the Nomad log folder. Optional. Default is the absolute path of '../log', relative to this script." echo -e " --user\t\tThe user to run Nomad as. Optional. Default is to use the owner of --config-dir." echo -e " --use-sudo\t\tIf set, run the Nomad agent with sudo. By default, sudo is only used if --client is set." echo -e " --environment\t\A single environment variable in the key/value pair form 'KEY=\"val\"' to pass to Nomad as environment variable when starting it up. Repeat this option for additional variables. Optional." @@ -77,11 +76,13 @@ function assert_not_empty { fi } -# Based on https://stackoverflow.com/a/17841619 -function join_by { - local IFS="$1" +function split_by_lines { + local prefix="$1" shift - echo "$*" + + for var in "$@"; do + echo "${prefix}${var}" + done } function lookup_path_in_instance_metadata { @@ -182,15 +183,14 @@ EOF chown "$user:$user" "$config_path" } -function generate_supervisor_config { - local readonly supervisor_config_path="$1" +function generate_systemd_config { + local readonly systemd_config_path="$1" local readonly nomad_config_dir="$2" local readonly nomad_data_dir="$3" local readonly nomad_bin_dir="$4" - local readonly nomad_log_dir="$5" - local readonly nomad_user="$6" - local readonly use_sudo="$7" - shift 7 + local readonly nomad_user="$5" + local readonly use_sudo="$6" + shift 6 local readonly environment=("$@") if [[ "$use_sudo" == "true" ]]; then @@ -198,25 +198,34 @@ function generate_supervisor_config { nomad_user="root" fi - log_info "Creating Supervisor config file to run Nomad in $supervisor_config_path" - cat > "$supervisor_config_path" < "$systemd_config_path" <