Wrote simple scripts to start/stop a go web app. Sometimes we need to start a pool of worker apps on specific ports. Following scripts help.
These scripts are system jobs for upstart and are to be placed in /etc/init.
description "App-Worker" author "Adnaan" start on (net-device-up and local-filesystems and runlevel ) stop on runlevel  respawn instance $PORT script #initramfs provides early userspace exec 2>>/dev/.initramfs/app-worker.log set -x export APP="/root/goworkspace/src/myappcode" #change directory or go won't read the web app resources chdir $APP #execute exec sudo $APP/app --port $PORT end script
The above script can be directly used as such:
Start a worker
service app-worker start PORT=8085
Stop a worker
service app-worker stop PORT=8085
But what if need a bunch of workers. Can't go starting them individually now, can we?
description "App Pool" author "Adnaan" start on (local-filesystems and net-device-up and runlevel ) stop on shutdown pre-start script #initramfs provides early userspace exec 2>>/dev/.initramfs/app-pool.log set -x start app-worker PORT=8085 start app-worker PORT=8086 #add more jobs.. end script
Start a Pool
service app-pool start
Stop the Pool
service app-pool stop
The above won't have any effect since it restarts the workers again. We need to individually stop the workers. Let's find our workers.
initctl list | grep "app"
Choose your worker from the list and stop it as described above. I realize that we are individually stopping the workers. Well I am still looking for a good solution to do that in a single step. Suggestions welcome!