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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 392144921cb0e216156a91d61a09cc108966a0bc
4
- data.tar.gz: 684fceac9707235b31bff2c86d6099ddc82f6d5a
3
+ metadata.gz: 4247c7b0a2874ba3c658df32d6d1dd9182e6b210
4
+ data.tar.gz: 1832c47897e9f2933a0a42e7c21476633293319a
5
5
  SHA512:
6
- metadata.gz: a381f1c8f5231e3fabaa66be75995d9254d915ff92623081225fa1ce49d7ce00e522eb790e28f9faf07a6dd4c775db86b7967536b95a998da0f12f85df6e3ec1
7
- data.tar.gz: e343cdc83191d441d5d72ba222e5886168f79ca2a8d817ae8d8b26ae0a9f02aa3a0f918cf7f5fe27356d2cd19e5474d11d0a5360348d5eca8b51c9eb601e7971
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.4) you can ````gem install minicron````, depending on your ruby setup
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
@@ -23,7 +23,9 @@ module Minicron
23
23
  'host' => '0.0.0.0',
24
24
  'port' => 9292,
25
25
  'path' => '/',
26
- 'debug' => false
26
+ 'debug' => false,
27
+ 'pid_file' => '/tmp/minicron.pid',
28
+ 'cron_file' => '/etc/crontab',
27
29
  },
28
30
  'database' => {
29
31
  'type' => 'sqlite'
data/lib/minicron/cli.rb CHANGED
@@ -41,7 +41,8 @@ module Minicron
41
41
  'port' => opts.port,
42
42
  'path' => opts.path,
43
43
  'debug' => opts.debug,
44
- 'pid_file' => opts.pid_file
44
+ 'pid_file' => opts.pid_file,
45
+ 'cron_file' => opts.cron_file
45
46
  }
46
47
  )
47
48
  end
@@ -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'] || default_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'] || default_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
- # 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
- )
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(:job_id => ids[:job_id], :execution_id => ids[:execution_id], :type => :status, :message => output[:output])
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(:job_id => ids[:job_id], :execution_id => ids[:execution_id], :type => :output, :message => output[:output])
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(:job_id => ids[:job_id], :execution_id => ids[:execution_id], :type => :output, :message => e.message)
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
@@ -1,6 +1,6 @@
1
1
  # The minicron module
2
2
  module Minicron
3
- VERSION = '0.7.4'
3
+ VERSION = '0.7.5'
4
4
  DEFAULT_CONFIG_FILE = '/etc/minicron.toml'
5
5
  BASE_PATH = File.expand_path('../../../', __FILE__)
6
6
  LIB_PATH = File.expand_path('../../', __FILE__)
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 /etc/crontab && echo \"y\" || echo \"n\"'").strip
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 /etc/crontab && echo \"y\" || echo \"n\"'").strip
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 /etc/crontab" if !test[:crontab][:read]
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 /etc/crontab" if !test[:crontab][:write]
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!('cat /etc/crontab').to_s.strip
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 crontab, reason: #{e}"
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 crontab but found #{grep}"
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 crontab but found #{grep}"
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 /etc/crontab && echo \"y\" || echo \"n\"'").to_s.strip
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, 'Unable to move /tmp/minicron_crontab to /etc/crontab, check the permissions?'
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} >> /etc/crontab"
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!('tail -n 1 /etc/crontab').to_s.strip
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 schedule removal fails but others don't? Should
217
- # we try and rollback somehow or just return the job with half its
218
- # schedules deleted?
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
@@ -79,6 +79,7 @@ describe Minicron do
79
79
  'path' => '/',
80
80
  'debug' => false,
81
81
  'pid_file' => '/tmp/minicron.pid'
82
+ 'cron_file' => '/etc/crontab'
82
83
  },
83
84
  'database' => {
84
85
  'type' => 'sqlite'
@@ -20,6 +20,7 @@ port = 9292
20
20
  path = "/"
21
21
  debug = false
22
22
  pid_file = "/tmp/minicron.pid"
23
+ cron_file = "/etc/crontab"
23
24
 
24
25
  # Database options
25
26
  [database]
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
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-03-23 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow