crontabinator 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ set :crontab_log_level, "info"
2
+ set :crontab_templates_path, "templates/crontab"
@@ -0,0 +1,24 @@
1
+ namespace :crontab do
2
+ namespace :check do
3
+
4
+ desc 'Ensure all crontabinator specific settings are set, and warn and exit if not.'
5
+ before 'crontab:setup', :settings do
6
+ {
7
+ (File.dirname(__FILE__) + "/examples/config/deploy.rb") => 'config/deploy.rb',
8
+ (File.dirname(__FILE__) + "/examples/config/deploy/staging.rb") => "config/deploy/#{fetch(:stage)}.rb"
9
+ }.each do |abs, rel|
10
+ Rake::Task['deployinator:settings'].invoke(abs, rel)
11
+ Rake::Task['deployinator:settings'].reenable
12
+ end
13
+ end
14
+
15
+ namespace :settings do
16
+ desc 'Print example crontabinator specific settings for comparison.'
17
+ task :print do
18
+ set :print_all, true
19
+ Rake::Task['crontab:check:settings'].invoke
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ module Capistrano
2
+ module TaskEnhancements
3
+ alias_method :crontab_original_default_tasks, :default_tasks
4
+ def default_tasks
5
+ crontab_original_default_tasks + [
6
+ "crontabinator:write_built_in",
7
+ "crontabinator:write_example_configs",
8
+ "crontabinator:write_example_configs:in_place"
9
+ ]
10
+ end
11
+ end
12
+ end
13
+
14
+ namespace :crontabinator do
15
+
16
+ set :example, "_example"
17
+
18
+ desc "Write example config files (with '_example' appended to their names)."
19
+ task :write_example_configs do
20
+ run_locally do
21
+ execute "mkdir", "-p", "config/deploy", fetch(:crontab_templates_path)
22
+ {
23
+ "examples/Capfile" => "Capfile#{fetch(:example)}",
24
+ "examples/config/deploy.rb" => "config/deploy#{fetch(:example)}.rb",
25
+ "examples/config/deploy/staging.rb" => "config/deploy/staging#{fetch(:example)}.rb",
26
+ "examples/crontab.erb" => "#{fetch(:crontab_templates_path)}/crontab#{fetch(:example)}.erb",
27
+ }.each do |source, destination|
28
+ config = File.read(File.dirname(__FILE__) + "/#{source}")
29
+ File.open("./#{destination}", 'w') { |f| f.write(config) }
30
+ info "Wrote '#{destination}'"
31
+ end
32
+ unless fetch(:example).empty?
33
+ info "Now remove the '#{fetch(:example)}' portion of their names or diff with existing files and add the needed lines."
34
+ end
35
+ end
36
+ end
37
+
38
+ desc 'Write example config files (will overwrite any existing config files).'
39
+ namespace :write_example_configs do
40
+ task :in_place do
41
+ set :example, ""
42
+ Rake::Task['crontabinator:write_example_configs'].invoke
43
+ end
44
+ end
45
+
46
+ desc 'Write a file showing the built-in overridable settings.'
47
+ task :write_built_in do
48
+ run_locally do
49
+ {
50
+ 'built-in.rb' => 'built-in.rb',
51
+ }.each do |source, destination|
52
+ config = File.read(File.dirname(__FILE__) + "/#{source}")
53
+ File.open("./#{destination}", 'w') { |f| f.write(config) }
54
+ info "Wrote '#{destination}'"
55
+ end
56
+ info "Now examine the file and copy-paste into your deploy.rb or <stage>.rb and customize."
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,58 @@
1
+ namespace :crontab do
2
+
3
+ desc "Idempotently setup Crontabs."
4
+ task :setup do
5
+ log_level = SSHKit.config.output_verbosity
6
+ log_level = "info" if log_level.nil?
7
+ SSHKit.config.output_verbosity = fetch(:crontab_log_level)
8
+
9
+ on roles(:cron) do |host|
10
+ fetch(:user_crontab_entries).each do |user, entries|
11
+ unless unix_user_exists?(user)
12
+ error "User #{user} does not exist even though you defined crontab settings for it - Skipping!"
13
+ else
14
+ set :crontab_entries, entries
15
+ template_path = File.expand_path("./#{fetch(:crontab_templates_path)}/crontab.erb")
16
+ generated_config_file = ERB.new(File.new(template_path).read, nil, '-').result(binding)
17
+ upload! StringIO.new(generated_config_file), "/tmp/crontab"
18
+ as :root do
19
+ execute("chown", "#{user}:#{user}", "/tmp/crontab")
20
+ end
21
+ as user do
22
+ execute "crontab", "/tmp/crontab"
23
+ end
24
+ as :root do
25
+ execute "rm", "/tmp/crontab"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ SSHKit.config.output_verbosity = log_level
31
+ end
32
+
33
+ if Rake::Task.task_defined?("deploy:publishing")
34
+ after 'deploy:publishing', 'crontab:setup'
35
+ end
36
+
37
+ desc "Check the status of the Crontabs."
38
+ task :status do
39
+ log_level = SSHKit.config.output_verbosity
40
+ log_level = "info" if log_level.nil?
41
+ SSHKit.config.output_verbosity = fetch(:crontab_log_level)
42
+
43
+ on roles(:cron) do
44
+ fetch(:user_crontab_entries).each do |user, _|
45
+ as :root do
46
+ unless unix_user_exists?(user)
47
+ error "User #{user} does not exist even though you defined crontab settings for it - Skipping!"
48
+ else
49
+ info "Crontab for user #{user}:\n#{capture "crontab", "-u", user, "-l" if test "crontab", "-u", user, "-l"}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ SSHKit.config.output_verbosity = log_level
56
+ end
57
+
58
+ end
@@ -0,0 +1,4 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ require 'crontabinator'
@@ -0,0 +1,19 @@
1
+ ##### crontabinator
2
+ ### ------------------------------------------------------------------
3
+ set :domain, "my-app.example.com"
4
+ server fetch(:domain),
5
+ :user => fetch(:deployment_username),
6
+ :roles => ["cron"]
7
+ set :user_crontab_entries, {
8
+ "www-data" => [
9
+ "SHELL=/bin/bash",
10
+ "MAILTO=myemail@example.com",
11
+ "0 */4 * * * #{current_path}/script/myscript > /dev/null"
12
+ ],
13
+ "root" => [
14
+ "SHELL=/bin/bash",
15
+ "MAILTO=myemail@example.com",
16
+ "0 */4 * * * /usr/local/bin/myscript > /dev/null"
17
+ ]
18
+ }
19
+ ### ------------------------------------------------------------------
@@ -0,0 +1,8 @@
1
+ # config valid only for Capistrano 3.2.1
2
+ lock '3.2.1'
3
+
4
+ ##### crontabinator
5
+ ### ------------------------------------------------------------------
6
+ #set :application, "my_app_name"
7
+ set :deployment_username, ENV['USER']
8
+ ### ------------------------------------------------------------------
@@ -0,0 +1,3 @@
1
+ <%- fetch(:crontab_entries).each do |entry| -%>
2
+ <%= entry %>
3
+ <%- end -%>
@@ -0,0 +1,8 @@
1
+ require 'capistrano/setup'
2
+ require 'erb'
3
+
4
+ load 'crontabinator/crontab.rb'
5
+ load 'crontabinator/config.rb'
6
+ load 'crontabinator/check.rb'
7
+ load 'crontabinator/built-in.rb'
8
+ load 'deployinator/helpers.rb'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crontabinator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - david amick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: deployinator
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.3.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.3.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: sshkit
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.1
78
+ description: Deploy Crontabs using an existing Cron Daemon
79
+ email: davidamick@ctisolutionsinc.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/crontabinator.rb
85
+ - lib/crontabinator/crontab.rb
86
+ - lib/crontabinator/config.rb
87
+ - lib/crontabinator/check.rb
88
+ - lib/crontabinator/built-in.rb
89
+ - lib/crontabinator/examples/Capfile
90
+ - lib/crontabinator/examples/config/deploy.rb
91
+ - lib/crontabinator/examples/config/deploy/staging.rb
92
+ - lib/crontabinator/examples/crontab.erb
93
+ homepage: https://github.com/snarlysodboxer/crontabinator
94
+ licenses:
95
+ - GNU
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.9.3
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements:
113
+ - Cron Daemon
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.23.2
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Deploy Crontabs
119
+ test_files: []