minicron 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/minicron.rb +3 -1
- data/lib/minicron/cli.rb +2 -1
- data/lib/minicron/cli/commands.rb +31 -16
- data/lib/minicron/constants.rb +1 -1
- data/lib/minicron/cron.rb +15 -15
- data/spec/minicron_spec.rb +1 -0
- data/spec/valid_config.toml +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4247c7b0a2874ba3c658df32d6d1dd9182e6b210
|
4
|
+
data.tar.gz: 1832c47897e9f2933a0a42e7c21476633293319a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d196437be5ebebdd185a176a8d384dd619479684927e52b35e6dc096150c4975745cbfee3cdb351aed65dfd07126c3423db27e82669cc2e3987e610b4bed1552
|
7
|
+
data.tar.gz: 3e0a20f945bd05b1474ae6b53dbc843a7035ad239028554780edda6be137d04740d803a197f5f590826bd726fe09e610e0331e7f0b7d9ba7ef12238ea2ef7b16
|
data/README.md
CHANGED
@@ -107,7 +107,7 @@ but I encourage you to give it a try in a non critical environment and help me t
|
|
107
107
|
|
108
108
|
2. On some distributions you may need to install the ````ruby-dev```` and ````build-essential```` packages
|
109
109
|
|
110
|
-
3. To install the latest release (currently 0.7.
|
110
|
+
3. To install the latest release (currently 0.7.5) you can ````gem install minicron````, depending on your ruby setup
|
111
111
|
you may need to run this with ````sudo````
|
112
112
|
|
113
113
|
4. Set your database configuration options in ````/etc/minicron.toml````, you can use the [minicron.toml](https://github.com/jamesrwhite/minicron/blob/master/config/minicron.toml) as a guide on what options are configurable
|
data/lib/minicron.rb
CHANGED
data/lib/minicron/cli.rb
CHANGED
@@ -52,14 +52,14 @@ module Minicron
|
|
52
52
|
|
53
53
|
# Add the `minicron server` command
|
54
54
|
def self.add_server_cli_command(cli)
|
55
|
-
default_pid_file = '/tmp/minicron.pid'
|
56
55
|
cli.command :server do |c|
|
57
56
|
c.syntax = 'minicron server [start|stop|restart|status]'
|
58
57
|
c.description = 'Controls the minicron server.'
|
59
58
|
c.option '--host STRING', String, "The host for the server to listen on. Default: #{Minicron.config['server']['host']}"
|
60
59
|
c.option '--port STRING', Integer, "How port for the server to listed on. Default: #{Minicron.config['server']['port']}"
|
61
60
|
c.option '--path STRING', String, "The path on the host. Default: #{Minicron.config['server']['path']}"
|
62
|
-
c.option '--pid_file STRING', String, "The path for daemon's PID file. Default: #{Minicron.config['server']['pid_file']
|
61
|
+
c.option '--pid_file STRING', String, "The path for daemon's PID file. Default: #{Minicron.config['server']['pid_file']}"
|
62
|
+
c.option '--cron_file STRING', String, "The path to the cron file. Default: #{Minicron.config['server']['cron_file']}"
|
63
63
|
c.option '--debug', "Enable debug mode. Default: #{Minicron.config['server']['debug']}"
|
64
64
|
|
65
65
|
c.action do |args, opts|
|
@@ -71,23 +71,23 @@ module Minicron
|
|
71
71
|
|
72
72
|
# Get an instance of insidious and set the pid file
|
73
73
|
insidious = Insidious.new(
|
74
|
-
:pid_file => Minicron.config['server']['pid_file']
|
74
|
+
:pid_file => Minicron.config['server']['pid_file'],
|
75
75
|
:daemonize => Minicron.config['server']['debug'] == false
|
76
76
|
)
|
77
77
|
|
78
78
|
case action
|
79
79
|
when 'start'
|
80
80
|
insidious.start! do
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
# Run the execution monitor (this runs in a separate thread)
|
82
|
+
monitor = Minicron::Monitor.new
|
83
|
+
monitor.start!
|
84
|
+
|
85
|
+
# Start the server!
|
86
|
+
Minicron::Transport::Server.start!(
|
87
|
+
Minicron.config['server']['host'],
|
88
|
+
Minicron.config['server']['port'],
|
89
|
+
Minicron.config['server']['path'],
|
90
|
+
)
|
91
91
|
end
|
92
92
|
when 'stop'
|
93
93
|
insidious.stop!
|
@@ -167,11 +167,21 @@ module Minicron
|
|
167
167
|
case output[:type]
|
168
168
|
when :status
|
169
169
|
unless Minicron.config['cli']['dry_run']
|
170
|
-
faye.send(
|
170
|
+
faye.send(
|
171
|
+
:job_id => ids[:job_id],
|
172
|
+
:execution_id => ids[:execution_id],
|
173
|
+
:type => :status,
|
174
|
+
:message => output[:output]
|
175
|
+
)
|
171
176
|
end
|
172
177
|
when :command
|
173
178
|
unless Minicron.config['cli']['dry_run']
|
174
|
-
faye.send(
|
179
|
+
faye.send(
|
180
|
+
:job_id => ids[:job_id],
|
181
|
+
:execution_id => ids[:execution_id],
|
182
|
+
:type => :output,
|
183
|
+
:message => output[:output]
|
184
|
+
)
|
175
185
|
end
|
176
186
|
end
|
177
187
|
|
@@ -180,7 +190,12 @@ module Minicron
|
|
180
190
|
rescue Exception => e
|
181
191
|
# Send the exception message to the server and yield it
|
182
192
|
unless Minicron.config['cli']['dry_run']
|
183
|
-
faye.send(
|
193
|
+
faye.send(
|
194
|
+
:job_id => ids[:job_id],
|
195
|
+
:execution_id => ids[:execution_id],
|
196
|
+
:type => :output,
|
197
|
+
:message => e.message
|
198
|
+
)
|
184
199
|
end
|
185
200
|
|
186
201
|
raise Exception, e
|
data/lib/minicron/constants.rb
CHANGED
data/lib/minicron/cron.rb
CHANGED
@@ -40,10 +40,10 @@ module Minicron
|
|
40
40
|
etc_execute = conn.exec!("/bin/sh -c 'test -x /etc && echo \"y\" || echo \"n\"'").strip
|
41
41
|
|
42
42
|
# Check if the crontab is readable
|
43
|
-
crontab_read = conn.exec!("/bin/sh -c 'test -r
|
43
|
+
crontab_read = conn.exec!("/bin/sh -c 'test -r #{Minicron.config['server']['cron_file']} && echo \"y\" || echo \"n\"'").strip
|
44
44
|
|
45
45
|
# Check if the crontab is writeable
|
46
|
-
crontab_write = conn.exec!("/bin/sh -c 'test -w
|
46
|
+
crontab_write = conn.exec!("/bin/sh -c 'test -w #{Minicron.config['server']['cron_file']} && echo \"y\" || echo \"n\"'").strip
|
47
47
|
|
48
48
|
{
|
49
49
|
:connect => true,
|
@@ -76,10 +76,10 @@ module Minicron
|
|
76
76
|
raise Exception, "Unable to connect to host, reason: unknown" if !test[:connect]
|
77
77
|
|
78
78
|
# Check the crontab is readable
|
79
|
-
raise Exception, "Insufficient permissions to read from
|
79
|
+
raise Exception, "Insufficient permissions to read from the cron file" if !test[:crontab][:read]
|
80
80
|
|
81
81
|
# Check the crontab is writeable
|
82
|
-
raise Exception, "Insufficient permissions to write to
|
82
|
+
raise Exception, "Insufficient permissions to write to the cron file" if !test[:crontab][:write]
|
83
83
|
|
84
84
|
# Check /etc is writeable
|
85
85
|
raise Exception, "/etc is not writeable by the current user" if !test[:etc][:write]
|
@@ -88,13 +88,13 @@ module Minicron
|
|
88
88
|
raise Exception, "/etc is not executable by the current user" if !test[:etc][:execute]
|
89
89
|
|
90
90
|
# Get the full crontab
|
91
|
-
crontab = conn.exec!(
|
91
|
+
crontab = conn.exec!("cat #{Minicron.config['server']['cron_file']}").to_s.strip
|
92
92
|
|
93
93
|
# Replace the full string with the replacement string
|
94
94
|
begin
|
95
95
|
crontab[find] = replace
|
96
96
|
rescue Exception => e
|
97
|
-
raise Exception, "Unable to replace '#{find}' with '#{replace}' in the
|
97
|
+
raise Exception, "Unable to replace '#{find}' with '#{replace}' in the cron file, reason: #{e}"
|
98
98
|
end
|
99
99
|
|
100
100
|
# Echo the crontab back to the tmp crontab
|
@@ -107,7 +107,7 @@ module Minicron
|
|
107
107
|
|
108
108
|
# Throw an exception if we can't see our new line at the end of the file
|
109
109
|
if grep != replace
|
110
|
-
fail Exception, "Expected to find nothing when grepping
|
110
|
+
fail Exception, "Expected to find nothing when grepping the cron file but found #{grep}"
|
111
111
|
end
|
112
112
|
else
|
113
113
|
# Check the updated line is there
|
@@ -115,15 +115,15 @@ module Minicron
|
|
115
115
|
|
116
116
|
# Throw an exception if we can't see our new line at the end of the file
|
117
117
|
if grep != replace
|
118
|
-
fail Exception, "Expected to find '#{replace}' when grepping
|
118
|
+
fail Exception, "Expected to find '#{replace}' when grepping the cron file but found #{grep}"
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
# And finally replace the crontab with the new one now we now the change worked
|
123
|
-
move = conn.exec!("/bin/sh -c 'mv /tmp/minicron_crontab
|
123
|
+
move = conn.exec!("/bin/sh -c 'mv /tmp/minicron_crontab #{Minicron.config['server']['cron_file']} && echo \"y\" || echo \"n\"'").to_s.strip
|
124
124
|
|
125
125
|
if move != 'y'
|
126
|
-
fail Exception,
|
126
|
+
fail Exception, "Unable to move /tmp/minicron_crontab to #{Minicron.config['server']['cron_file']}, check the permissions?"
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -139,13 +139,13 @@ module Minicron
|
|
139
139
|
# Prepare the line we are going to write to the crontab
|
140
140
|
line = build_minicron_command(schedule, job.user, job.command)
|
141
141
|
escaped_line = line.shellescape
|
142
|
-
echo_line = "echo #{escaped_line} >>
|
142
|
+
echo_line = "echo #{escaped_line} >> #{Minicron.config['server']['cron_file']}"
|
143
143
|
|
144
144
|
# Append it to the end of the crontab
|
145
145
|
conn.exec!(echo_line).to_s.strip
|
146
146
|
|
147
147
|
# Check the line is there
|
148
|
-
tail = conn.exec!(
|
148
|
+
tail = conn.exec!("tail -n 1 #{Minicron.config['server']['cron_file']}").to_s.strip
|
149
149
|
|
150
150
|
# Throw an exception if we can't see our new line at the end of the file
|
151
151
|
if tail != line
|
@@ -213,9 +213,9 @@ module Minicron
|
|
213
213
|
conn ||= @ssh.open
|
214
214
|
|
215
215
|
# Loop through each job and delete them one by one
|
216
|
-
# TODO: what if one
|
217
|
-
# we try and rollback somehow or just return the
|
218
|
-
#
|
216
|
+
# TODO: what if one job removal fails but others don't? Should
|
217
|
+
# we try and rollback somehow or just return the host with half its
|
218
|
+
# jobs deleted?
|
219
219
|
host.jobs.each do |job|
|
220
220
|
delete_job(job, conn)
|
221
221
|
end
|
data/spec/minicron_spec.rb
CHANGED
data/spec/valid_config.toml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minicron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|