Skip to content

Instantly share code, notes, and snippets.

@rezen
Last active May 11, 2018 18:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rezen/9792753 to your computer and use it in GitHub Desktop.
Save rezen/9792753 to your computer and use it in GitHub Desktop.
Example upstart for centos /etc/init/template.conf
# Below are some good links for reference
# https://gist.github.com/c4milo/940909
# https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/
# http://upstart.ubuntu.com/cookbook/
# http://serverfault.com/questions/321375/passing-arguments-to-upstart-job
author "Andres Hermosilla <an2dres5m@gmail.com>"
description "Update Example Config"
# Set variables
env upstart_name=template
env log_file=/var/log/upstart-template.txt
env pid_file=/var/run/template.pid
# If you want to pass args to upstart
# e.g. start template src=/var/www/test
instance $src
# Start ....
start on startup
stop on shutdown
# Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90
# Before it starts ....
pre-start script
PID=`status $upstart_name | egrep -oi '([0-9]+)$' | head -n1`
echo $PID > $pid_file
logger "$PID pre-starting .... "
mkdir -p /var/www/html/upstart
end script
# The main thing that loops forever
script
logger "the logfile variable = $log_file"
sleep 1000
logger "script stopped sleeping ... "
end script
# Before it all dies ...
pre-stop script
logger "$PID pre-stopping .... "
rm -rf /var/www/html/upstart
rm -f $pid_file
end script
@KanishkTanwar
Copy link

whenever I try to run the script like sudo start pricing_service, I am getting this error unknown job, also there is no initctl how to fix help me
i have installed centos 6.7 minimal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment