| 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<Rexfile>. | ||||||||||
| 11 | |||||||||||
| 12 | You can find examples and howtos on L<http://rexify.org/> | ||||||||||
| 13 | |||||||||||
| 14 | This is the official webinterface for Rex. | ||||||||||
| 15 | |||||||||||
| 16 | =head1 GETTING HELP | ||||||||||
| 17 | |||||||||||
| 18 | =over 4 | ||||||||||
| 19 | |||||||||||
| 20 | =item * Web Site: L<http://rexify.org/> | ||||||||||
| 21 | |||||||||||
| 22 | =item * IRC: irc.freenode.net #rex | ||||||||||
| 23 | |||||||||||
| 24 | =item * Bug Tracker: L<https://github.com/RexOps/rex-jobcontrol/issues> | ||||||||||
| 25 | |||||||||||
| 26 | =item * Twitter: L<http://twitter.com/RexOps> | ||||||||||
| 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<setup> 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<admin> with password I<admin>. | ||||||||||
| 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<admin> with password I<admin>. | ||||||||||
| 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 | 1 | $Rex::JobControl::VERSION = '0.18.0'; | |||||||||
| 187 | 1 | ▶ | use File::Basename 'dirname'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 188 | 1 | ▶ | use File::Spec::Functions 'catdir'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 189 | 1 | ▶ | use Mojo::Base 'Mojolicious'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 190 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 191 | 1 | ▶ | use Rex::JobControl::Mojolicious::Command::jobcontrol; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 192 | |||||||||||
| 193 | # This method will run once at server start | ||||||||||
| 194 | 1 | ▶ | sub startup { | ||||||||
|
Subroutine
startup: called CC=4 SCAR=25.0
Pod
documented
| |||||||||||
| 195 | 1 | my $self = shift; | |||||||||
| 196 | |||||||||||
| 197 | # Documentation browser under "/perldoc" | ||||||||||
| 198 | # $self->plugin('PODRenderer'); | ||||||||||
| 199 | |||||||||||
| 200 | ####################################################################### | ||||||||||
| 201 | # Load configuration | ||||||||||
| 202 | ####################################################################### | ||||||||||
| 203 | 1 | my @cfg = ( | |||||||||
| 204 | "/etc/rex/jobcontrol.conf", "/usr/local/etc/rex/jobcontrol.conf", | ||||||||||
| 205 | "jobcontrol.conf" | ||||||||||
| 206 | ); | ||||||||||
| 207 | 1 | my $cfg; | |||||||||
| 208 | 1 | for my $file (@cfg) { | |||||||||
| 209 | 3 | ▶ | if ( -f $file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 210 | 1 | $cfg = $file; | |||||||||
| 211 | 1 | last; | |||||||||
| 212 | } | ||||||||||
| 213 | } | ||||||||||
| 214 | |||||||||||
| 215 | ####################################################################### | ||||||||||
| 216 | # Load plugins | ||||||||||
| 217 | ####################################################################### | ||||||||||
| 218 | 1 | $self->plugin( "Config", file => $cfg ); | |||||||||
| 219 | |||||||||||
| 220 | 1 | ▶ | if ( -d dirname( $self->config->{log}->{access_log} ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 221 | $self->app->log( | ||||||||||
| 222 | Mojo::Log->new( | ||||||||||
| 223 | path => $self->config->{log}->{access_log}, | ||||||||||
| 224 | level => $self->config->{log}->{access_log_level} | ||||||||||
| 225 | ) | ||||||||||
| 226 | 0 | ); | |||||||||
| 227 | } | ||||||||||
| 228 | |||||||||||
| 229 | 1 | $self->plugin("Rex::JobControl::Mojolicious::Plugin::Project"); | |||||||||
| 230 | |||||||||||
| 231 | 1 | $self->plugin( Minion => { File => $self->app->config->{minion_db_file} } ); | |||||||||
| 232 | 0 | $self->plugin("Rex::JobControl::Mojolicious::Plugin::MinionJobs"); | |||||||||
| 233 | 0 | $self->plugin("Rex::JobControl::Mojolicious::Plugin::User"); | |||||||||
| 234 | 0 | $self->plugin("Rex::JobControl::Mojolicious::Plugin::Audit"); | |||||||||
| 235 | $self->plugin( | ||||||||||
| 236 | "Authentication" => { | ||||||||||
| 237 | autoload_user => 1, | ||||||||||
| 238 | session_key => $self->config->{session}->{key}, | ||||||||||
| 239 | 0 | ▶ | load_user => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 240 | 0 | my ( $app, $uid ) = @_; | |||||||||
| 241 | |||||||||||
| 242 | 0 | my $user = $app->get_user($uid); | |||||||||
| 243 | 0 | return $user; # user objekt | |||||||||
| 244 | }, | ||||||||||
| 245 | 0 | ▶ | validate_user => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 246 | 0 | my ( $app, $username, $password ) = @_; | |||||||||
| 247 | 0 | return $app->check_password( $username, $password ); | |||||||||
| 248 | }, | ||||||||||
| 249 | } | ||||||||||
| 250 | 0 | ); | |||||||||
| 251 | |||||||||||
| 252 | ####################################################################### | ||||||||||
| 253 | # Define routes | ||||||||||
| 254 | ####################################################################### | ||||||||||
| 255 | 0 | my $base_routes = $self->routes; | |||||||||
| 256 | |||||||||||
| 257 | # Normal route to controller | ||||||||||
| 258 | |||||||||||
| 259 | 0 | my $r = $base_routes->bridge('/')->to('dashboard#prepare_stash'); | |||||||||
| 260 | |||||||||||
| 261 | 0 | $r->get('/login')->to('dashboard#login'); | |||||||||
| 262 | 0 | $r->post('/login')->to('dashboard#login_post'); | |||||||||
| 263 | |||||||||||
| 264 | 0 | my $r_formular_execute = | |||||||||
| 265 | $r->bridge('/project/:project_dir/formular/:formular_dir/execute') | ||||||||||
| 266 | ->to("formular#check_public"); | ||||||||||
| 267 | |||||||||||
| 268 | 0 | my $r_auth = $r->bridge('/')->to("dashboard#check_login"); | |||||||||
| 269 | |||||||||||
| 270 | 0 | $r_auth->get('/logout')->to('dashboard#ctrl_logout'); | |||||||||
| 271 | 0 | $r_auth->get('/')->to('dashboard#index'); | |||||||||
| 272 | 0 | $r_auth->get('/help')->to('help#index'); | |||||||||
| 273 | |||||||||||
| 274 | 0 | $r_auth->get('/project/new')->to('project#project_new'); | |||||||||
| 275 | 0 | $r_auth->post('/project/new')->to('project#project_new_create'); | |||||||||
| 276 | |||||||||||
| 277 | 0 | my $project_r = | |||||||||
| 278 | $r_auth->bridge('/project/:project_dir')->to('project#prepare_stash'); | ||||||||||
| 279 | 0 | my $rex_r = $r_auth->bridge('/project/:project_dir/rexfile/:rexfile_dir') | |||||||||
| 280 | ->to('rexfile#prepare_stash'); | ||||||||||
| 281 | 0 | my $job_r = $r_auth->bridge('/project/:project_dir/job/:job_dir') | |||||||||
| 282 | ->to('job#prepare_stash'); | ||||||||||
| 283 | 0 | my $form_r = $r_auth->bridge('/project/:project_dir/formular/:formular_dir') | |||||||||
| 284 | ->to('formular#prepare_stash'); | ||||||||||
| 285 | |||||||||||
| 286 | 0 | $project_r->get('/nodes')->to('nodes#index'); | |||||||||
| 287 | 0 | $project_r->get('/audit')->to('audit#index'); | |||||||||
| 288 | |||||||||||
| 289 | 0 | $project_r->get('/')->to('project#view'); | |||||||||
| 290 | 0 | $project_r->get('/job/new')->to('job#job_new'); | |||||||||
| 291 | 0 | $project_r->post('/job/new')->to('job#job_new_create'); | |||||||||
| 292 | 0 | $project_r->get('/delete')->to('project#remove'); | |||||||||
| 293 | 0 | $project_r->get('/rexfile/new')->to('rexfile#rexfile_new'); | |||||||||
| 294 | 0 | $project_r->post('/rexfile/new')->to('rexfile#rexfile_new_create'); | |||||||||
| 295 | 0 | $project_r->get('/formular/new')->to('formular#formular_new'); | |||||||||
| 296 | 0 | $project_r->post('/formular/new')->to('formular#formular_new_create'); | |||||||||
| 297 | |||||||||||
| 298 | 0 | $form_r->get('/')->to('formular#view'); | |||||||||
| 299 | 0 | $form_r->get('/edit')->to('formular#edit'); | |||||||||
| 300 | 0 | $form_r->post('/edit')->to('formular#edit_save'); | |||||||||
| 301 | 0 | $r_formular_execute->get('/')->to('formular#view_formular'); | |||||||||
| 302 | 0 | $r_formular_execute->post('/')->to('formular#view_formular'); | |||||||||
| 303 | 0 | $form_r->post('/execute/delete_data_item')->to('formular#delete_data_item'); | |||||||||
| 304 | 0 | $form_r->get('/delete')->to('formular#remove'); | |||||||||
| 305 | |||||||||||
| 306 | 0 | $rex_r->get('/')->to('rexfile#view'); | |||||||||
| 307 | 0 | $rex_r->get('/reload')->to('rexfile#reload'); | |||||||||
| 308 | 0 | $rex_r->get('/delete')->to('rexfile#remove'); | |||||||||
| 309 | |||||||||||
| 310 | 0 | $job_r->get('/')->to('job#view'); | |||||||||
| 311 | 0 | $job_r->get('/edit')->to('job#edit'); | |||||||||
| 312 | 0 | $job_r->post('/edit')->to('job#edit_save'); | |||||||||
| 313 | 0 | $job_r->get('/delete')->to('job#job_delete'); | |||||||||
| 314 | 0 | $job_r->get('/execute')->to('job#job_execute'); | |||||||||
| 315 | 0 | $job_r->post('/execute')->to('job#job_execute_dispatch'); | |||||||||
| 316 | 0 | $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 | 0 | $self->home->parse( catdir( dirname(__FILE__), 'JobControl' ) ); | |||||||||
| 324 | |||||||||||
| 325 | # Switch to installable "public" directory | ||||||||||
| 326 | 0 | $self->static->paths->[0] = $self->home->rel_dir('public'); | |||||||||
| 327 | |||||||||||
| 328 | # Switch to installable "templates" directory | ||||||||||
| 329 | 0 | $self->renderer->paths->[0] = $self->home->rel_dir('templates'); | |||||||||
| 330 | |||||||||||
| 331 | } | ||||||||||
| 332 | |||||||||||
| 333 | 1 | 1; | |||||||||