capistrano-offroad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2010, Maciej Pasternacki <maciej@pasternacki.net>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the copyright holder nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL MACIEJ PASTERNACKI BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ require 'capistrano-offroad/reset'
2
+ require 'capistrano-offroad/utils'
3
+
4
+ # just for consistency
5
+ def offroad_modules(*modules)
6
+ modules.each { |mod| require "capistrano-offroad/modules/#{mod}" }
7
+ end
@@ -0,0 +1,75 @@
1
+ # Running via demontools
2
+ require 'capistrano'
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ set :svscan_root, "/service"
6
+ set :supervise_name, "#{application}"
7
+
8
+ def svc(cmd)
9
+ sudo "svc #{cmd} #{svscan_root}/#{supervise_name}"
10
+ end
11
+
12
+ namespace :daemontools do
13
+ desc "Create symlink in svscan directory"
14
+ task :create_symlink do
15
+ sudo "ln -s -v #{current_path} #{svscan_root}/#{supervise_name}"
16
+ end
17
+
18
+ desc "[internal] Remove symlink from svscan directory"
19
+ task :remove_symlink do
20
+ sudo "rm -v #{svscan_root}/#{supervise_name}"
21
+ end
22
+
23
+ desc "Remove symlink from svscan directory and stop supervise"
24
+ task :remove do
25
+ remove_symlink
26
+ sudo "svc -x -t #{current_path}"
27
+ end
28
+
29
+ desc "Supervise status of current release"
30
+ task :status do
31
+ sudo "svstat #{svscan_root}/#{supervise_name}"
32
+ end
33
+
34
+ desc "Supervise status of all releases"
35
+ task :relstatus do
36
+ sudo "svstat #{releases_path}/*"
37
+ end
38
+ end
39
+
40
+ namespace :deploy do
41
+ desc "Start service (svc -u)"
42
+ task :start do
43
+ svc "-u"
44
+ end
45
+
46
+ desc "Stop service (svc -d)"
47
+ task :stop do
48
+ svc "-d"
49
+ end
50
+
51
+ desc "Restart service (svc -t)"
52
+ task :restart do
53
+ svc "-t"
54
+ end
55
+
56
+ desc <<-DESC
57
+ [internal] Symlink latest release to current, taking daemontools into accont.
58
+
59
+ WARNING: rollback is broken!
60
+ DESC
61
+ task :symlink do
62
+ on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" } # FIXME!
63
+ run "rm -f #{current_path}"
64
+ sleep 5
65
+ sudo "svc -t -x #{previous_release}"
66
+ run "ln -s #{latest_release} #{current_path}"
67
+ end
68
+ end
69
+
70
+ before "deploy:cleanup" do
71
+ # needed, by default I don't use sudo, but we need one to remove
72
+ # supervise/ directories.
73
+ set :run_method, :sudo
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ # My defaults for deployment, may or may nat be useful for anyone else.
2
+ require 'capistrano'
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ set :scm, :git
6
+ set :ssh_options, { :forward_agent => true }
7
+ set :use_sudo, false
8
+ set :deploy_to, "/srv/#{application}"
9
+ end
@@ -0,0 +1,51 @@
1
+ # Django deployment
2
+
3
+ require 'capistrano'
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+
7
+ set :python, "python"
8
+
9
+ set :django_project_subdirectory, "project"
10
+ set :django_use_south, false
11
+
12
+ depend :remote, :command, "#{python}"
13
+
14
+ def django_manage(cmd, options={})
15
+ path = options.delete(:path) || "#{latest_release}"
16
+ run "cd #{path}/#{django_project_subdirectory}; #{python} manage.py #{cmd}", options
17
+ end
18
+
19
+ namespace :django do
20
+ desc <<EOF
21
+ Run custom Django management command in latest release.
22
+
23
+ Pass the management command and arguments in COMMAND="..." variable.
24
+ If COMMAND variable is not provided, Capistrano will ask for a command.
25
+ EOF
26
+ task :manage do
27
+ set_from_env_or_ask :command, "Enter management command"
28
+ django_manage "#{command}"
29
+ end
30
+ end
31
+
32
+ namespace :deploy do
33
+ desc "Run manage.py syncdb in latest release."
34
+ task :migrate, :roles => :db, :only => { :primary => true } do
35
+ # FIXME: path, see default railsy deploy:migrate
36
+ django_manage "syncdb --noinput"
37
+ django_manage "migrate" if fetch(:django_use_south, false)
38
+ end
39
+ end
40
+
41
+ # depend :remote, :python_module, "module_name"
42
+ # runs #{python} and tries to import module_name.
43
+ class Capistrano::Deploy::RemoteDependency
44
+ def python_module(module_name, options={})
45
+ @message ||= "Cannot import `#{module_name}'"
46
+ python = configuration.fetch(:python, "python")
47
+ try("#{python} -c 'import #{module_name}'", options)
48
+ self
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ require 'capistrano'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ set :monit_group, nil
5
+ set :monit_command, "monit"
6
+
7
+ def _monit_args()
8
+ if fetch :monit_group, nil then
9
+ return " -g #{monit_group} "
10
+ else
11
+ return ""
12
+ end
13
+ end
14
+
15
+ namespace :deploy do
16
+ desc "Start processes"
17
+ task :start do
18
+ process = ENV['PROCESS'] || 'all'
19
+ sudo "#{monit_command} #{_monit_args} start #{process}"
20
+ end
21
+
22
+ desc "Stop processes"
23
+ task :stop do
24
+ process = ENV['PROCESS'] || 'all'
25
+ sudo "#{monit_command} #{_monit_args} stop #{process}"
26
+ end
27
+
28
+ desc "Restart processes"
29
+ task :restart do
30
+ process = ENV['PROCESS'] || 'all'
31
+ sudo "#{monit_command} #{_monit_args} restart #{process}"
32
+ end
33
+
34
+ namespace :status do
35
+ desc "Status summary"
36
+ task :default do
37
+ sudo "#{monit_command} #{_monit_args} summary"
38
+ end
39
+
40
+ desc "Full status"
41
+ task :full do
42
+ sudo "#{monit_command} #{_monit_args} status"
43
+ end
44
+ end
45
+
46
+ desc "Reload monit"
47
+ task :reload_monit do
48
+ sudo "#{monit_command} reload"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,94 @@
1
+ require 'capistrano'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ set :supervisord_path, ""
5
+ set :supervisord_command, "supervisord"
6
+ set :supervisorctl_command, "supervisorctl"
7
+ set :supervisord_conf, "supervisord_conf"
8
+ set :supervisord_pidfile, "supervisord.pid"
9
+ set :supervisord_start_group, nil
10
+ set :supervisord_stop_group, nil
11
+
12
+ namespace :deploy do
13
+ def supervisord_pidfile_path ; "#{shared_path}/#{supervisord_pidfile}" end
14
+ def supervisord_pid ; "`cat #{supervisord_pidfile_path}`" end
15
+
16
+ # Run supervisorctl command `cmd'.
17
+ # If options[:try_start] is true (default) and supervisord is not running, start it.
18
+ # If just started supervisord, and options[:run_when_started] is false (default), skip running supervisorctl
19
+ def supervisorctl(cmd, options={})
20
+ try_start = options.delete(:try_start) {|k| true}
21
+
22
+ full_command = "#{supervisord_path}#{supervisorctl_command} -c #{current_path}/#{supervisord_conf} #{cmd}"
23
+ after_start = (full_command if options.delete(:run_when_started)) || ""
24
+
25
+ if not try_start then
26
+ run full_command, options
27
+ else
28
+ run <<-EOF, options
29
+ if test -f #{shared_path}/#{supervisord_pidfile}
30
+ && ps #{supervisord_pid} > /dev/null ;
31
+ then
32
+ echo "supervisord seems to be up, good" ;
33
+ #{full_command} ;
34
+ else
35
+ echo "starting supervisord" ;
36
+ #{sudo :as => deploy_user} #{supervisord_path}#{supervisord_command} -c #{current_path}/#{supervisord_conf} ;
37
+ #{after_start}
38
+ fi
39
+ EOF
40
+ end
41
+ end
42
+
43
+ def _target(var)
44
+ group_name = ENV['GROUP']
45
+ group_name ||= fetch var
46
+ prog_name = ENV['PROGRAM']
47
+ prog_name ||= 'all'
48
+
49
+ if ['', nil].include? group_name then
50
+ prog_name
51
+ else
52
+ "'#{group_name}:*'"
53
+ end
54
+ end
55
+
56
+ desc "Start processes"
57
+ task :start do
58
+ to_start = _target(:supervisord_start_group)
59
+ supervisorctl "start #{to_start}", :try_start => true
60
+ end
61
+
62
+ desc "Stop processes"
63
+ task :stop do
64
+ to_stop = _target(:supervisord_stop_group)
65
+ supervisorctl "stop #{to_stop}", :try_start => false
66
+ end
67
+
68
+ desc "Restart processes"
69
+ task :restart do
70
+ to_restart = _target(:supervisord_start_group)
71
+ supervisorctl "restart #{to_restart}"
72
+ end
73
+
74
+ desc "Display status of processes"
75
+ task :status do
76
+ supervisorctl "status", :try_start => false
77
+ end
78
+
79
+ desc "Display detailed list of processes"
80
+ task :processes do
81
+ run "test -f #{supervisord_pidfile_path} && pstree -a #{supervisord_pid}"
82
+ end
83
+
84
+ desc "Reload supervisor daemon"
85
+ task :reload_supervisord do
86
+ supervisorctl "reload"
87
+ end
88
+
89
+ task :run_supervisorctl do
90
+ set_from_env_or_ask :command, "supervisorctl command: "
91
+ supervisorctl "#{command}", :try_start => false
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,20 @@
1
+ # Reset Rails-specific stuff.
2
+
3
+ require 'capistrano'
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ set :shared_children, %w()
7
+
8
+ namespace :deploy do
9
+ task :finalize_update, :except => { :no_release => true } do
10
+ if fetch(:group_writable, true)
11
+ sudo "chgrp -R #{deploy_group} #{latest_release}"
12
+ run "chmod -R g+w #{latest_release}"
13
+ end
14
+ end
15
+ task :migrate do end
16
+ task :start do end
17
+ task :stop do end
18
+ task :restart do end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # Small extensions to Capistrano
2
+
3
+ require 'capistrano'
4
+
5
+ # depend :remote, :run, "whole command with args"
6
+ # runs command, if return code <> 0, dependency fails.
7
+ class Capistrano::Deploy::RemoteDependency
8
+ def run(command, options={})
9
+ @message ||= "Cannot run `#{command}'"
10
+ try(command, options)
11
+ self
12
+ end
13
+ end
14
+
15
+ # set_from_env_or_ask :variable, "Please enter variable name: "
16
+ # If there is VARIABLE in enviroment, set :variable to it, otherwise
17
+ # ask user for a value
18
+ def set_from_env_or_ask(sym, question)
19
+ if ENV.has_key? sym.to_s.upcase then
20
+ set sym, ENV[sym.to_s.upcase]
21
+ else
22
+ set sym do Capistrano::CLI.ui.ask question end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ module CapistranoOffroad
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+ STRING = [MAJOR, MINOR, TINY].join('.')
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-offroad
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Maciej Pasternacki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-27 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Capistrano add-ons and recipes for non-rails projects
23
+ email: maciej@pasternacki.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/capistrano-offroad/modules/daemontools.rb
32
+ - lib/capistrano-offroad/modules/defaults.rb
33
+ - lib/capistrano-offroad/modules/django.rb
34
+ - lib/capistrano-offroad/modules/monit.rb
35
+ - lib/capistrano-offroad/modules/supervisord.rb
36
+ - lib/capistrano-offroad/reset.rb
37
+ - lib/capistrano-offroad/utils.rb
38
+ - lib/capistrano-offroad/version.rb
39
+ - lib/capistrano-offroad.rb
40
+ - README
41
+ - LICENSE
42
+ has_rdoc: true
43
+ homepage: http://github.com/mpasternacki/capistrano-offroad
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 23
66
+ segments:
67
+ - 1
68
+ - 3
69
+ - 6
70
+ version: 1.3.6
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Capistrano add-ons and recipes for non-rails projects
78
+ test_files: []
79
+