Monday, October 5, 2015

Configuring Devcamps to run multiple Apache or NGINX instances

Here is a solution for enabling Devcamps to run your apps using separate instances of Apache2.

Out of the box, Devcamps does not configure our Apache2 setup.

It's nice to go from running mkcamp to viewing a live version of the app on the camp port without running any additional setup scripts.

I knew running multiple apache2 instances was possible. Googling some brought me to run this in my terminal:

cat /usr/share/doc/apache2/README.multiple-instances

The key take away is this:

The basic idea is to copy /etc/apache2 to /etc/apache2-xxx.

Since our 'camp type' directory [camp_type]/etc gets copied down to our camp directories on running mkcamp, we can copy the /etc/apache2 directory to our [camp_type]/etc directory and modify the appropriate Apache config files with our camp tokens. The 'magic' happens when we change httpd_command_path value in local-config to:

httpd_cmd_path:sudo cp __CAMP_PATH__/apache2-camp/apache2ctl __CAMP_PATH__/apache2-camp/apache2ctl-camp__CAMP_NUMBER__ && sudo __CAMP_PATH__/apache2-camp/apache2ctl-camp__CAMP_NUMBER__

This will allow us start the apache2 binary on separate processes for each camp.

The apache config files I tokenize are as follows:


Update: 12/04/2015

The above code works. However, we don't want to run our web servers as root. There is a better way and it's baked into devcamps. The copy-paths.yml file lets us include the camp tokens in the paths with the 'parse_target' options.

source: /usr/bin/apache2ctl
target: apache2-camp/apache2ctl-__CAMP_NUMBER__
always: 1
parse_target: 1

Happy camping!