Skip to content

Instantly share code, notes, and snippets.

@ryanray
Created November 21, 2013 11:15
Show Gist options
  • Save ryanray/7579912 to your computer and use it in GitHub Desktop.
Save ryanray/7579912 to your computer and use it in GitHub Desktop.

Revisions

  1. ryanray created this gist Nov 21, 2013.
    46 changes: 46 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    # config/deploy.rb

    # probably a lot of ways to improve this...
    set :application, 'my_app'
    set :repo_url, '[email protected]:USERNAME/my_app.git'
    # should set up a deploy user
    set :user, 'deploy'

    set :deploy_to, '/var/www/my_app'
    set :scm, :git

    set :format, :pretty
    set :log_level, :debug
    set :pty, true

    set :keep_releases, 5

    namespace :deploy do

    #TODO: Add stop task in upstart
    desc "Stop Forever"
    task :started do
    on roles(:app) do
    execute "forever stopall"
    end
    end

    desc "Install node modules non-globally"
    task :npm_install do
    on roles(:app) do
    execute "cd #{current_path} && npm install"
    end
    end

    desc 'Restart application'
    task :restart do
    on roles(:app), in: :sequence, wait: 5 do
    # This assumes you are using upstart to startup your application
    # - be sure that your upstart script runs as the 'deploy' user
    execute "sudo start node-upstart-script", raise_on_non_zero_exit: false
    end
    end

    before :restart, 'deploy:npm_install'

    end
    14 changes: 14 additions & 0 deletions node-upstart-script.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # /etc/init/node-upstart-script.conf
    description "myapp"
    author "Your Name <[email protected]>"

    start on (local-filesystems and net-device-up IFACE=eth0)
    stop on shutdown

    script
    export HOME=/home/deploy
    export NODE_ENV=production

    cd /var/www/my_app/current/
    exec sudo -u deploy forever start -l "/var/log/node/my_app.log" -a app.js >> /var/log/node/my_app.log 2>&1
    end script
    15 changes: 15 additions & 0 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # config/deploy/production.rb
    set :stage, :production

    server '127.0.0.1', user: 'deploy', roles: %w{web app}, my_property: :my_value

    server '127.0.0.1',
    user: 'deploy',
    roles: %w{web app},
    ssh_options: {
    # user: 'user_name', # overrides user setting above
    # keys: %w(~/.ssh/id_rsa),
    forward_agent: true,
    auth_methods: %w(publickey password),
    #password: 'use a key instead'
    }