Creating an UpStart Job for the Product Scraper - welikepie/asos-hangout-app GitHub Wiki

Upstart is an Ubuntu Tool that runs scripts automatically for you. This is useful so you don’t have to manually run the scraper yourself each time you want to update the product database. Upstart can also recover from error states if one arises.

If your server is running on Ubuntu, the Upstart tool can be used and you can follow this guide to install it. If your server is not based on a linux variant however, you will need to explore other ways of achieving automatic script running.

To use Upstart, you need to create a config script, also know as an upstart “job”.

Here is an example of what the Upstart file could look like: Everything in curly brackets {} needs to be edited.

# ASOS Realtime Communication Server
description		"{Description of Process}"
author			"{Author of Process}"

# Stop server automatically on system stops/restarts
stop on starting rc RUNLEVEL=[016]

respawn
respawn limit 20 5

# Max open files are @ 1024 by default. Bit few.
limit nofile 32768 32768

kill timeout 30
normal exit 0

chdir {absolute filepath to node-backend folder}
nice 0
exec node --harmony server.js >> {absolute path to log file, with filename and extension} 2>&1

An important part of this script is to require it to restart the node server, should a crash occur. Jobs are plain text files and should not be executable. This script should be saved in etc/init with the .conf extension.

Jobs can be started and stopped manually by using the start and stop commands. Each command takes a job name and outputs the final status of the job as a response to the command. I.E “start scraper”, “stop scraper”. The status of any job may be queried using the “status” command: “status scraper”.


Step Five: Deploying the Product Scraper