Last active
December 18, 2015 14:59
-
-
Save miyagawa/5801509 to your computer and use it in GitHub Desktop.
Capistrano template to run carton exec plackup with start_server (Server::Starter). Change to use Starman/Starlet/Monoceros if you want more concurrency.
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
require 'capistrano/ext/multistage' | |
set :stages, %w(vagrant) | |
set :default_stage, "vagrant" | |
set :application, "cpanmetadb" | |
set :repository, "git://github.com/miyagawa/cpanmetadb-perl.git" | |
set :scm, :git | |
set :use_sudo, false | |
set :branch, ENV['BRANCH'] || "master" | |
set :deploy_via, :remote_cache | |
# http://stackoverflow.com/questions/3023857/capistrano-and-deployment-of-a-website-from-github | |
set :normalize_asset_timestamps, false | |
set :pidfile, "#{shared_path}/pids/start_server.pid" | |
set :statusfile, "#{shared_path}/pids/start_server.status" | |
before "deploy:finalize_update", "carton:install" | |
namespace :carton do | |
task :install do | |
run "cd #{latest_release} && carton install --deployment --path=#{shared_path}/local 2>&1" | |
end | |
end | |
namespace :deploy do | |
def server_starter | |
"cd #{current_path} && nohup carton exec start_server --port=#{app_port} --status-file=#{statusfile} --pid-file=#{pidfile}" | |
end | |
def run_server | |
"#{server_starter} -- plackup -I#{current_path}/lib --access-log=#{shared_path}/log/access_log #{current_path}/app-gw.psgi > #{shared_path}/log/start_server.log 2>&1" | |
end | |
def carton_env | |
{ "PERL_CARTON_PATH" => "#{shared_path}/local" } | |
end | |
task :start, :roles => :app do | |
run "#{run_server} &", :env => carton_env | |
end | |
task :stop, :roles => :app do | |
run "if [ -e #{pidfile} ]; then kill -s TERM `cat #{pidfile}`; rm #{pidfile}; fi" | |
end | |
task :restart, :roles => :app do | |
run "if [ -e #{pidfile} ]; then #{server_starter} --restart; else (#{run_server} &); fi", :env => carton_env | |
end | |
end |
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
set :user, "vagrant" | |
server "cpanmetadb-vagrant", :app, :web | |
set :deploy_to, "/home/vagrant/apps/cpanmetadb-perl" | |
set :app_port, 5000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment