def pid_file_exists?(pid_file) test(*("[ -f #{pid_file} ]").split(' ')) end def process_exists?(pid_file) pid_file_exists?(pid_file) and test(*("kill -0 $( cat #{pid_file} )").split(' ')) end namespace :load do task :defaults do set :pid_dir, -> { File.join(shared_path, 'tmp', 'pids') } set :crono_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) } set :crono_log, -> { File.join(shared_path, 'log', 'crono.log') } set :crono_role, -> { :app } end end namespace :crono do desc "Start crono" task :start do on roles fetch(:crono_role) do args = [] args.push "--piddir #{pid_dir}" args.push "--logfile #{fetch(:crono_log)}" args.push "--environment #{fetch(:crono_env)}" within release_path do execute(:bundle, :exec, :crono, :start, args.compact.join(' ')) end end end desc "Stop crono" task :stop do on roles fetch(:crono_role) do args = [] args.push "--piddir #{pid_dir}" args.push "--logfile #{fetch(:crono_log)}" args.push "--environment #{fetch(:crono_env)}" within release_path do execute(:bundle, :exec, :crono, :stop, args.compact.join(' ')) end end end desc 'Restart crono' task :restart do invoke 'crono:stop' invoke 'crono:start' end end after 'deploy:updated', 'crono:stop' after 'deploy:reverted', 'crono:stop' after 'deploy:published', 'crono:start'