minicron 0.7.6 → 0.7.7

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: 4e56bf6a4890ec60c50ff3843130e356c62a4205
4
- data.tar.gz: a99ba6773693386d61f30607f2198af48704ac38
3
+ metadata.gz: f28365c7bfec3d1aee7154ca2c0d92c71c9606b3
4
+ data.tar.gz: 0764cab857b36939ca2a24482549a48fd2e5f0e8
5
5
  SHA512:
6
- metadata.gz: a5bd6f87272cd992a266bcee8b13b12cb7152f45a2ff93d9a4c32c3dd97e38e3baccd68cc107b4aa4748a8b9eeb86dd6c419a1ad6527de8819d7375535715e20
7
- data.tar.gz: cf7f3861b4efff02d9eb7e67ded6c3f1f34702825cdfe3f27c34306bc87fd63c302756e5b7839f66be30e4df76de4bd19057927425553f3073ef55ec9e00101f
6
+ metadata.gz: 68942a54bad7846305ce191398a84def24ba9ecad774edd83ab9195a148363ab4b22faa51bc1ae1eb1d198a2aa31afd6f5c4f401c997dd7be8978d7534ff9247
7
+ data.tar.gz: 11736bb3645b87ed55ae95744a61022f0044f7706c1d51071cd5aaf211929b2b6056edbd17b53059488747cc37f1b6f54faa21c339e88d44e4077d406123b235
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.6) you can ````gem install minicron````, depending on your ruby setup
110
+ 3. To install the latest release (currently 0.7.7) 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
@@ -1,6 +1,6 @@
1
1
  # The minicron module
2
2
  module Minicron
3
- VERSION = '0.7.6'
3
+ VERSION = '0.7.7'
4
4
  DEFAULT_CONFIG_FILE = '/etc/minicron.toml'
5
5
  BASE_PATH = File.expand_path('../../../', __FILE__)
6
6
  LIB_PATH = File.expand_path('../../', __FILE__)
@@ -149,7 +149,7 @@ module Minicron
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
152
- fail Exception, "Expected to find '#{line}' at eof but found '#{tail}'"
152
+ fail Exception, "Expected to find '#{line}' at EOF but found '#{tail}'"
153
153
  end
154
154
  end
155
155
 
@@ -173,6 +173,31 @@ module Minicron
173
173
  find_and_replace(conn, find, replace)
174
174
  end
175
175
 
176
+ # Update the user for a job and all its schedules
177
+ #
178
+ # @param job [Minicron::Hub::Job] an instance of a job model including the schedule relation
179
+ # @param old_user [String] the old job user as a string
180
+ # @param new_user [String] the new job user as a string
181
+ # @param conn an instance of an open ssh connection
182
+ def update_user(job, old_user, new_user, conn = nil)
183
+ conn ||= @ssh.open
184
+
185
+ # Loop through each schedule and delete them one by one
186
+ # TODO: what if one schedule update fails but others don't? Should
187
+ # we try and rollback somehow or just return the job with half its
188
+ # schedules deleted?
189
+ job.schedules.each do |schedule|
190
+ # We are looking for the current value of the schedule
191
+ find = build_minicron_command(schedule.formatted, old_user, job.command)
192
+
193
+ # And replacing it with the updated value
194
+ replace = build_minicron_command(schedule.formatted, new_user, job.command)
195
+
196
+ # Replace the old schedule with the new schedule
197
+ find_and_replace(conn, find, replace)
198
+ end
199
+ end
200
+
176
201
  # Remove the schedule for this job from the crontab
177
202
  #
178
203
  # @param job [Minicron::Hub::Job] an instance of a job model
@@ -23,14 +23,15 @@
23
23
 
24
24
  function testConnection(self, host) {
25
25
  self.set('test_connection', 'Testing..');
26
+ var path_prefix = window.config.path === '/' ? '' : window.config.path;
26
27
 
27
- jQuery.getJSON(window.config.path + '/api/hosts/' + host.id + '/test_ssh').done(function(data) {
28
+ jQuery.getJSON(path_prefix + '/api/hosts/' + host.id + '/test_ssh').done(function(data) {
28
29
  // Could we at least connect to the host?
29
30
  if (data.connect) {
30
31
  // TODO: make this use a bootstrap model as a component
31
32
  var results = 'Test Results\n\n';
32
33
  results += 'connect: ' + data.connect + '\n';
33
- results += '/etc writeable: ' + data.etc.write + '\n';
34
+ results += '/etc writeable: ' + data.etc.write + '\n';
34
35
  results += '/etc executable: ' + data.etc.execute + '\n';
35
36
  results += 'crontab readable: ' + data.crontab.read + '\n';
36
37
  results += 'crontab writeable: ' + data.crontab.write;
@@ -58,21 +58,45 @@ class Minicron::Hub::App
58
58
  put '/api/jobs/:id' do
59
59
  content_type :json
60
60
  begin
61
- # Load the JSON body
62
- request_body = Oj.load(request.body)
61
+ Minicron::Hub::Job.transaction do
62
+ # Load the JSON body
63
+ request_body = Oj.load(request.body)
63
64
 
64
- # Find the job
65
- job = Minicron::Hub::Job.includes(:host, :schedules, :executions => :job_execution_outputs)
66
- .find(params[:id])
65
+ # Find the job
66
+ job = Minicron::Hub::Job.includes(:host, :schedules, :executions => :job_execution_outputs)
67
+ .find(params[:id])
67
68
 
68
- # Update the name and user
69
- job.name = request_body['job']['name']
70
- job.user = request_body['job']['user']
69
+ # Store a copy of the current job user in case we need to change it
70
+ old_user = job.user
71
71
 
72
- job.save!
72
+ # Update the name and user
73
+ job.name = request_body['job']['name']
74
+ job.user = request_body['job']['user']
73
75
 
74
- # Return the new job
75
- Minicron::Hub::JobSerializer.new(job).serialize.to_json
76
+ # Only update the job user if it has changed
77
+ if old_user != job.user
78
+ ssh = Minicron::Transport::SSH.new(
79
+ :user => job.host.user,
80
+ :host => job.host.host,
81
+ :port => job.host.port,
82
+ :private_key => "~/.ssh/minicron_host_#{job.host.id}_rsa"
83
+ )
84
+
85
+ # Get an instance of the cron class
86
+ cron = Minicron::Cron.new(ssh)
87
+
88
+ # Update the job schedules in the crontab
89
+ cron.update_user(job, old_user, job.user)
90
+
91
+ # Tidy up
92
+ ssh.close
93
+ end
94
+
95
+ job.save!
96
+
97
+ # Return the new job
98
+ Minicron::Hub::JobSerializer.new(job).serialize.to_json
99
+ end
76
100
  # TODO: nicer error handling here with proper validation before hand
77
101
  rescue Exception => e
78
102
  status 422
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.6
4
+ version: 0.7.7
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-05-09 00:00:00.000000000 Z
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -104,20 +104,20 @@ dependencies:
104
104
  requirements:
105
105
  - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: '0.1'
107
+ version: '0.3'
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.1.4
110
+ version: 0.3.8
111
111
  type: :runtime
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.1'
117
+ version: '0.3'
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
- version: 0.1.4
120
+ version: 0.3.8
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: sinatra
123
123
  requirement: !ruby/object:Gem::Requirement