Skip to content

Running as a service on Ubuntu 12.04

Robert Fonó edited this page Jun 10, 2015 · 2 revisions

Note: This guide is for Ubuntu 12.04 or newer. It may work on some other distributions or older versions of Ubuntu, but nothing is guaranteed.

After installing DemocracyOS, to run it as a service do the following:

#1. Create startup scripts

You will need to create two sh script that will issue the comands needed for starting DemocracyOS and the notifier service.

The script contents:

#! /bin/bash
 
cd /PATH/TO/DEMOCRACY/OS
export GITHUB_USERNAME=USERNAME
export GITHUB_PASSWORD=PASSWORD
export NODE_PATH=.
export STAFF='johndoe@example.com,peter@example.com'
make run

Swap the placeholder text to the absolute path to your DemocracyOS installation. Also swap in a valid Github username and password and the real list of administrator email addresses.

Save it as democracy.sh, then make it executable: chmod +x democracy.sh

The script for notifier:

#! /bin/bash
 
cd /PATH/TO/DEMOCRACY/NOTIFIER
export NODE_PATH=.
make

Save it as notifier.sh, then make it executable: chmod +x notifier.sh

#2. Create service jobs

Open up a new file in /etc/init:

sudo nano /etc/init/democracy.conf

Copy and paste the following to the new file you just made:

description "DemocracyOS"
 
start on startup
stop on shutdown
 
respawn
respawn limit 10 90
 
exec start-stop-daemon --start -c USERNAME --exec /PATH/TO/democracy.sh

Make sure to swap USERNAME for an actual unix user on your server. DemocracyOS will be run as this user. Also swap in the actual path to democracy.sh you made in the previous step.

Now for the notifier:

sudo nano /etc/init/notifier.conf

And the contents:

description "DemocracyOS notifier"
 
start on startup
stop on shutdown
 
respawn
respawn limit 10 90
 
exec start-stop-daemon --start -c USERNAME --exec /PATH/TO/notifier.sh

Again, don't forget to swap in the actual path to your notifier.sh script.

#3. Starting the services

After you've done all this, you can start both services like so:

sudo service democracy start sudo service notifier start

#+1 Running multiple instances with apache

You can run multiple instances and balance between them. This way you can update the app without downtime or make sure that traffic doesn't crash your server by running DemocracyOS on multiple servers.

Here's the guide.

On a single server you can have multiple services like democracy and democracy2 and balance between them. This way you can safely restart one of them, then the other and never have a second of downtime.