Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Switch from supervisord to systemd #62

Merged
merged 3 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/nomad-consul-ami/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from the Consul AWS Module with [Packer](https://www.packer.io/) to create [Amaz

1. Ubuntu 16.04
1. Ubuntu 18.04
1. Amazon Linux
1. Amazon Linux 2

These AMIs will have [Consul](https://www.consul.io/) and [Nomad](https://www.nomadproject.io/) installed and
configured to automatically join a cluster during boot-up.
Expand Down
19 changes: 10 additions & 9 deletions examples/nomad-consul-ami/nomad-consul-docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"min_packer_version": "0.12.0",
"variables": {
"aws_region": "us-east-1",
"nomad_version": "0.7.1",
"consul_module_version": "v0.3.1",
"consul_version": "1.0.3"
"nomad_version": "0.9.1",
"consul_module_version": "v0.7.4",
"consul_version": "1.5.1"
},
"builders": [
{
Expand Down Expand Up @@ -52,17 +52,17 @@
"ssh_username": "ubuntu"
},
{
"ami_name": "nomad-consul-docker-amazon-linux-{{isotime | clean_ami_name}}",
"ami_description": "An Amazon Linux AMI that has Nomad, Consul and Docker installed.",
"ami_name": "nomad-consul-docker-amazon-linux-2-{{isotime | clean_ami_name}}",
"ami_description": "An Amazon Linux 2 AMI that has Nomad, Consul and Docker installed.",
"instance_type": "t2.micro",
"name": "amazon-linux-ami",
"name": "amazon-linux-2-ami",
"region": "{{user `aws_region`}}",
"type": "amazon-ebs",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"architecture": "x86_64",
"name": "*amzn-ami-hvm-*",
"name": "*amzn2-ami-hvm-*",
"block-device-mapping.volume-type": "gp2",
"root-device-type": "ebs"
},
Expand All @@ -89,9 +89,9 @@
},
{
"type": "shell",
"script": "{{template_dir}}/setup_amazon-linux.sh",
"script": "{{template_dir}}/setup_amazon-linux-2.sh",
"only": [
"amazon-linux-ami"
"amazon-linux-2-ami"
]
},
{
Expand All @@ -111,3 +111,4 @@
}
]
}

17 changes: 9 additions & 8 deletions examples/nomad-consul-ami/nomad-consul.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"min_packer_version": "0.12.0",
"variables": {
"aws_region": "us-east-1",
"nomad_version": "0.7.1",
"consul_module_version": "v0.3.1",
"consul_version": "1.0.3"
"nomad_version": "0.9.1",
"consul_module_version": "v0.7.4",
"consul_version": "1.5.1"
},
"builders": [
{
Expand Down Expand Up @@ -52,17 +52,17 @@
"ssh_username": "ubuntu"
},
{
"ami_name": "nomad-consul-amazon-linux-{{isotime | clean_ami_name}}",
"ami_description": "An Amazon Linux AMI that has Nomad and Consul installed.",
"ami_name": "nomad-consul-amazon-linux-2-{{isotime | clean_ami_name}}",
"ami_description": "An Amazon Linux 2 AMI that has Nomad and Consul installed.",
"instance_type": "t2.micro",
"name": "amazon-linux-ami",
"name": "amazon-linux-2-ami",
"region": "{{user `aws_region`}}",
"type": "amazon-ebs",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"architecture": "x86_64",
"name": "*amzn-ami-hvm-*",
"name": "*amzn2-ami-hvm-*",
"block-device-mapping.volume-type": "gp2",
"root-device-type": "ebs"
},
Expand Down Expand Up @@ -91,7 +91,7 @@
"sudo yum install -y git"
],
"only": [
"amazon-linux-ami"
"amazon-linux-2-ami"
]
},
{
Expand All @@ -111,3 +111,4 @@
}
]
}

16 changes: 8 additions & 8 deletions modules/install-nomad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This script has been tested on the following operating systems:

* Ubuntu 16.04
* Ubuntu 18.04
* Amazon Linux
* Amazon Linux 2

There is a good chance it will work on other flavors of Debian, CentOS, and RHEL as well.

Expand Down Expand Up @@ -63,7 +63,6 @@ The `install-nomad` script does the following:

1. [Create a user and folders for Nomad](#create-a-user-and-folders-for-nomad)
1. [Install Nomad binaries and scripts](#install-nomad-binaries-and-scripts)
1. [Install supervisord](#install-supervisord)
1. [Follow-up tasks](#follow-up-tasks)


Expand All @@ -88,12 +87,6 @@ Install the following:
* `run-nomad`: Copy the [run-nomad script](https://github.com/hashicorp/terraform-aws-nomad/tree/master/modules/run-nomad) into `/opt/nomad/bin`.


### Install supervisord

Install [supervisord](http://supervisord.org/). We use it as a cross-platform supervisor to ensure Nomad is started
whenever the system boots and restarted if the Nomad process crashes.


### Follow-up tasks

After the `install-nomad` script finishes running, you may wish to do the following:
Expand All @@ -105,6 +98,13 @@ After the `install-nomad` script finishes running, you may wish to do the follow



## Dependencies

The install script assumes that `systemd` is already installed. We use it as a cross-platform supervisor to ensure Nomad is started
whenever the system boots and restarted if the Nomad process crashes. Additionally, it is used to store all logs which can be accessed
using `journalctl`.


## Why use Git to install this code?

<!-- TODO: update the package managers URL to the final URL when this Module is released -->
Expand Down
42 changes: 2 additions & 40 deletions modules/install-nomad/install-nomad
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# 1. Ubuntu 16.04
# 2. Ubuntu 18.04
# 3. Amazon Linux
# 3. Amazon Linux 2

set -e

Expand All @@ -23,7 +23,7 @@ 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, Ubuntu 18.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, Ubuntu 18.04 and Amazon Linux 2."
echo
echo "Options:"
echo
Expand Down Expand Up @@ -69,41 +69,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)" ]
}
Expand All @@ -118,11 +83,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
Expand Down Expand Up @@ -154,7 +117,6 @@ function create_nomad_install_paths {
sudo mkdir -p "$path/bin"
sudo mkdir -p "$path/config"
sudo mkdir -p "$path/data"
sudo mkdir -p "$path/log"

log_info "Changing ownership of $path to $username"
sudo chown -R "$username:$username" "$path"
Expand Down
116 changes: 0 additions & 116 deletions modules/install-nomad/supervisor-initd-script.sh

This file was deleted.

39 changes: 0 additions & 39 deletions modules/install-nomad/supervisord.conf

This file was deleted.

Loading