Skip to content
Permalink
Browse files

Updated guides

  • Loading branch information...
davidmerfield committed Mar 7, 2019
1 parent dc94610 commit ccced86e14b2f4b490a9e341c99c9ba89353f61e
Showing with 39 additions and 83 deletions.
  1. +26 −0 config/guides/production-environment-setup.txt
  2. +13 −10 config/readme.txt
  3. +0 −73 config/upstart/{README → readme.txt}
@@ -19,3 +19,29 @@ I made these changes to the AWS instance when I created it. I believe they were
sysctl vm.overcommit_memory=1
sudo bash -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
dd if=/dev/zero of=/swapfile1 bs=1024 count=4194304

Upstart
-------

Before we install our upstart scripts, we'll need to comment out ```Defaults requiretty``` in /etc/sudoers. This allows me to run an upstart script as another user without a tty. Ideally, we'd use upstart's setuid feature, but the version of upstart that ships with amazon linux is too old and does not have that feature. To fix this, open /etc/sudoers and comment out requiretty by adding a '#' at the start of its line.

Upstart reads conf files in /etc/init. So run the script which will copy the file's from Blot's directory there, reload upstart's configuration, and then verify that upstart could load the scripts:

$ sudo ./scripts/production/update_upstart.sh

If the configuration is incorrect, the services will not appear on the output. Then you can start redis, then blot, then nginx.

```
> start redis
> start blot
> start nginx
```

If you'd like more information about the scripts, check the conf files. I've added plenty of comments. Remember that Blot needs redis to be running before it can run. This is documented in its conf file.


Monit
-----

Add a line to /etc/hosts file to allow monit to request localhost.

@@ -1,22 +1,25 @@
Config
------

This directory contains the scripts and configuration code to run NGINX, Redis and Monit, which combine with the application code in ../app to produce a useful blogging platform.
This directory contains the scripts and configuration code to run NGINX, Redis and Monit, which combine with the node js server to produce a useful blogging platform. When setting up a new production or development machine, follow the respective guides in the guides directory. There are a number of scripts for updating Blot's configuration on the server, which are stored in scripts/production:

Upstart
-------
Upstart: reloading the scripts
sudo ./scripts/production/update_upstart.sh

Monit: reloading configuration
sudo ./scripts/production/reload_monit_rc.sh

Blot and the software it depends on (Redis + NGINX) are started by three corresponding upstart scripts, which are invoked when the server boots or reboots. These scripts can also be controlled like so:
NGINX: reloading configuration
sudo ./scripts/production/nginx_reload_configuration.sh

$ sudo stop blot
$ sudo start blot
$ sudo stop redis
$ sudo start redis

You can browse these scripts in the upstart subdirectory of this folder. Upstart monitors the processes started and attempts to respawn them if they die unexpectedly.
Upstart
-------

Used to start Blot, Redis, NGINX and monit when the server boots. You can browse these scripts in the upstart subdirectory of this folder. Upstart monitors the processes after they have started and attempts to respawn them if they exit. For more about upstart, check the readme in the upstart subdirectory.

Additionally, upstart starts Monit to ensure that the two web servers (Blot and NGINX) are responding to requests appropriately.

Monit
-----

Used to check that a running server is still responsive.
@@ -1,8 +1,3 @@
When you make an edit, run scripts/production/update_upstart

then sudo stop blot && sudo start blot


Installing an upstart service
------------------

@@ -60,74 +55,6 @@ monit 0:off 1:off 2:off 3:off 4:off 5:off 6:off
...
```

## Installing upstart scripts

Before we install our upstart scripts, we'll need to comment out ```Defaults requiretty``` in /etc/sudoers. This allows me to run an upstart script as another user without a tty. Ideally, we'd use upstart's setuid feature, but the version of upstart that ships with amazon linux is too old and does not have that feature.

To fix this, open /etc/sudoers and comment out requiretty by adding a '#' at the start of its line.

Upstart reads conf files in /etc/init. So copy the file's from Blot's directory there.

```
> cp /var/www/blot/scripts/upstart/nginx.conf /etc/init/nginx.conf
> cp /var/www/blot/scripts/upstart/redis.conf /etc/init/redis.conf
> cp /var/www/blot/scripts/upstart/monit.conf /etc/init/monit.conf
> cp /var/www/blot/scripts/upstart/blot.conf /etc/init/blot.conf
```

Then reload upstart's configuration:

```
> initctl reload-configuration
```

Then verify that upstart could load the scripts:

```
> initctl list | grep -e 'blot\|nginx\|redis\|monit'
blot stop/waiting
nginx stop/waiting
redis stop/waiting
monit stop/waiting
```

If the configuration is incorrect, the service will not appear on that list.

Then you can start redis, then blot, then nginx.

```
> start redis
> start blot
> start nginx
```

If you'd like more information about the scripts, check the conf files. I've added plenty of comments. Remember that Blot needs redis to be running before it can run. This is documented in its conf file.






# Monit

Upstart will respawn processes it detects have crashed. It detects crashed processes by checking a pid file. It's possible that Blot's webserver (and NGINX) enter an unresponsive state in which a process is still running and a pid file exists, but the server cannot handle requests. To mitigate this risk, we use monit to check periodically that nginx and blot and responding to requests as they should.

Monit requires that root owns the configuration file and that is has ```0700``` permissions.

```
> chmod 0700 /etc/monit.rc
```

I then added a line to /etc/hosts file to allow monit to request localhost.


# Deploying changes

First fetch the latest code:

```
> git pull origin master
```

## Blot

0 comments on commit ccced86

Please sign in to comment.
You can’t perform that action at this time.