Activator

 view release on metacpan or  search on metacpan

bin/activator.pl  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Activator::Registry;
use Activator::Config;
use Activator::Log qw( :levels );
use Exception::Class::TryCatch;
use Data::Dumper;
use Template;
use File::Find;

=head1 NAME

activator.pl - setup and manage services with an Activator project.

=head1 SYNOPSIS

activator.pl [OPTIONS] ACTION project-name

 Actions
  sync : sync user codebase to target install base

 Options:
  --restart : (re)start the webserver after performing <ACTION>
  --log_level : One of TRACE, DEBUG, INFO, WARN, ERROR, FATAL (see L<Activator::Log>)
  --sync_dir : ignore sync_dir setting from configuration, use this.

 Todo:
  --activator_codebase=<path> : use alternate Activator codebase (for Activator development)

See L<Activator::Tutorial> for a description of how to configure an Activator project.

=cut

# $config, $args, $project, $action and the current apache pid are globally interesting
my ( $config, $args, $project, $action, $httpd_pid );

try eval {
    # Act::Config requires that project be set via an option or be the
    # last arg, hence the flag after undef below
    $config = Activator::Config->get_config( \@ARGV, undef, 1 );
};

if ( catch my $e ) {
    die( "Error while processing command line options: $e" );
}

my $log_level = $config->{log_level} || 'WARN';
if ( $config->{v} || $config->{verbose} ) {
    Activator::Log->level( 'INFO' );
}

$action  = $ARGV[-2];
$project = $ARGV[-1];

if ( $action eq 'sync' ) {
    &sync( $project );
}
else {
    ERROR("'$action' action not supported");
    exit(1);
}

if ( $config->{restart} ) {
    &restart( $project );
}

sub sync {
    my $project = shift;

    if ( $config->{sync_target} eq '/' ) {
	ERROR( "target sync_dir is root dir! Refusing to continue this DANGEROUS operation");
	exit(1);
    }


    my $cmd;

    # before blowing away the run dir, grab the httpd pid and store it globally
    if ( -f $config->{apache2}->{PidFile}) {
	INFO("Looking for pid file...");
	$cmd = 'cat '. $config->{apache2}->{PidFile};
	INFO( $cmd );
	$httpd_pid = `$cmd`;
	chomp $httpd_pid;
    }

    # convenience vars
    my $project_codebase = $config->{project_codebase};
    my $perl5lib      = $config->{apache2}->{PERL5LIB};
    my $document_root = $config->{apache2}->{DocumentRoot};
    my $server_root   = $config->{apache2}->{ServerRoot};

    my $rsync_flags = ( $config->{debug} ? '-v' : '' );
    $rsync_flags   .= ' --cvs-exclude';

    # these commands need to run to create the target installation
    my @cmds = (
		# blow away the target dir
		"rm -rf $config->{sync_target}",

		"mkdir -p $config->{sync_target}",
		"mkdir -p $config->{sync_run_dir}",
		"mkdir -p $config->{sync_lock_dir}",
		"mkdir -p $config->{sync_conf_dir}",
		"mkdir -p $config->{sync_log_dir}",

		"mkdir -p $perl5lib",
		"mkdir -p $document_root",
		"mkdir -p $server_root/logs",

		# all your perl lib are belong to PERL5LIB
		"rsync -a $rsync_flags $project_codebase/lib/* $perl5lib",

		# symlink template files so we don't have to restart server
		# not that this symlinks INTO document root
		"ln -sf $project_codebase/root $document_root",

		# symlink apache modules
		"ln -sf /usr/lib/httpd/modules $server_root",

		# symlink apache log files
		"ln -sf $server_root/logs $config->{sync_log_dir}/httpd",

	       );


    if ( $config->{activator_codebase} ) {
	push @cmds,
	  "rsync -a $rsync_flags ".$config->{activator_codebase}."/lib/* $perl5lib";
    }

    if ( $config->{sync_data_dirs} ) {
	foreach my $dir ( @{ $config->{sync_data_dirs} } ) {
	    push @cmds, "mkdir -p $dir";
	}
    }

    if ( my $dict_targ = $config->{Activator}->{Dictionary}->{dict_files} ) {



( run in 1.439 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )