minicron 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -43
  3. data/Rakefile +9 -1
  4. data/lib/minicron.rb +9 -4
  5. data/lib/minicron/alert.rb +2 -1
  6. data/lib/minicron/alert/email.rb +7 -2
  7. data/lib/minicron/alert/pagerduty.rb +3 -2
  8. data/lib/minicron/alert/sms.rb +2 -1
  9. data/lib/minicron/cli.rb +49 -19
  10. data/lib/minicron/constants.rb +2 -1
  11. data/lib/minicron/cron.rb +6 -6
  12. data/lib/minicron/hub/app.rb +8 -8
  13. data/lib/minicron/hub/assets/app/controllers/executions.js +4 -3
  14. data/lib/minicron/hub/assets/app/controllers/hosts.js +4 -4
  15. data/lib/minicron/hub/assets/app/controllers/jobs.js +4 -4
  16. data/lib/minicron/hub/assets/app/controllers/schedules.js +4 -1
  17. data/lib/minicron/hub/controllers/api/executions.rb +4 -4
  18. data/lib/minicron/hub/controllers/api/hosts.rb +18 -5
  19. data/lib/minicron/hub/controllers/api/job_execution_outputs.rb +2 -2
  20. data/lib/minicron/hub/controllers/api/jobs.rb +8 -8
  21. data/lib/minicron/hub/controllers/api/schedule.rb +10 -10
  22. data/lib/minicron/hub/db/schema.rb +70 -65
  23. data/lib/minicron/hub/db/schema.sql +53 -25
  24. data/lib/minicron/hub/models/execution.rb +1 -1
  25. data/lib/minicron/hub/models/host.rb +10 -1
  26. data/lib/minicron/hub/models/job.rb +3 -3
  27. data/lib/minicron/hub/models/schedule.rb +1 -1
  28. data/lib/minicron/hub/serializers/execution.rb +61 -57
  29. data/lib/minicron/hub/serializers/host.rb +49 -42
  30. data/lib/minicron/hub/serializers/job.rb +82 -78
  31. data/lib/minicron/hub/serializers/job_execution_output.rb +42 -38
  32. data/lib/minicron/hub/serializers/schedule.rb +56 -52
  33. data/lib/minicron/hub/views/handlebars/executions.erb +7 -1
  34. data/lib/minicron/hub/views/handlebars/hosts.erb +2 -2
  35. data/lib/minicron/hub/views/handlebars/schedules.erb +3 -3
  36. data/lib/minicron/monitor.rb +4 -4
  37. data/lib/minicron/transport/client.rb +6 -6
  38. data/lib/minicron/transport/faye/client.rb +4 -4
  39. data/lib/minicron/transport/faye/extensions/job_handler.rb +3 -2
  40. data/lib/minicron/transport/faye/server.rb +1 -0
  41. data/lib/minicron/transport/server.rb +2 -2
  42. data/lib/minicron/transport/ssh.rb +6 -8
  43. data/spec/minicron/cli_spec.rb +4 -4
  44. data/spec/minicron/transport/client_spec.rb +2 -2
  45. data/spec/minicron/transport/faye/client_spec.rb +7 -7
  46. data/spec/minicron/transport/server_spec.rb +1 -1
  47. data/spec/minicron_spec.rb +2 -1
  48. data/spec/valid_config.toml +1 -0
  49. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60fca4e316aa04aa9af9e988a25aac6f52bee585
4
- data.tar.gz: 77a60882f414259f240a49d9b780c7b82a162ac0
3
+ metadata.gz: aa2c40fa9887bb6c06b46153ba397a13806ed4f9
4
+ data.tar.gz: e1fc6d9b267c3e0a21727328f25922ecffeae9e4
5
5
  SHA512:
6
- metadata.gz: 3af6cc620890e0883e5c8541f19a39694d964f0bfddddd384a9c3ec123548e4f3b815390212079efd68b6ccca692b7ca636682ae3b0f9fe8bf2dc006b031c4a6
7
- data.tar.gz: 8732f37eba792dee23ac23f12543301dd231ab3d67f912c51679fd1f77a6b9ef98af0a80d9530fd93c03b3cf7e683e2f51dc16c30112dc8a90767b3ffac7d458
6
+ metadata.gz: 3f8fa7cdcd2a80623bbf1a0c3f266e575f9c3da024325579e96b65a523158212ac879ced4cffa834a11f150c14c3bfce48d921b90004ec380a5629779af89e14
7
+ data.tar.gz: 3e48387f403abbf3b34d1efd85bb4f3d33aec113a20abfce5336c6e801794d9a49a6f0e00e7844af12e4aa87a298de04632a6a2bffaf13b8686519ae790e34b7
data/README.md CHANGED
@@ -1,12 +1,20 @@
1
1
  minicron
2
2
  =======
3
3
 
4
- [![Gem Version](http://img.shields.io/gem/v/minicron.svg)](https://rubygems.org/gems/minicron) [![Build Status](http://img.shields.io/travis/jamesrwhite/minicron.svg)](http://travis-ci.org/jamesrwhite/minicron) [![Coverage Status](http://img.shields.io/coveralls/jamesrwhite/minicron.svg)](https://coveralls.io/r/jamesrwhite/minicron?branch=master) [![Code Climate](http://img.shields.io/codeclimate/github/jamesrwhite/minicron.svg)](https://codeclimate.com/github/jamesrwhite/minicron) [![Dependency Status](http://img.shields.io/gemnasium/jamesrwhite/minicron.svg)](https://gemnasium.com/jamesrwhite/minicron) [![Inline docs](http://inch-pages.github.io/github/jamesrwhite/minicron.png)](http://inch-pages.github.io/github/jamesrwhite/minicron)
5
-
6
- minicron aims to complement ````cron```` by making it easier to manage and monitor cron jobs, it can largely be thought of as two components that interact together, the CLI and the Hub. The CLI is what is installed on your server(s) and executes your cron command and reports the status back to the Hub. The Hub is the central point where data from one or many instances of the CLI are is recieved and stored in a database. The Hub also provides a web interface to the data and makes it easy to manage your cron jobs.
4
+ [![Gem Version](http://img.shields.io/gem/v/minicron.svg)](https://rubygems.org/gems/minicron)
5
+ [![Build Status](http://img.shields.io/travis/jamesrwhite/minicron.svg)](http://travis-ci.org/jamesrwhite/minicron)
6
+ [![Coverage Status](http://img.shields.io/coveralls/jamesrwhite/minicron.svg)](https://coveralls.io/r/jamesrwhite/minicron?branch=master)
7
+ [![Code Climate](http://img.shields.io/codeclimate/github/jamesrwhite/minicron.svg)](https://codeclimate.com/github/jamesrwhite/minicron)
8
+ [![Dependency Status](http://img.shields.io/gemnasium/jamesrwhite/minicron.svg)](https://gemnasium.com/jamesrwhite/minicron)
9
+ [![Inline docs](http://inch-pages.github.io/github/jamesrwhite/minicron.png)](http://inch-pages.github.io/github/jamesrwhite/minicron)
10
+
11
+ minicron aims to complement ````cron```` by making it easier to manage and monitor cron jobs, it can largely be
12
+ thought of as two components that interact together, the CLI and the Hub. The CLI is what is installed on your
13
+ server(s) and executes your cron command and reports the status back to the Hub. The Hub is the central point
14
+ where data from one or many instances of the CLI are is recieved and stored in a database. The Hub also provides
15
+ a web interface to the data and makes it easy to manage your cron jobs.
7
16
 
8
17
  - [Background](https://github.com/jamesrwhite/minicron/blob/master/README.md#background)
9
- - [Goals](https://github.com/jamesrwhite/minicron/blob/master/README.md#features)
10
18
  - [Features](https://github.com/jamesrwhite/minicron/blob/master/README.md#goals)
11
19
  - [Requirements](https://github.com/jamesrwhite/minicron/blob/master/README.md#requirements)
12
20
  - [Installation](https://github.com/jamesrwhite/minicron/blob/master/README.md#installation)
@@ -20,17 +28,9 @@ minicron aims to complement ````cron```` by making it easier to manage and monit
20
28
  Background
21
29
  -----------
22
30
 
23
- I'm developing minicron as part of my dissertation at university which is due in May but I plan to continue development after that. My inspiration for developing minicron comes from time spent working at [Miniclip](http://www.miniclip.com) where the management and monitoring of cron jobs at times proved to be tricky!
24
-
25
- Goals
26
- ------
27
-
28
- Some rough goals that minicron is trying to achieve.
29
-
30
- - Remove the need to understand cron syntax
31
- - Increase visiblity into cron failures and missed executions
32
- - Have minimal external dependencies
33
- - Fault tolerance
31
+ I'm developing minicron as part of my dissertation at university which is due in May but I plan to continue
32
+ development after that. My inspiration for developing minicron comes from time spent working at
33
+ [Miniclip](http://www.miniclip.com) where the management and monitoring of cron jobs at times proved to be tricky!
34
34
 
35
35
  Features
36
36
  ---------
@@ -51,10 +51,9 @@ Requirements
51
51
  -------------
52
52
 
53
53
  #### Ruby
54
- - MRI
55
- - 1.9.3 and above (tested on 1.9.3, 2.0.0, 2.1.0)
56
- - <del>Rubinius</del>
57
- - <del>Travis builds are run on the latest release</del> [*awaiting bug fix*](https://github.com/rubinius/rubinius/issues/2944)
54
+ - **MRI**: 1.9.3 and above (tested on 1.9.3, 2.0.0, 2.1.0)
55
+ - <del>**Rubinius**: Travis builds are run on the latest release</del> [*awaiting bug fix*](https://github.com/rubinius/rubinius/issues/2944)
56
+ - **JRuby:** currently untested but most likely needs some workn
58
57
 
59
58
  #### Database
60
59
 
@@ -63,11 +62,13 @@ Requirements
63
62
 
64
63
  #### Web Server / Reverse Proxy
65
64
 
66
- If you want to run minicron behind a web server or proxy it needs to support the web socket protocol. nginx for example supports web sockets from version 1.3.13 and up.
65
+ If you want to run minicron behind a web server or proxy it needs to support the web socket protocol.
66
+ nginx for example supports web sockets from version 1.3.13 and up. I've included an [example config](https://github.com/jamesrwhite/minicron/blob/master/sample.nginx.conf) for nginx.
67
67
 
68
68
  #### Browser
69
69
 
70
- I have been testing the web interface in the latest versions of Chrome, Firefox and Safari. I'm currently unsure of how it functions in the various of Internet Explorer but in theory it should support IE9+
70
+ I have been testing the web interface in the latest versions of Chrome, Firefox and Safari.
71
+ I'm currently unsure of how it functions in the various of Internet Explorer but in theory it should support IE9+
71
72
 
72
73
  #### OS
73
74
 
@@ -76,61 +77,111 @@ Should run on any linux/bsd based OS that the above ruby versions run on.
76
77
  Installation
77
78
  -------------
78
79
 
79
- minicron is currently under heavy development and as such I would not recommend that you use this in production yet but I encourage you to give it a try in a non critical environment and help me improve it.
80
+ minicron is currently under heavy development and as such I would not recommend that you use this in production yet
81
+ but I encourage you to give it a try in a non critical environment and help me to improve it.
82
+
83
+ 1. First check you meet the [requirements](https://github.com/jamesrwhite/minicron/blob/master/README.md#requirements)
84
+
85
+ 2. On some distributions you may need to install the ````ruby-dev```` and ````build-essential```` packages
80
86
 
81
- To install the latest release (currently 0.1.1) you can ````gem install minicron````.
87
+ 3. To install the latest release (currently 0.2) you can ````gem install minicron````, depending on your ruby setup
88
+ you may need to run this with ````sudo````
82
89
 
83
- #### Database Setup
90
+ 4. Set your database configuration options in ````/etc/minicron.toml````, you can use the [default.config.toml](https://github.com/jamesrwhite/minicron/blob/master/default.config.toml) as a guide on what options are configurable
84
91
 
85
- Set your database configuration options in ````/etc/minicron.toml````, you can use the [default.config.toml](https://github.com/jamesrwhite/minicron/blob/master/default.config.toml) as a guide on what options are configurable. You can then ````minicron db setup````
92
+ 5. Make sure you have created an empty database with the name you set in ````/etc/minicron.toml````
86
93
 
87
- > **WARNING** this will drop any existing tables of the same name in the configured database and create new ones
94
+ > **WARNING**
95
+ >
96
+ > the step below will drop any existing tables in the configured database and create new ones i.e:
97
+ > ````sql
98
+ > DROP TABLE IF EXISTS jobs; CREATE TABLE jobs ..
99
+ > ````
88
100
 
89
- or set it up manually using the [schema dump provided](https://github.com/jamesrwhite/minicron/blob/master/lib/minicron/hub/db/schema.sql).
101
+ 6. You can then ````minicron db setup```` to create the database schema, alternatively you can use
102
+ the [schema dump provided](https://github.com/jamesrwhite/minicron/blob/master/lib/minicron/hub/db/schema.sql)
103
+
104
+ 7. Done! See the usage section below for more details on how to use minicron now you have it installed
90
105
 
91
106
  Usage
92
107
  -----
93
108
 
94
- minicron is packaged as a gem and can be interacted with from the command line once you have installed it. The current commands are as follows:
95
-
96
109
  #### Run a command
97
110
 
98
- ````
99
- minicron run 'command --options'
111
+ ````bash
112
+ minicron run 'mysqldump db > backup.sql'
100
113
  ````
101
114
 
102
- You can alter the way in which the command alters it's output by passing the --mode option to the run argument with the value of either 'line' or 'char'. Most of the time you'll want to use the default value of line but for some commands e.g a script that outputs a progress bar minicron printing the output each character at a time can be useful.
115
+ The global ````--verbose```` option can also be passed to the ````run```` argument like so
103
116
 
117
+ ````bash
118
+ minicron run --verbose ls
104
119
  ````
105
- minicron run 'mysqldump db > backup.sql'
120
+
121
+ You can also run a command in 'dry run' mode to test if it works without sending the output to the server.
122
+
123
+ ````bash
124
+ minicron run --dry-run 'zip -r backup.zip website'
106
125
  ````
107
126
 
108
- The global ````--verbose```` option can also be passed to the ````run```` argument like so ````minicron run --verbose ls````, for further information see ````minicron help run````.
127
+ for further information see ````minicron help run````.
109
128
 
110
129
  #### Get help
111
130
 
112
- Running ````minicron```` with no arguments is an alias to running ````minicron help````, ````minicron -h```` or ````minicron --help````. You can also use the help argument to get information on any command as shown above in the run a command section or alternatively you can pass the ````-h```` or ````--help```` options like so ````minicron run -h````.
131
+ Running ````minicron```` with no arguments is an alias to running ````minicron help````, ````minicron -h```` or ````minicron --help````.
132
+ You can also use the help argument to get information on any command as shown above in the run a command section
133
+ or alternatively you can pass the ````-h```` or ````--help```` options like so ````minicron run -h````.
113
134
 
114
135
  #### Server
115
136
 
116
- To launch the server (aka the Hub) run ````minicron server```` - by default it will bind to port 9292 on the host 127.0.0.1 but this can be configured by the command line arguments ````--host```` ````--port```` and ````--path```` or in the config file.
137
+ To launch the server (aka the Hub) run
138
+
139
+ ````bash
140
+ minicron server start
141
+ ````
142
+
143
+ by default it will bind to port 9292 on the host 127.0.0.1 but this can be configured by the command line
144
+ arguments ````--host```` ````--port```` and ````--path```` or in the config file.
117
145
 
118
- See [sample.nginx.conf](https://github.com/jamesrwhite/minicron/blob/master/sample.nginx.conf) for an example of how to run minicron behind a reverse proxy. It should be possible to run minicron behind any web server/reverse proxy as long as it supports WebSockets.
146
+ By default the server will run as a daemon with its process id stored in ````/tmp/minicron.pid````
147
+ you can also use the ````stop```` ````restart```` and ````status```` commands to control the server.
148
+
149
+ To run the server in debug mode, i.e not as a daemon so you can see its output you can pass the ````--debug````
150
+ option.
151
+
152
+ See [sample.nginx.conf](https://github.com/jamesrwhite/minicron/blob/master/sample.nginx.conf) for an example of
153
+ how to run minicron behind a reverse proxy.
154
+
155
+ #### Connecting to a host via SSH
156
+
157
+ To be able to perform CRUD operations on the crontab minicron needs to connect via SSH to the host.
158
+ When you set up a host minicron automatically creates a public/private key pair for you and stores it
159
+ in ````~/.ssh```` on the host the minicron server is being run on using the naming schema ````minicron_host_*HOST_ID*_rsa(.pub)````.
160
+ To be able edit the crontab on a host minicron *needs* to connect to the host as the root user so you will
161
+ need to to copy the public key to the hosts authorized_keys file e.g ````/root/.ssh/authorized_keys```` on
162
+ most linux distributions or ````/var/root/.ssh/authorized_keys```` on OSX.
119
163
 
120
164
  #### Version
121
165
 
122
- Like many command line programs minicron will show it's version number when the global options ````-v```` or ````--version```` are passed to the CLI.
166
+ Like many command line programs minicron will show it's version number when the global options ````-v````
167
+ or ````--version```` are passed to the CLI.
123
168
 
124
169
  #### Configuration
125
170
 
126
- Some configuration options can be passed in manually but the recommend way to configure minicron is through the use of a config file. You can specify the path to the file using the ````--config```` global option. The file is expected to be in the [toml](https://github.com/mojombo/toml "toml") format. The default options are specified in the [default.config.toml](https://github.com/jamesrwhite/minicron/blob/master/default.config.toml "default.config.toml") file and minicron will parse a config located in ````/etc/minicron.toml```` if it exists. Options specified via the command line will take precedence over those taken from a config file.
171
+ Some configuration options can be passed in manually but the recommend way to configure minicron is through the use
172
+ of a config file. You can specify the path to the file using the ````--config```` global option. The file is expected
173
+ to be in the [toml](https://github.com/mojombo/toml "toml") format. The default options are specified in the
174
+ [default.config.toml](https://github.com/jamesrwhite/minicron/blob/master/default.config.toml "default.config.toml")
175
+ file and minicron will parse a config located in ````/etc/minicron.toml```` if it exists. Options specified via
176
+ the command line will take precedence over those taken from a config file.
127
177
 
128
178
  Documentation
129
179
  -------------
130
180
 
131
- minicron uses [Yard](http://yardoc.org/ "Yard") for it's code documentation, you can either generate it and view it locally using the following commands:
181
+ minicron uses [Yard](http://yardoc.org/ "Yard") for it's code documentation, you can either generate it and view
182
+ it locally using the following commands:
132
183
 
133
- ````
184
+ ````bash
134
185
  yard doc
135
186
  yard server
136
187
  ````
@@ -163,8 +214,10 @@ Areas that I would love some help with:
163
214
  - General testing of the system, let me know what you think and create issues for any bugs you find!
164
215
  - Tests!!
165
216
  - Validation and error handling improvements
166
- - Documentation improvements. Find something confusing or unexpected, let me know and I'll add or improve documentation for it!
167
- - Look for '[TODO:](https://github.com/jamesrwhite/minicron/search?q=TODO%3A)' notices littered around the code, I'm trying to convert them all to issues but there are a lot..
217
+ - Documentation improvements. Find something confusing or unexpected, let me know and I'll add or improve
218
+ documentation for it!
219
+ - Look for '[TODO:](https://github.com/jamesrwhite/minicron/search?q=TODO%3A)' notices littered around the code,
220
+ I'm trying to convert them all to issues but there are a lot..
168
221
  - Code refactoring, I had a reasonably tight deadline to have the main concept done by so some parts are a bit rushed
169
222
  - UI improvements
170
223
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'sinatra/activerecord/rake'
4
- require 'minicron'
4
+ require 'minicron/constants'
5
5
  require 'minicron/hub/app'
6
6
 
7
7
  # rspec tests
@@ -15,3 +15,11 @@ end
15
15
  task :default do
16
16
  puts `rake --tasks`
17
17
  end
18
+
19
+ namespace :db do
20
+ # Tell active record where the db dir is
21
+ Sinatra::ActiveRecordTasks.db_dir = Minicron::HUB_PATH + '/db'
22
+
23
+ # Connect to the DB
24
+ Minicron::Hub::App.setup_db
25
+ end
@@ -23,7 +23,8 @@ module Minicron
23
23
  'server' => {
24
24
  'host' => '127.0.0.1',
25
25
  'port' => 9292,
26
- 'path' => '/'
26
+ 'path' => '/',
27
+ 'debug' => false
27
28
  },
28
29
  'database' => {
29
30
  'type' => 'mysql',
@@ -41,7 +42,12 @@ module Minicron
41
42
  'enabled' => false,
42
43
  'smtp' => {
43
44
  'address' => 'localhost',
44
- 'port' => 25
45
+ 'port' => 25,
46
+ 'domain' => 'localhost.localdomain',
47
+ 'user_name' => nil,
48
+ 'password' => nil,
49
+ 'authentication' => nil,
50
+ 'enable_starttls_auto' => true
45
51
  }
46
52
  },
47
53
  'sms' => {
@@ -68,7 +74,7 @@ module Minicron
68
74
  rescue Errno::ENOENT
69
75
  # Fail if the file doesn't exist unless it's the default config file
70
76
  if file_path != DEFAULT_CONFIG_FILE
71
- fail Exception, "Unable to the load the file '#{file_path}', are you sure it exists?"
77
+ raise Exception, "Unable to the load the file '#{file_path}', are you sure it exists?"
72
78
  end
73
79
  rescue Errno::EACCES
74
80
  fail Exception, "Unable to the readthe file '#{file_path}', check it has the right permissions."
@@ -152,7 +158,6 @@ module Minicron
152
158
  filename
153
159
  end
154
160
 
155
-
156
161
  # Used to generate SSH keys for hosts but is completely generic
157
162
  #
158
163
  # @param type [String] the thing that is using the key, this is just here
@@ -5,6 +5,7 @@ require 'minicron/hub/models/alert'
5
5
  require 'minicron/hub/models/job'
6
6
 
7
7
  module Minicron
8
+ # Allows the sending of alerts via multiple mediums
8
9
  class Alert
9
10
  # Send an alert using all enabled mediums
10
11
  #
@@ -50,7 +51,7 @@ module Minicron
50
51
  when 'pagerduty'
51
52
  send_pagerduty(options)
52
53
  else
53
- raise Exception, "The medium '#{options[:medium]}' is not supported!"
54
+ fail Exception, "The medium '#{options[:medium]}' is not supported!"
54
55
  end
55
56
 
56
57
  # Store that we sent the alert
@@ -1,6 +1,7 @@
1
1
  require 'mail'
2
2
 
3
3
  module Minicron
4
+ # Allows the sending of email alerts
4
5
  class Email
5
6
  # Configure the mail client
6
7
  def initialize
@@ -8,7 +9,11 @@ module Minicron
8
9
  delivery_method(
9
10
  :smtp,
10
11
  :address => Minicron.config['alerts']['email']['smtp']['address'],
11
- :port => Minicron.config['alerts']['email']['smtp']['port']
12
+ :port => Minicron.config['alerts']['email']['smtp']['port'],
13
+ :domain => Minicron.config['alerts']['email']['smtp']['domain'],
14
+ :user_name => Minicron.config['alerts']['email']['smtp']['user_name'],
15
+ :password => Minicron.config['alerts']['email']['smtp']['password'],
16
+ :enable_starttls_auto => Minicron.config['alerts']['email']['smtp']['enable_starttls_auto']
12
17
  )
13
18
  end
14
19
  end
@@ -28,7 +33,7 @@ module Minicron
28
33
  when 'fail'
29
34
  "Execution ##{options[:execution_id]} of Job ##{options[:job_id]} '#{options[:job].name}' failed."
30
35
  else
31
- raise Exception, "The kind '#{options[:kind]} is not supported!"
36
+ fail Exception, "The kind '#{options[:kind]} is not supported!"
32
37
  end
33
38
  end
34
39
 
@@ -1,6 +1,7 @@
1
1
  require 'pagerduty'
2
2
 
3
3
  module Minicron
4
+ # Allows the sending of pagerduty alerts
4
5
  class PagerDuty
5
6
  # Used to set up on the pagerduty client
6
7
  def initialize
@@ -24,7 +25,7 @@ module Minicron
24
25
  when 'fail'
25
26
  "Execution ##{options[:execution_id]} of Job ##{options[:job_id]} failed"
26
27
  else
27
- raise Exception, "The kind '#{options[:kind]} is not supported!"
28
+ fail Exception, "The kind '#{options[:kind]} is not supported!"
28
29
  end
29
30
  end
30
31
 
@@ -33,7 +34,7 @@ module Minicron
33
34
  # @param title [String]
34
35
  # @param message [String]
35
36
  def send(title, message)
36
- @client.trigger(title, { :message => message })
37
+ @client.trigger(title, :message => message)
37
38
  end
38
39
  end
39
40
  end
@@ -1,6 +1,7 @@
1
1
  require 'twilio-ruby'
2
2
 
3
3
  module Minicron
4
+ # Allows the sending of SMS alerts via Twilio
4
5
  class SMS
5
6
  # Used to set up on the twilio client
6
7
  def initialize
@@ -27,7 +28,7 @@ module Minicron
27
28
  when 'fail'
28
29
  "minicron alert - job failed!\nExecution ##{options[:execution_id]} of Job ##{options[:job_id]} failed"
29
30
  else
30
- raise Exception, "The kind '#{options[:kind]} is not supported!"
31
+ fail Exception, "The kind '#{options[:kind]} is not supported!"
31
32
  end
32
33
  end
33
34
 
@@ -2,6 +2,7 @@ require 'pty'
2
2
  require 'English'
3
3
  require 'rainbow/ext/string'
4
4
  require 'commander'
5
+ require 'insidious'
5
6
  require 'minicron/constants'
6
7
  require 'minicron/transport'
7
8
  require 'minicron/transport/client'
@@ -11,6 +12,8 @@ require 'minicron/monitor'
11
12
  include Commander::UI
12
13
 
13
14
  module Minicron
15
+ # Handles the main CLI interaction of minicron
16
+ # TODO: this class is probably too complicated and should be refactored a bit
14
17
  class CLI
15
18
  # Function to the parse the config of the options passed to commands
16
19
  #
@@ -32,7 +35,8 @@ module Minicron
32
35
  'server' => {
33
36
  'host' => opts.host,
34
37
  'port' => opts.port,
35
- 'path' => opts.path
38
+ 'path' => opts.path,
39
+ 'debug' => opts.debug
36
40
  }
37
41
  )
38
42
  end
@@ -128,9 +132,7 @@ module Minicron
128
132
  end
129
133
  end
130
134
  rescue Errno::ENOENT
131
- exit_status = 1
132
-
133
- fail Exception, "Running the command `#{command}` failed, are you sure it exists?"
135
+ raise Exception, "Running the command `#{command}` failed, are you sure it exists?"
134
136
  ensure
135
137
  # Record the time the command finished
136
138
  finish = Time.now.utc - subtract_total
@@ -142,7 +144,7 @@ module Minicron
142
144
 
143
145
  # Output some debug info
144
146
  if options[:verbose]
145
- yield structured :verbose, "\n" + "[minicron]".colour(:magenta)
147
+ yield structured :verbose, "\n" + '[minicron]'.colour(:magenta)
146
148
  yield structured :verbose, ' finished running '.colour(:blue) + "`#{command}`".colour(:yellow) + " at #{start}\n".colour(:blue)
147
149
  yield structured :verbose, '[minicron]'.colour(:magenta)
148
150
  yield structured :verbose, ' running '.colour(:blue) + "`#{command}`".colour(:yellow) + " took #{finish - start}s\n".colour(:blue)
@@ -233,11 +235,26 @@ module Minicron
233
235
  ids
234
236
  end
235
237
 
238
+ # Start the server and monitor
239
+ def start_server
240
+ # Run the execution monitor (this runs in a separate thread)
241
+ monitor = Minicron::Monitor.new
242
+ monitor.start!
243
+
244
+ # Start the server!
245
+ server = Minicron::Transport::Server.new
246
+ server.start!(
247
+ Minicron.config['server']['host'],
248
+ Minicron.config['server']['port'],
249
+ Minicron.config['server']['path']
250
+ )
251
+ end
252
+
236
253
  # Add the `minicron db` command
237
254
  def add_db_cli_command
238
255
  @cli.command :db do |c|
239
- c.syntax = 'minicron db [setup|dump]'
240
- c.description = 'Loads or dumps the minicron database schema.'
256
+ c.syntax = 'minicron db [setup]'
257
+ c.description = 'Sets up the minicron database schema.'
241
258
 
242
259
  c.action do |args, opts|
243
260
  # Check that exactly one argument has been passed
@@ -271,27 +288,40 @@ module Minicron
271
288
  # Add the `minicron server` command
272
289
  def add_server_cli_command
273
290
  @cli.command :server do |c|
274
- c.syntax = 'minicron server'
275
- c.description = 'Starts the minicron server.'
291
+ c.syntax = 'minicron server [start|stop|restart|status]'
292
+ c.description = 'Controls the minicron server.'
276
293
  c.option '--host STRING', String, "The host for the server to listen on. Default: #{Minicron.config['server']['host']}"
277
294
  c.option '--port STRING', Integer, "How port for the server to listed on. Default: #{Minicron.config['server']['port']}"
278
295
  c.option '--path STRING', String, "The path on the host. Default: #{Minicron.config['server']['path']}"
296
+ c.option '--debug', "Enable debug mode. Default: #{Minicron.config['server']['debug']}"
279
297
 
280
298
  c.action do |args, opts|
281
299
  # Parse the file and @cli config options
282
300
  parse_config(opts)
283
301
 
284
- # Run the execution monitor (this runs in a separate thread)
285
- monitor = Minicron::Monitor.new
286
- monitor.start!
302
+ # If we get no arguments then default the action to start
303
+ action = args.first.nil? ? 'start' : args.first
287
304
 
288
- # Start the server!
289
- server = Minicron::Transport::Server.new
290
- server.start!(
291
- Minicron.config['server']['host'],
292
- Minicron.config['server']['port'],
293
- Minicron.config['server']['path']
305
+ # Get an instance of insidious and set the pid file
306
+ insidious = Insidious.new(
307
+ :pid_file => '/tmp/minicron.pid',
308
+ :daemonize => Minicron.config['server']['debug'] == false
294
309
  )
310
+
311
+ case action
312
+ when 'start'
313
+ insidious.start! { start_server }
314
+ when 'stop'
315
+ insidious.stop!
316
+ when 'restart'
317
+ insidious.restart! { start_server }
318
+ when 'status'
319
+ if insidious.running?
320
+ puts 'minicron is running'
321
+ else
322
+ puts 'minicron is not running'
323
+ end
324
+ end
295
325
  end
296
326
  end
297
327
  end
@@ -352,7 +382,7 @@ module Minicron
352
382
  faye.send(:job_id => ids[:job_id], :execution_id => ids[:execution_id], :type => :output, :message => e.message)
353
383
  end
354
384
 
355
- fail e
385
+ raise e
356
386
  ensure
357
387
  # Ensure that all messages are delivered and that we
358
388
  unless Minicron.config['cli']['dry_run']