Skip to content

Instantly share code, notes, and snippets.

@meritt
Created November 21, 2011 22:32
Show Gist options
  • Save meritt/1384184 to your computer and use it in GitHub Desktop.
Save meritt/1384184 to your computer and use it in GitHub Desktop.
Настройка whenever для запуска CoffeeScript в кроне (доставка с помощью Capistrano)
set :application, "simonenko.su"
set :node_file, "server.coffee"
set :host, "178.79.189.200"
set :repository, "[email protected]:meritt/simonenko.su.git"
set :user, "root"
set :admin_runner, "www"
set :scm, :git
set :branch, "master"
set :deploy_via, :remote_cache
set :deploy_to, "/usr/www/#{application}"
set :keep_releases, 4
role :app, host
namespace :deploy do
desc "Start application with forever"
task :start, :roles => :app, :except => { :no_release => true } do
run "forever start -c coffee #{current_path}/#{node_file}"
end
desc "Stop application"
task :stop, :roles => :app, :except => { :no_release => true } do
run "forever stop #{current_path}/#{node_file}"
end
desc "Restart application"
task :restart, :roles => :app, :except => { :no_release => true } do
stop
sleep 1
start
end
desc "Install npm modules"
task :npm_install do
run "cd #{release_path} && npm link"
end
desc "Update node_modules symlink"
task :npm_update_symlink do
run "rm -rf #{release_path}/node_modules"
run "ln -s #{shared_path}/node_modules #{release_path}/node_modules"
end
desc "Update access to application"
task :final_options, roles => :app do
run "chown -R #{admin_runner}:#{admin_runner} #{deploy_to}"
run "chmod 777 #{release_path}/cache"
end
desc "Clear cron jobs"
task :clear_crontab, :roles => :app do
run "cd #{current_path} && whenever --clear-crontab #{application}"
end
desc "Update cron jobs"
task :update_crontab, :roles => :app do
run "cd #{current_path} && whenever --update-crontab #{application}"
end
task :symlink_configs, :roles => :app do
%w[app_config.yml].each do |f|
run "ln -sf #{shared_path}/config/#{f} #{release_path}/config/#{f}"
end
end
desc "Create folders for nodejs application"
task :setup_for_nodejs, :roles => :app do
run "mkdir -p #{deploy_to}"
run "mkdir -p #{shared_path}/node_modules"
run "chown -R #{admin_runner}:#{admin_runner} #{deploy_to}"
end
end
before 'deploy:setup', 'deploy:setup_for_nodejs'
after "deploy:finalize_update", "deploy:cleanup", "deploy:symlink_configs", "deploy:update_crontab", "deploy:final_options"
after "deploy:update_code", "deploy:npm_update_symlink", "deploy:npm_install", "deploy:clear_crontab"
job_type :coffee, "cd :path && /usr/local/bin/coffee :task :output"
every 2.hours do
coffee "import.coffee"
end
@meritt
Copy link
Author

meritt commented Nov 22, 2011

Подробнее о настройке whenever и запуске с помощью Capistrano здесь: blog.simonenko.su

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment