This gem provides some Capistrano3 tasks for deploying NodeJS servers using the npm package Forever to make sure that that application runs forever. The gem is named 'capistrano-4ever', as 'capistrano-forever' was taken (thus, perhaps, rendering this gem redundant). In any case, this gem namespaces under 'forever' instead of '4ever', and so the two gems are incompatible.
Add this line to your application's Gemfile:
gem 'capistrano-4ever'
And then execute:
% bundle
Or install it yourself as:
% gem install capistrano-4ever
Require in Capfile:
require 'capistrano/forever'
:forever_env_variables
: Any environmental variables you'd like, as a hash. I recommend setting NODE_ENV
here.
:forever_path
: Path to globally installed forever binary.
:forever_app
: The application you're deploying.
:forever_target_path
: The target path. Defaults to Capistrano's release_path
. I recommend that you don't set this.
:forever_flags
: Flags to pass to the forever binary as a string.
- NB: Order is important here! Ape the order in the example below or play around, but don't be frustrated if something that seems like it should work doesn't. This is due to how the forever binary parses options.
Configuration symbol | Default |
---|---|
:forever_env_variables |
{} |
:forever_path |
'forever' (let env take care of pathing) |
:forever_app |
'main.js' |
:forever_target_path |
Capistrano's release_path |
:forever_flags |
'--append --uid <forever_app>' |
I recommend setting:
-l
: So that you can have a shared logfile across deploys
--append
: Append to logfiles and don't die when the logfile exists
--minUptime
: If nothing else, keep NodeJS from complaing that you didn't set it.
--spinSleepTime
: See above
--uid <string>
: Set a custom string so that this gem will be able to stop previously-started instances.
set :forever_env_variables, {'NODE_ENV' => "#{fetch(:npm_env)}"}
set :forever_path, '/usr/bin/forever'
set :forever_app, 'dog-sitting-calendar.js'
set :forever_target_path, '/var/www/dogsit'
set :forever_flags, [ "-l #{fetch :forever_target_path}/log/forever.log",
'--append',
'--minUptime 1000',
'--spinSleepTime 1000',
"--uid '#{fetch :forever_app}'" ].join(' ')
% bundle exec cap <environment> forever:<task>
check
: Check forforever
binary on deploy target- Displays human-readable output; not for scripting
start
: Start NodeJS server with foreverstop
: Stop NodeJS server with foreverrestart
: Restart NodeJS server with foreverstop_all
: Stop all NodeJS servers managed by forever on target serverrestart_all
: Restart all NodeJS servers managed by forever on target server
- Fork it ( https://github.com/oversee-ffleming/capistrano-forever/fork )
- Create your feature branch (
git checkout -b new-feature
) - Commit your changes (
git commit -am 'Added a neat feature!'
) - Push to the branch (
git push origin new-feature
) - Create a new Pull Request