#!/opt/casp/tools/bin/linux2/perl5/bin/perl -I/opt/casp/tools/bin/linux2/perl5/lib -I/opt/casp use INSTALL::common; use INSTALL::global; use INSTALL::parameter; use INSTALL::os; use strict; my $pParameters = \%INSTALL::parameter::variables; #============================================================================== #------------------------ Make sure that the user is a root #============================================================================== if ($> != 0) { print STDOUT "You will need to be root to execute this script.\n"; exit 1; } #============================================================================== #------------------------ Default global values #============================================================================== $pParameters->{asphome} = "/opt/casp"; $pParameters->{com_layer} = "chilicom"; INSTALL::common::set_standard_globals; my $pGlobals = \%INSTALL::global::variables; my $pOS = \%INSTALL::os::Details; #============================================================================== #------------------------ Validate all the required parameters. #============================================================================== my %PARAM_REQUIREMENTS = ( REQUIRED => [ 'engine(_dir|_name)?' ], OPTIONAL => [ 'boot_enabled', 'query_enabled' ] ); unless(INSTALL::parameter::verify(%PARAM_REQUIREMENTS)) { exit (1); } #============================================================================== #-------------------Configure boot settings #============================================================================== use INSTALL::caspeng; sub configure_boot { my @matches = grep { /engine(_dir|_name)?(_[0-9])?/ } keys %{$pParameters}; my @Engine_Params; foreach my $match (@matches) { my ($path); if ($match =~ /_name/) { $path = "$pParameters->{asphome}/$pParameters->{$match}"; } else { $path = $pParameters->{$match}; } my $realpath = realpath($path); unless(defined $realpath) { error("engine=$path refers to an invalid path."); exit(1); } else { push @Engine_Params, $realpath; } } use INSTALL::ini; my $pIni = INSTALL::ini::open($pGlobals->{installed_db}); if (not $pIni) { exit(not error("Could not open $pGlobals->{installed_db}.")); } my %Engine_Exists = map { $_ => $_ } INSTALL::ini::getSectionNames($pIni); foreach my $engine (@Engine_Params) { unless(exists $Engine_Exists{$engine}) { error("Unknown engine specified: ", " $engine"); exit(1); } } my $status; if (exists $pParameters->{boot_enabled}) { # Need to actually perform configuration. my $value = (boolean_value($pParameters->{boot_enabled}) > 0) ? 1 : 0; foreach my $engine (@Engine_Params) { my $pSection = INSTALL::ini::openSection($pIni,$engine); if (not $pSection) { exit(not error("Could not open section $engine in $pGlobals->{installed_db}.")); } $pSection->{engine_asponboot} = $value; if ($value) { INSTALL::caspeng::install_boot_script($pSection); } else { INSTALL::caspeng::uninstall_boot_script($pSection); } } INSTALL::ini::save($pIni,$pGlobals->{installed_db}); $status = $value; } else { foreach my $engine (@Engine_Params) { my $pSection = INSTALL::ini::openSection($pIni,$engine); if (not $pSection) { exit(not error("Could not open section $engine in $pGlobals->{installed_db}.")); } $status |= (boolean_value($pSection->{engine_asponboot}) > 0) ? 1 : 0; } } return($status); } if (interactive) { use INSTALL::caspeng; my @server_list = INSTALL::caspeng::load_engines(); my $pServerStats; my $description_message = (" ". "This functionality provides a hands-off mechanism for automatically restarting ". "Sun Chili!Soft ASP on system reboot. While this is the default behavior of our ". "installation, some people like to disable this feature, while others like ". "to enable it or disable it at various times. This script provides gives you those ". "options."); if (@server_list != 1) { my @server_options; foreach my $pServerStats (@server_list) { my $type = ucfirst($pServerStats->{webserver_type}); push @server_options, ("$pServerStats->{engine_name} associated with a $type Webserver:\n". " Webserver conf file: $pServerStats->{webserver_conf}\n". " Webserver port number: $pServerStats->{webserver_port}\n" ); } my $response = INSTALL::query::user_menu ("Sun Chili!Soft ASP - Boot Configuration", "By selecting one of the servers listed below, you will later be given ". "the option of changing the so called 'start upon system boot' functionality ". "of Sun Chili!Soft ASP.". $description_message, "Which Sun Chili!Soft ASP server would you like to reconfigure", "terminal_mark=?", @server_options, "default=Cancel reconfiguration." ); $description_message = ""; if ($response > @server_list) { report("Status: ","Reconfiguration canceled."); exit(1); } else { $pServerStats = $server_list[$response - 1]; $pParameters->{engine_dir} = $pServerStats->{engine_dir}; } } else { $pParameters->{engine_dir} = $server_list[0]->{engine_dir}; $pServerStats = $server_list[0]; } my $type = ucfirst($pServerStats->{webserver_type}); my $enabled = (boolean_value($pServerStats->{engine_asponboot}) ? "enabled" : "disabled"); my $response = INSTALL::query::user_menu ("Sun Chili!Soft ASP - Boot Configuration", "You have chosen to reconfigure the 'start on system boot' functionality ". "of Sun Chili!Soft ASP.${description_message} The server to be altered has the following associated details:\n ". "\n". " $pServerStats->{engine_name} (Associated with a $type Webserver):\n". " Webserver conf file: $pServerStats->{webserver_conf}\n". " Webserver port: $pServerStats->{webserver_port}\n". " Current 'start on system boot' setting: $enabled", "What would you like to do", "terminal_mark=?", "Enable starting the ASP server on system boot.", "Disable starting the ASP server on system boot.", "default=Keep the current setting." ); if ($response == 1) { $pParameters->{boot_enabled} = 1; } elsif ($response == 2) { $pParameters->{boot_enabled} = 0; } else { report("Status: Start on system boot was left $enabled."); exit(configure_boot() ? 0 : 1); } # No boot_enabled parameter means merely perform a query. } if (configure_boot()) { interactive && report("Status: Start on system boot was enabled."); exit(0); } else { interactive && report("Status: Start on system boot was disabled."); exit(1); }