Last active
August 29, 2015 14:07
-
-
Save markhuge/b29bcd7cef50af4dc2cd to your computer and use it in GitHub Desktop.
Node.js app Upstart Script example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <%= @app_name %>.conf | |
# This file is generated by Chef for <%= node[:fqdn] %> | |
description "<%= @app_name %>" | |
start on filesystem or runlevel [2345] | |
stop on runlevel [06] | |
expect fork | |
respawn | |
respawn limit 5 30 | |
pre-start script | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (upstart) Starting" >> <%= @logfile %> | |
end script | |
pre-stop script | |
rm /var/run/<%= @app_name %>.pid | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (upstart) Stopping" >> <%= @logfile %> | |
end script | |
script | |
echo $$ > /var/run/<%= @app_name %>.pid | |
chdir <%= @path %> | |
exec sudo -u <%= @username %> \ | |
NODE_ENV=<%= @node_env %> \ | |
npm start >> <%= @logfile %> 2>&1 | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_app.conf | |
# This file is generated by Chef for myapp.example.biz | |
description "my_app" | |
start on filesystem or runlevel [2345] | |
stop on runlevel [06] | |
expect fork | |
respawn | |
respawn limit 5 30 | |
pre-start script | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (upstart) Starting" >> /var/log/my_app.log | |
end script | |
pre-stop script | |
rm /var/run/my_app.pid | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (upstart) Stopping" >> /var/log/my_app.log | |
end script | |
script | |
echo $$ > /var/run/my_app.pid | |
chdir /opt/my_app/1.2.0 | |
exec sudo -u nodeuser \ | |
NODE_ENV=production \ | |
npm start >> /var/log/my_app.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app_name = node[:myapp][:name] | |
template "/etc/init/#{app_name}.conf" do | |
source "chef.template.erb" | |
owner "root" | |
group "root" | |
mode "0744" | |
variables({ | |
:path => node[:myapp][:deploy_path], | |
:app_name => app_name, | |
:node_env => node[:myapp][:node_env], | |
:user => node[:myapp][:user], | |
:logfile => node[:myapp][:logfile] | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment