File Coverage

blib/lib/Rex/JobControl.pm
Criterion Covered Total %
statement 75 81 92.5
branch 3 4 75.0
condition n/a
subroutine 6 8 75.0
pod 1 1 100.0
total 85 94 90.4


line stmt bran cond sub pod time code
1              
2             =encoding UTF-8
3              
4             =head1 NAME
5              
6             Rex::JobControl - Job-Control Webinterface for Rex
7              
8             =head1 DESCRIPTION
9              
10             (R)?ex is a configuration- and deployment management framework. You can write tasks in a file named I.
11              
12             You can find examples and howtos on L
13              
14             This is the official webinterface for Rex.
15              
16             =head1 GETTING HELP
17              
18             =over 4
19              
20             =item * Web Site: L
21              
22             =item * IRC: irc.freenode.net #rex
23              
24             =item * Bug Tracker: L
25              
26             =item * Twitter: L
27              
28             =back
29              
30             =head1 INSTALLATION
31              
32             To install Rex::JobControl you can use the normal cpan tools. We recommend using cpanm from http://cpanmin.us/.
33              
34             cpanm Rex::JobControl
35              
36             After installing you have to create the configuration file in on of the locations mentioned in CONFIGURATION.
37              
38             Before you first start the server you have to run the I command.
39              
40             rex_job_control jobcontrol setup
41              
42             This command will create all the necesarry directories you have configured in your configuration file.
43              
44             =head2 UBUNTU
45              
46             If you want to install Rex::JobControl on Ubuntu 14.04 you have to follow these steps.
47              
48             =over 4
49              
50             =item Install build dependencies
51              
52             apt-get install cpanminus libdatetime-perl gcc make automake m4 bison flex libssh2-1-dev libssl-dev
53              
54             =item Install Rex::JobControl
55              
56             cpanm Rex::JobControl
57              
58             =item Create a configuration file
59              
60             For this, you can use the example configuration file from the git repostiroy.
61              
62             mkdir /etc/rex
63             wget -O /etc/rex/jobcontrol.conf https://raw.githubusercontent.com/RexOps/rex-jobcontrol/master/jobcontrol.conf
64              
65             =item Preparing to start the services
66              
67             Now after you have configured Rex::JobControl you have to create all the necessary folders. You can do this with a build-in command.
68              
69             rex_job_control jobcontrol setup
70              
71             This will also create a user I with password I.
72              
73             =item Starting services
74              
75             Rex::JobControl can create upstart files for you. To do this run the following command.
76              
77             rex_job_control jobcontrol upstart -c
78              
79             After this you can start the Rex::JobWorker server and worker daemon (minion).
80              
81             service rex-jobcontrol start
82             service rex-jobcontrol-minion start
83              
84             =item Accessing the Webfrontend
85              
86             Now you can access the webfrontend via http://$your-server:8080/. If you can't connect, make sure the firewall doesn't block the traffic to post 8080.
87              
88              
89              
90             =back
91              
92             =head2 CENTOS 7
93              
94             If you want to install Rex::JobControl on CentOS 7 you have to follow these steps.
95              
96             =over 4
97              
98             =item Install build dependencies
99              
100             yum install perl-DateTime perl-App-cpanminus gcc m4 flex bison git wget
101              
102             =item Install Rex::JobControl
103              
104             cpanm Rex::JobControl
105              
106             =item Create a configuration file
107              
108             For this, you can use the example configuration file from the git repostiroy.
109              
110             mkdir /etc/rex
111             wget -O /etc/rex/jobcontrol.conf https://raw.githubusercontent.com/RexOps/rex-jobcontrol/master/jobcontrol.conf
112              
113             =item Preparing to start the services
114              
115             Now after you have configured Rex::JobControl you have to create all the necessary folders. You can do this with a build-in command.
116              
117             rex_job_control jobcontrol setup
118              
119             This will also create a user I with password I.
120              
121             =item Starting services
122              
123             Rex::JobControl can create systemd unit files for you. To do this run the following command.
124              
125             rex_job_control jobcontrol systemd -c
126              
127             After this you can start the Rex::JobWorker server and worker daemon (minion).
128              
129             systemctl start rex-jobcontrol.service
130             systemctl start rex-jobcontrol-minion.service
131              
132             =item Accessing the Webfrontend
133              
134             Now you can access the webfrontend via http://$your-server:8080/. If you can't connect, make sure the firewall doesn't block the traffic to post 8080.
135              
136             =back
137              
138             =head1 CONFIGURATION
139              
140             The configuration file is looked up in 3 locations.
141              
142             =over 4
143              
144             =item /etc/rex/jobcontrol.conf
145              
146             =item /usr/local/etc/rex/jobcontrol.conf
147              
148             =item ./jobcontrol.conf
149              
150             =back
151              
152             You find an example configuration file on https://github.com/RexOps/rex-jobcontrol.
153              
154             =head1 RUNNING
155              
156             Rex::JobControl consists of 2 services. The Webinterface and the Worker.
157              
158             To start the worker you have to run the following command. You can start as many worker as you need/want.
159              
160             rex_job_control minion worker
161              
162             To start the Webinterface you have to run this command. This will start a webserver at port 8080.
163              
164             hypnotoad /usr/bin/rex_job_control
165              
166              
167             =head1 MANAGING USERS
168              
169             Currently there is no webinterface to manage the users, but you can use a cli command to do this.
170              
171             Add user:
172              
173             rex_job_control jobcontrol adduser -u $user -p $password
174              
175             Remove user:
176              
177             rex_job_control jobcontrol deluser -u $user
178              
179             List user:
180              
181             rex_job_control jobcontrol listuser
182              
183             =cut
184              
185             package Rex::JobControl;
186             $Rex::JobControl::VERSION = '0.18.0';
187 1     1   619 use File::Basename 'dirname';
  1         1  
  1         54  
188 1     1   4 use File::Spec::Functions 'catdir';
  1         1  
  1         39  
189 1     1   4 use Mojo::Base 'Mojolicious';
  1         1  
  1         8  
190 1     1   91589 use Data::Dumper;
  1         2  
  1         46  
191 1     1   449 use Rex::JobControl::Mojolicious::Command::jobcontrol;
  1         2  
  1         1022  
192              
193             # This method will run once at server start
194             sub startup {
195 1     1 1 14064 my $self = shift;
196              
197             # Documentation browser under "/perldoc"
198             # $self->plugin('PODRenderer');
199              
200             #######################################################################
201             # Load configuration
202             #######################################################################
203 1         3 my @cfg = (
204             "/etc/rex/jobcontrol.conf", "/usr/local/etc/rex/jobcontrol.conf",
205             "jobcontrol.conf"
206             );
207 1         2 my $cfg;
208 1         3 for my $file (@cfg) {
209 3 100       34 if ( -f $file ) {
210 1         2 $cfg = $file;
211 1         2 last;
212             }
213             }
214              
215             #######################################################################
216             # Load plugins
217             #######################################################################
218 1         7 $self->plugin( "Config", file => $cfg );
219              
220 1 50       2048 if ( -d dirname( $self->config->{log}->{access_log} ) ) {
221 0         0 $self->app->log(
222             Mojo::Log->new(
223             path => $self->config->{log}->{access_log},
224             level => $self->config->{log}->{access_log_level}
225             )
226             );
227             }
228              
229 1         70 $self->plugin("Rex::JobControl::Mojolicious::Plugin::Project");
230              
231 1         100 $self->plugin( Minion => { File => $self->app->config->{minion_db_file} } );
232 1         49612 $self->plugin("Rex::JobControl::Mojolicious::Plugin::MinionJobs");
233 1         167 $self->plugin("Rex::JobControl::Mojolicious::Plugin::User");
234 1         67 $self->plugin("Rex::JobControl::Mojolicious::Plugin::Audit");
235             $self->plugin(
236             "Authentication" => {
237             autoload_user => 1,
238             session_key => $self->config->{session}->{key},
239             load_user => sub {
240 0     0   0 my ( $app, $uid ) = @_;
241              
242 0         0 my $user = $app->get_user($uid);
243 0         0 return $user; # user objekt
244             },
245             validate_user => sub {
246 0     0   0 my ( $app, $username, $password ) = @_;
247 0         0 return $app->check_password( $username, $password );
248             },
249             }
250 1         53 );
251              
252             #######################################################################
253             # Define routes
254             #######################################################################
255 1         2331 my $base_routes = $self->routes;
256              
257             # Normal route to controller
258              
259 1         13 my $r = $base_routes->bridge('/')->to('dashboard#prepare_stash');
260              
261 1         394 $r->get('/login')->to('dashboard#login');
262 1         512 $r->post('/login')->to('dashboard#login_post');
263              
264 1         614 my $r_formular_execute =
265             $r->bridge('/project/:project_dir/formular/:formular_dir/execute')
266             ->to("formular#check_public");
267              
268 1         591 my $r_auth = $r->bridge('/')->to("dashboard#check_login");
269              
270 1         245 $r_auth->get('/logout')->to('dashboard#ctrl_logout');
271 1         453 $r_auth->get('/')->to('dashboard#index');
272 1         293 $r_auth->get('/help')->to('help#index');
273              
274 1         437 $r_auth->get('/project/new')->to('project#project_new');
275 1         467 $r_auth->post('/project/new')->to('project#project_new_create');
276              
277 1         525 my $project_r =
278             $r_auth->bridge('/project/:project_dir')->to('project#prepare_stash');
279 1         451 my $rex_r = $r_auth->bridge('/project/:project_dir/rexfile/:rexfile_dir')
280             ->to('rexfile#prepare_stash');
281 1         540 my $job_r = $r_auth->bridge('/project/:project_dir/job/:job_dir')
282             ->to('job#prepare_stash');
283 1         513 my $form_r = $r_auth->bridge('/project/:project_dir/formular/:formular_dir')
284             ->to('formular#prepare_stash');
285              
286 1         531 $project_r->get('/nodes')->to('nodes#index');
287 1         446 $project_r->get('/audit')->to('audit#index');
288              
289 1         448 $project_r->get('/')->to('project#view');
290 1         292 $project_r->get('/job/new')->to('job#job_new');
291 1         497 $project_r->post('/job/new')->to('job#job_new_create');
292 1         462 $project_r->get('/delete')->to('project#remove');
293 1         483 $project_r->get('/rexfile/new')->to('rexfile#rexfile_new');
294 1         493 $project_r->post('/rexfile/new')->to('rexfile#rexfile_new_create');
295 1         527 $project_r->get('/formular/new')->to('formular#formular_new');
296 1         472 $project_r->post('/formular/new')->to('formular#formular_new_create');
297              
298 1         466 $form_r->get('/')->to('formular#view');
299 1         291 $form_r->get('/edit')->to('formular#edit');
300 1         445 $form_r->post('/edit')->to('formular#edit_save');
301 1         485 $r_formular_execute->get('/')->to('formular#view_formular');
302 1         301 $r_formular_execute->post('/')->to('formular#view_formular');
303 1         287 $form_r->post('/execute/delete_data_item')->to('formular#delete_data_item');
304 1         519 $form_r->get('/delete')->to('formular#remove');
305              
306 1         466 $rex_r->get('/')->to('rexfile#view');
307 1         292 $rex_r->get('/reload')->to('rexfile#reload');
308 1         452 $rex_r->get('/delete')->to('rexfile#remove');
309              
310 1         441 $job_r->get('/')->to('job#view');
311 1         302 $job_r->get('/edit')->to('job#edit');
312 1         436 $job_r->post('/edit')->to('job#edit_save');
313 1         482 $job_r->get('/delete')->to('job#job_delete');
314 1         442 $job_r->get('/execute')->to('job#job_execute');
315 1         441 $job_r->post('/execute')->to('job#job_execute_dispatch');
316 1         446 $job_r->get('/:job_id/output')->to('job#view_output_log');
317              
318             #######################################################################
319             # for the package
320             #######################################################################
321              
322             # Switch to installable home directory
323 1         515 $self->home->parse( catdir( dirname(__FILE__), 'JobControl' ) );
324              
325             # Switch to installable "public" directory
326 1         111 $self->static->paths->[0] = $self->home->rel_dir('public');
327              
328             # Switch to installable "templates" directory
329 1         86 $self->renderer->paths->[0] = $self->home->rel_dir('templates');
330              
331             }
332              
333             1;