package Web::App::Helper; use Class::Easy; use IO::Easy::File; use IO::Easy::Dir; use Project::Easy::Config; use Project::Easy::Helper; sub ::entangle { $Class::Easy::DEBUG = 'immediately'; Project::Easy::Helper::_script_wrapper ( IO::Easy::Dir->current->append ('bin', 'fake') ); my $pack = $::project; my $apxs_libexec; my $apxs; foreach my $apxs_cmd (( 'ap2xs', 'apxs', 'apxs2', '/usr/sbin/apxs', # Old Fedora verions '/usr/sbin/apxs2' # Opensuse "alias" [sic] )) { my $apxs_test = `$apxs_cmd -q LIBEXECDIR 2>/dev/null`; chomp $apxs_test; next unless $apxs_test; $apxs_libexec = $apxs_test; $apxs = $apxs_cmd; } die "no apxs libexec directory" unless $apxs_libexec; debug "found apxs libexecdir $apxs_libexec"; my $httpd_dir = `$apxs -q SBINDIR`; chomp $httpd_dir; my $httpd_name = `$apxs -q TARGET`; chomp $httpd_name; my $httpd_bin = IO::Easy->new ($httpd_dir)->append ($httpd_name); my $vars = { root => $pack->root, distro => $pack->distro, project => $pack->id, user => scalar getpwuid ($<), group => scalar getgrgid ($(), port => 50000, admin => 'author@example.com', apxs_libexec => $apxs_libexec, httpd_bin => $httpd_bin, }; my $files = &IO::Easy::File::__data__files; my $root = $pack->root; my $global_config_patch_json = delete $files->{global_config_patch_json}; my $local_config_patch_json = delete $files->{local_config_patch_json}; debug "storing config files"; foreach my $deploy_file_tmpl (keys %$files) { # for files with expansion my $deploy_file_name = Project::Easy::Config::string_from_template ( $deploy_file_tmpl, $vars ); my $deploy_file = $root->append ($deploy_file_name)->as_file; my $deploy_dir = $deploy_file->parent; $deploy_dir->create; my $deploy_tmpl = $files->{$deploy_file_tmpl}; my $deploy_contents = Project::Easy::Config::string_from_template ( $deploy_tmpl, $vars ); my $result = $deploy_file->store_if_empty ($deploy_contents); # TODO: make correct routine for file names comparison (etc/ and etc, as example) # because some files may be incorrectly chmod'ed if ($deploy_dir->name eq $pack->bin) { # and $deploy_dir->updir eq $pack->root) { chmod (0755, $deploy_file); } # warn "something" # unless defined $result; } debug "patching configuration for daemon"; # within helper we have json structures my $serializer = Project::Easy::Config->serializer ('json'); # global config my $patch = $serializer->parse_string ($global_config_patch_json); $pack->conf_path->patch ($patch); # local config, variables expansion $local_config_patch_json = Project::Easy::Config::string_from_template ( $local_config_patch_json, $vars ); $patch = $serializer->parse_string ($local_config_patch_json); $pack->fixup_path->patch ($patch); $pack->root->dir_io ('htdocs')->create; debug "done"; } 1; __DATA__ ######################################## IO::Easy etc/httpd.conf ######################################## PerlOptions +GlobalRequest ErrorLog "var/log/error_log" PidFile "var/run/{$project}-backend.pid" ######################################## IO::Easy etc/{$distro}/httpd.conf ######################################## ServerName 127.0.0.1 ServerAdmin {$admin} Listen {$port} ServerRoot {$root} LockFile {$root}/var/lock/accept DocumentRoot {$root}/htdocs/ User {$user} Group {$group} # Directive below is needed on old Fedora versions #TypesConfig /path/to/mime.types LoadModule perl_module {$apxs_libexec}/mod_perl.so LoadModule mime_module {$apxs_libexec}/mod_mime.so PerlConfigRequire {$root}/bin/mod_perl_startup Include {$root}/etc/httpd.conf MaxClients 15 StartServers 5 MinSpareServers 1 MaxSpareServers 3 MaxRequestsPerChild 100 ######################################## IO::Easy etc/{$project}-web-app.xml ######################################## ######################################## IO::Easy etc/{$project}-screens.xml ######################################## / ######################################## IO::Easy bin/mod_perl_startup ######################################## #!/usr/bin/perl -w use Class::Easy; use Project::Easy qw(script); use Web::App; use Web::App::Request; $Class::Easy::DEBUG = 'immediately'; warn "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nstarting Web::App mod_perl"; my $wa = Web::App->new ( project => $::project ); Web::App::Request->preload ($wa); warn "init done"; 1; ######################################## IO::Easy bin/backend ######################################## #!/usr/bin/perl use Class::Easy; use Project::Easy qw(script); use Project::Easy::Helper; # there initialization for core package my $instance = $::project; my $distro = $instance->distro; print "project '".$instance->id."' using distribution: '$distro'\n"; Project::Easy::Helper::status (); print "modules are ok\n"; my $backend = $instance->daemon ('backend'); print 'process id ' . ($backend->pid || '[undef]') . ' is' . ( $backend->running ? '' : ' not' ) . " running\n"; exit unless $ARGV[0]; if ($ARGV[0] eq 'stop') { if (! $backend->running) { print "no process is running\n"; exit; } print "awaiting process to kill… "; $backend->shutdown; print "\n"; } elsif ($ARGV[0] eq 'start') { if ($backend->running) { print "no way, process is running\n"; exit; } $backend->launch; } elsif ($ARGV[0] eq 'restart') { if ($backend->running) { my $finished = $backend->shutdown; unless ($finished) { print "pid is running after kill, please kill manually\n"; exit; } } $backend->launch; } ######################################## IO::Easy share/presentation/{$project}/index.xsl ######################################## hello, world! you have completed web-app installation and ready to start development. documentation: here click to view xml source ######################################## # IO::Easy::File global_config_patch_json ######################################## { "daemons" : { "backend" : { "conf_file" : "{$root}/etc/{$distro}/httpd.conf" } } } ######################################## # IO::Easy::File local_config_patch_json ######################################## { "daemons" : { "backend" : { "bin" : "{$httpd_bin}" } } } ######################################## IO::Easy share/presentation/symbols.ent ########################################
you have completed web-app installation and ready to start development.
documentation: here
click to view xml source