File Coverage

blib/lib/Rex/JobControl.pm
Criterion Covered Total %
statement 74 79 93.6
branch 2 2 100.0
condition n/a
subroutine 6 8 75.0
pod 1 1 100.0
total 83 90 92.2


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.7.0';
187 1     1   888 use File::Basename 'dirname';
  1         2  
  1         127  
188 1     1   7 use File::Spec::Functions 'catdir';
  1         3  
  1         53  
189 1     1   5 use Mojo::Base 'Mojolicious';
  1         2  
  1         17  
190 1     1   222049 use Data::Dumper;
  1         3  
  1         54  
191 1     1   731 use Rex::JobControl::Mojolicious::Command::jobcontrol;
  1         3  
  1         911  
192              
193             # This method will run once at server start
194             sub startup {
195 1     1 1 25687 my $self = shift;
196              
197             # Documentation browser under "/perldoc"
198             # $self->plugin('PODRenderer');
199              
200             #######################################################################
201             # Load configuration
202             #######################################################################
203 1         4 my @cfg = (
204             "/etc/rex/jobcontrol.conf", "/usr/local/etc/rex/jobcontrol.conf",
205             "jobcontrol.conf"
206             );
207 1         2 my $cfg;
208 1         2 for my $file (@cfg) {
209 3 100       61 if ( -f $file ) {
210 1         3 $cfg = $file;
211 1         2 last;
212             }
213             }
214              
215             #######################################################################
216             # Load plugins
217             #######################################################################
218 1         6 $self->plugin( "Config", file => $cfg );
219 1         3062 $self->plugin("Rex::JobControl::Mojolicious::Plugin::Project");
220              
221 1         166 $self->plugin( Minion => { File => $self->app->config->{minion_db_file} } );
222 1         123307 $self->plugin("Rex::JobControl::Mojolicious::Plugin::MinionJobs");
223 1         205 $self->plugin("Rex::JobControl::Mojolicious::Plugin::User");
224 1         81 $self->plugin("Rex::JobControl::Mojolicious::Plugin::Audit");
225             $self->plugin(
226             "Authentication" => {
227             autoload_user => 1,
228             session_key => $self->config->{session}->{key},
229             load_user => sub {
230 0     0   0 my ( $app, $uid ) = @_;
231              
232 0         0 my $user = $app->get_user($uid);
233 0         0 return $user; # user objekt
234             },
235             validate_user => sub {
236 0     0   0 my ( $app, $username, $password ) = @_;
237 0         0 return $app->check_password( $username, $password );
238             },
239             }
240 1         75 );
241              
242             #######################################################################
243             # Define routes
244             #######################################################################
245 1         3523 my $base_routes = $self->routes;
246              
247             # Normal route to controller
248              
249 1         18 my $r = $base_routes->bridge('/')->to('dashboard#prepare_stash');
250              
251 1         363 $r->get('/login')->to('dashboard#login');
252 1         659 $r->post('/login')->to('dashboard#login_post');
253              
254              
255 1         527 my $r_formular_execute =
256             $r->bridge('/project/:project_dir/formular/:formular_dir/execute')
257             ->to("formular#check_public");
258              
259 1         745 my $r_auth = $r->bridge('/')->to("dashboard#check_login");
260              
261 1         397 $r_auth->get('/logout')->to('dashboard#ctrl_logout');
262 1         868 $r_auth->get('/')->to('dashboard#index');
263 1         436 $r_auth->get('/help')->to('help#index');
264              
265 1         561 $r_auth->get('/project/new')->to('project#project_new');
266 1         670 $r_auth->post('/project/new')->to('project#project_new_create');
267              
268 1         575 my $project_r =
269             $r_auth->bridge('/project/:project_dir')->to('project#prepare_stash');
270 1         689 my $rex_r = $r_auth->bridge('/project/:project_dir/rexfile/:rexfile_dir')
271             ->to('rexfile#prepare_stash');
272 1         774 my $job_r = $r_auth->bridge('/project/:project_dir/job/:job_dir')
273             ->to('job#prepare_stash');
274 1         695 my $form_r = $r_auth->bridge('/project/:project_dir/formular/:formular_dir')
275             ->to('formular#prepare_stash');
276              
277 1         626 $project_r->get('/nodes')->to('nodes#index');
278 1         738 $project_r->get('/audit')->to('audit#index');
279              
280 1         716 $project_r->get('/')->to('project#view');
281 1         477 $project_r->get('/job/new')->to('job#job_new');
282 1         759 $project_r->post('/job/new')->to('job#job_new_create');
283 1         641 $project_r->get('/delete')->to('project#remove');
284 1         527 $project_r->get('/rexfile/new')->to('rexfile#rexfile_new');
285 1         593 $project_r->post('/rexfile/new')->to('rexfile#rexfile_new_create');
286 1         632 $project_r->get('/formular/new')->to('formular#formular_new');
287 1         617 $project_r->post('/formular/new')->to('formular#formular_new_create');
288              
289 1         511 $form_r->get('/')->to('formular#view');
290 1         347 $form_r->get('/edit')->to('formular#edit');
291 1         546 $form_r->post('/edit')->to('formular#edit_save');
292 1         6348 $r_formular_execute->get('/')->to('formular#view_formular');
293 1         502 $r_formular_execute->post('/')->to('formular#view_formular');
294 1         409 $form_r->post('/execute/delete_data_item')->to('formular#delete_data_item');
295 1         898 $form_r->get('/delete')->to('formular#remove');
296              
297 1         595 $rex_r->get('/')->to('rexfile#view');
298 1         397 $rex_r->get('/reload')->to('rexfile#reload');
299 1         635 $rex_r->get('/delete')->to('rexfile#remove');
300              
301 1         528 $job_r->get('/')->to('job#view');
302 1         386 $job_r->get('/edit')->to('job#edit');
303 1         580 $job_r->post('/edit')->to('job#edit_save');
304 1         599 $job_r->get('/delete')->to('job#job_delete');
305 1         649 $job_r->get('/execute')->to('job#job_execute');
306 1         578 $job_r->post('/execute')->to('job#job_execute_dispatch');
307 1         608 $job_r->get('/:job_id/output')->to('job#view_output_log');
308              
309             #######################################################################
310             # for the package
311             #######################################################################
312              
313             # Switch to installable home directory
314 1         716 $self->home->parse( catdir( dirname(__FILE__), 'JobControl' ) );
315              
316             # Switch to installable "public" directory
317 1         139 $self->static->paths->[0] = $self->home->rel_dir('public');
318              
319             # Switch to installable "templates" directory
320 1         105 $self->renderer->paths->[0] = $self->home->rel_dir('templates');
321              
322             }
323              
324             1;