CPAN-Testers-Backend

 view release on metacpan or  search on metacpan

Rexfile  view on Meta::CPAN

            say last_command_output;
        }
        run_task 'deploy_config', on => connection->server;
    };

=head2 deploy_config

    rex -E vm deploy_config

Deploy the configuration for the backend, including L<Beam::Wire> container
files, C<crontab> files, and user profile files.

=cut

my %cron_entry = (
    'process-reports' => {
        user => 'cpantesters',
        minute => '*/10',
        hour => '*',
        day_of_month => '*',
        month => '*',
        day_of_week => '*',
        command => 'beam run report process >>$HOME/var/log/report/process.log 2>&1',
    },
);

task deploy_config =>
    group => 'backend',
    sub {
        Rex::Logger::info( 'Creating log/pid directories' );
        file '~/var/run/report', ensure => 'directory';
        file '~/var/log/report', ensure => 'directory';

        Rex::Logger::info( 'Syncing container files' );
        file '~/etc/container',
            ensure => 'directory';
        sync_up 'etc/container' => '~/etc/container',
            exclude => [ '*.sw*' ];

        Rex::Logger::info( 'Syncing service files' );
        file '~/service/minion/log',
            ensure => 'directory';
        file '~/service/minion/run',
            source => 'etc/runit/minion/run';
        file '~/service/minion/log/run',
            source => 'etc/runit/minion/log/run';

        Rex::Logger::info( 'Syncing crontab files' );
        cron env => 'cpantesters' => add => {
            BEAM_PATH => '/home/cpantesters/etc/container',
        };
        for my $key ( keys %cron_entry ) {
            cron_entry $key, %{ $cron_entry{ $key } }, ensure => 'present';
        }

        Rex::Logger::info( 'Ensuring user profile is correct' );
        for my $file ( qw( .profile .bash_profile ) ) {
            append_if_no_such_line '/home/cpantesters/' . $file,
                'export BEAM_PATH=$HOME/etc/container';
            append_if_no_such_line '/home/cpantesters/' . $file,
                'export BEAM_MINION="mysql+dsn+dbi:mysql:mysql_read_default_file=~/.cpanstats.cnf;mysql_read_default_group=application"';
        }

        Rex::Logger::info( 'Restarting services' );
        run 'sv restart ~/service/minion';
    };

=head2 disable

    rex -E vm disable

Disable the backend processes and cron entries to decommission a backend server.

=cut

task disable =>
    group => 'backend',
    sub {
        Rex::Logger::info( 'Stopping services' );
        run 'sv stop ./service/minion';

        Rex::Logger::info( 'Removing service files' );
        file '~/service/minion', ensure => 'absent';

        Rex::Logger::info( 'Removing cron entries' );
        for my $key ( keys %cron_entry ) {
            cron_entry $key, %{ $cron_entry{ $key } }, ensure => 'absent';
        }
    };

#######################################################################

=head1 SUBROUTINES

=head2 ensure_sudo_password

Ensure a C<sudo> password is set. Use this at the start of any task
that requires C<sudo>.

=cut

sub ensure_sudo_password {
    return if sudo_password();
    return if get 'no_sudo_password';
    print 'Password to use for sudo: ';
    ReadMode('noecho');
    sudo_password ReadLine(0);
    ReadMode('restore');
    print "\n";
}



( run in 2.675 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )