Skip to content

Commit

Permalink
node.js app auto started by upstart
Browse files Browse the repository at this point in the history
  • Loading branch information
truepattern committed Sep 2, 2012
1 parent d415adc commit 801c7df
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions Vagrantfile
Expand Up @@ -41,6 +41,7 @@ Vagrant::Config.run do |config|

# add mysite to webserver
chef.add_recipe("mysite")
chef.add_recipe("mysite::node")

# add node.js
chef.add_recipe "nodejs"
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Expand Up @@ -26,10 +26,10 @@ Following softwares are installed to the vbox
### Node.js App
* The sample app is in 'app' directory
* ssh to virtualbox

```bash
cd app
node server.js
# node is automatically started by upstart and should be running already
ps -aef | grep node
```

* go to your host box, browser and try http://localhost:8080
Expand Down
17 changes: 17 additions & 0 deletions site-cookbooks/mysite/files/default/nodejs.conf
@@ -0,0 +1,17 @@
#!upstart
description "node.js application"

start on startup
stop on shutdown

#Send KILL after 5 seconds
kill timeout 5
respawn

#script details
script
export HOME="/home/vagrant"
NODE_ENV=production
exec sudo -u vagrant NODE_ENV=production node $HOME/app/server.js 2>&1 >> /var/log/node.log
end script

12 changes: 0 additions & 12 deletions site-cookbooks/mysite/recipes/default.rb
Expand Up @@ -11,15 +11,3 @@

nginx_site "mysite"

#nginx_site "mysite" do
#template "nginx/mysite.conf.erb"
#action :enable
#end

#
#directory "/var/www/construction" do
#owner "www-data"
#group "sdmin"
#mode "0755"
#end

15 changes: 15 additions & 0 deletions site-cookbooks/mysite/recipes/node.rb
@@ -0,0 +1,15 @@
cookbook_file "/etc/init/mysite-nodejs.conf" do
source "nodejs.conf"
owner "root"
group "root"
mode 0644
end

service "mysite-nodejs" do
provider Chef::Provider::Service::Upstart
enabled true
running true
supports :restart => true, :reload => true, :status => true
action [:enable, :start]
end

0 comments on commit 801c7df

Please sign in to comment.