This commit is contained in:
Zane C. B-H 2021-11-09 23:27:43 -06:00
parent 3cc63c7ac7
commit 533f9d8376
6 changed files with 143 additions and 121 deletions

37
bin/stoaster Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env perl
#
#This software is Copyright (c) 2021 by Zane C. Bowers-Hadley.
#
#This is free software, licensed under:
#
# The Artistic License 2.0 (GPL Compatible)
use strict;
use warnings;
use Server::Toaster;
use Getopt::Long qw(:config pass_through);
use Data::Dumper;
my $stoaster_dir;
my $templates_dir;
my $output_dir;
my $module;
my $action;
GetOptions(
's=s' => \$stoaster_dir,
't=s' => \$templates_dir,
'o=s' => \$output_dir,
'm=s' => \$module,
'a=s' => \$action,
);
my $stoaster = Server::Toaster->new(
dir => $stoaster_dir,
templates => $templates_dir,
output => $output_dir,
);
if ($action eq 'get_files') {
my %returned=$stoaster->get_files($module);
print Dumper( \%returned );
}

View File

@ -49,7 +49,6 @@ This initiates the module.
$templates and $output will be created as needed, but $dir must
exist upon module init or it will die.
=cut
sub new {
@ -75,12 +74,14 @@ sub new {
$opts{templates} = $opts{dir} . '/templates';
}
my %defaults = Server::Toaster::Defaults->get;
# init the object
my $self = {
dir => $opts{dir},
output => $opts{output},
templates => $opts{templates},
defaults=>Server::Toaster::Defaults->get,
defaults => \%defaults,
share => dist_dir('Server-Toaster'),
};
bless $self;
@ -134,13 +135,18 @@ sub fill_in {
my $config = $merger->merge( $opts{config}, $self->{defaults} );
my $to_eval='use Server::Toaster::Modules::'.$opts{module}.'; '.
'my $st_module=Server::Toaster::Modules::'.$opts{module}.'->new(',
'dir=>$self->{dir}, '.
'output=>$self->{output}, '.
'templates=>$self->{templates} );'.
'$st_module->fill_in(%opts);';
my $to_eval
= 'use Server::Toaster::Modules::'
. $opts{module} . '; '
. 'my $st_module=Server::Toaster::Modules::'
. $opts{module}
. '->new('.
'dir=>$self->{dir}, '
. 'output=>$self->{output}, '
. 'templates=>$self->{templates} );'
. '$st_module->fill_in(%opts);';
eval($to_eval);
}
@ -161,7 +167,7 @@ Sever::Toaster::Modules. So 'Sever::Toaster::Modules::Apache' becomes
=cut
sub get_files {
my ( $blank, $module ) = @_;
my ( $self, $module ) = @_;
# make sure we have a module defined
if ( !defined($module) ) {
@ -171,11 +177,19 @@ sub get_files {
my %returned;
my $to_eval
= 'use Server::Toaster::Modules::'
. $module . '; '
. 'my $st_module=Server::Toaster::Modules::'
. $module
. '; %returned=Server::Toaster::Modules::'
. $module
. '->get_files;';
. '->new('.
'dir=>$self->{dir}, '
. 'output=>$self->{output}, '
. 'templates=>$self->{templates} );'
. '%returned=$st_module->get_files;';
eval($to_eval);
if ($@) {
print "Evaled... ".$to_eval."\n";
die "Eval failed... ".$@;
}
return %returned;
}

View File

@ -46,7 +46,7 @@ sub get {
ssl_honor_cipher_order => '0',
server_admin_email => 'you@foo.bar',
server_admin_name => 'Who Ever',
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAN%%%/',
ssl_cert_path => '/usr/local/etc/letsencrypt/live/%%%DOMAIN%%%/',
Apache => {
listen => [],
http_port => '80',
@ -54,8 +54,9 @@ sub get {
server_root => '/usr/local',
default_https_redirect => '0',
enable_https => '0',
include_optional => 1,
include_optional => '0',
ssl_stapling => '1',
version => '2.4',
ssl_stapling_cache => 'shmcb:logs/ssl_stapling(32768)',
modules => {
mpm_prefork => '1',
@ -152,33 +153,33 @@ sub get {
wsgi => "1",
auth_openidc => "1",
},
modules_d => 1,
modules_d => '0',
user => 'www',
group => 'www',
doc_root => '/usr/local/www/apache24/data',
cgi => 0,
cgi => '0',
mpm_event => {
StartServers => 3,
MinSpareThreads => 75,
MaxSpareThreads => 250,
ThreadsPerChild => 25,
MaxRequestWorkers => 400,
MaxConnectionsPerChild => 0
StartServers => '3',
MinSpareThreads => '75',
MaxSpareThreads => '250',
ThreadsPerChild => '25',
MaxRequestWorkers => '400',
MaxConnectionsPerChild => '0'
},
mpm_prefork => {
StartServers => 5,
MinSpareServers => 5,
MaxSpareServers => 10,
MaxRequestWorkers => 250,
MaxConnectionsPerChild => 0,
StartServers => '5',
MinSpareServers => '5',
MaxSpareServers => '10',
MaxRequestWorkers => '250',
MaxConnectionsPerChild => '0',
},
mpm_worker => {
StartServers => 3,
MinSpareThreads => 75,
MaxSpareThreads => 250,
ThreadsPerChild => 25,
MaxRequestWorkers => 400,
MaxConnectionsPerChild => 0,
StartServers => '3',
MinSpareThreads => '75',
MaxSpareThreads => '250',
ThreadsPerChild => '25',
MaxRequestWorkers => '400',
MaxConnectionsPerChild => '0',
}
}

View File

@ -3,11 +3,12 @@ package Server::Toaster::Modules::Apache;
use 5.006;
use strict;
use warnings;
use base 'Server::Toaster::Modules::Base';
use Moose;
extends 'Server::Toaster::Modules::Base';
=head1 NAME
Server::Toaster::Modules::Apache - Apache helper for Server::Toaster
Server::Toaster::Modules::Apache - Apache module for Server::Toaster
=head1 VERSION
@ -62,11 +63,11 @@ sub fill_in {
hostname => $opts{hostname},
d => Server::Toaster::Defaults->get,
c => %opts{config},
}
};
}
=head2 get_files
=head2 get_files_module
Fetches a list of templates a module uses.
@ -75,18 +76,11 @@ and the value being the full path to the file.
=cut
sub get_files {
my ( $self ) = @_;
my $dir=dist_dir('Server-Toaster');
my %returned=(
'Apache/domain.tt'=>$dir.'/Apache/domain.tt',
'Apache/httpd.conf.tt'=>$dir.'/Apache/httpd.conf.tt',
'Apache/doc_root.conf.tt'=>$dir.'/Apache/doc_root.conf.tt',
sub get_files_module {
return (
'Apache/domain.tt',
'Apache/httpd.conf.tt'
);
return %returned;
}
=head1 AUTHOR

View File

@ -6,6 +6,8 @@ use warnings;
use Template;
use Server::Toaster::Defaults;
use File::ShareDir ':ALL';
use File::Spec::Functions;
use Moose;
=head1 NAME
@ -29,8 +31,6 @@ Perhaps a little code snippet.
my $st = Server::Toaster->new();
=head1 METHODS
=head2 new
@ -49,7 +49,6 @@ This initiates the module.
$templates and $output will be created as needed, but $dir must
exist upon module init or it will die.
=cut
sub new {
@ -67,12 +66,12 @@ sub new {
# set the default output dir if non is specified
if ( !defined( $opts{output} ) ) {
$opts{output} = $opts{dir} . '/output';
$opts{output} = catdir( $opts{dir}, 'output' );
}
# set the default template dir if non is specified
if ( !defined( $opts{templates} ) ) {
$opts{templates} = $opts{dir} . '/templates';
$opts{templates} = catdir($opts{dir} , 'templates');
}
# init the object
@ -87,42 +86,7 @@ sub new {
return $self;
}
=head2 fill_in
This filles in the templates.
The required values are as below.
hostname - The hostname of the system being processed.
config - The config hash ref for the use with filling the templates.
This will die upon error.
=cut
sub fill_in {
my ( $self, %opts ) = @_;
# make sure we have a hostname
if (!defined( $opts{hostname} )) {
die( 'No hostname defined' );
}
# make sure we have a config to use
if (!defined( $opts{config} )) {
die( 'No config defined' );
}
my $vars={
hostname=>$opts{hostname},
d=>Server::Toaster::Defaults->get,
c=>%opts{config},
}
}
=head2 get_files
=head2 get_files_module
Fetches a list of templates a module uses.
@ -134,15 +98,27 @@ and the value being the full path to the file.
sub get_files {
my ($self) = @_;
my $dir=dist_dir('Server-Toaster');
my @files=$self->get_files_module;
my %returned=(
'Apache/domain.tt'=>$dir.'/Apache/domain.tt',
'Apache/httpd.conf.tt'=>$dir.'/Apache/httpd.conf.tt',
'Apache/doc_root.conf.tt'=>$dir.'/Apache/doc_root.conf.tt',
);
my $share_dir = dist_dir('Server-Toaster');
return %returned;
my %to_return;
foreach my $file (@files) {
my @split_path=split(/\//, $file);
$to_return{$file}={
rel=>catfile(@split_path),
share=>catfile($share_dir, @split_path),
};
my $use_test=catfile( $self->{templates}, @split_path );
if (-f $use_test ) {
$to_return{$file}{use}=$use_test;
}else {
$to_return{$file}{use}=$to_return{$file}{share};
}
}
return %to_return;
}
=head1 AUTHOR

0
t/stoaster/.exists Normal file
View File