diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 3f369825d2b1995db620fc5c711d1beec48bb0fd..895ca1edcd87d7a7edfe36d9ce6821629777109a 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my $repo_path;
my %repo_dirs=();
+my $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'};
+
# Variables declared in config file are always set to 'our'
our (%cfg_defaults, $log_file, $pid_file, $pid,
$server_ip, $server_port, $ClientPackages_key, $dns_lookup,
@@ -315,7 +317,7 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu
"messaging" => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'],
"foreign-clients" => [\$foreign_clients_file_name, '/var/lib/gosa-si/foreign_clients.db'],
"source-list" => [\$sources_list, '/etc/apt/sources.list'],
- "repo-path" => [\$repo_path, '/srv/www'],
+ "repo-path" => [\$repo_path, '/srv/www/debian'],
"debian-arch" => [\$arch, 'i386'],
"ldap-uri" => [\$ldap_uri, ""],
"ldap-base" => [\$ldap_base, ""],
}
}
-
-#=== FUNCTION ================================================================
-# NAME: check_cmdline_param
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: validates commandline parameter
-#===============================================================================
-sub check_cmdline_param () {
- my $err_counter = 0;
-
- # Check configuration file
- if(not defined($cfg_file)) {
- $cfg_file = "/etc/gosa-si/server.conf";
- if(! -r $cfg_file) {
- print STDERR "Please specify a config file.\n";
- $err_counter++;
- }
- }
-
- # Prepare identification which gosa-si parts should be debugged and which not
- if (defined $debug_parts)
- {
- if ($debug_parts =~ /^\d+$/)
- {
- $debug_parts_bitstring = unpack("B32", pack("N", $debug_parts));
- }
- else
- {
- print STDERR "Value '$debug_parts' invalid for option d (number expected)\n";
- $err_counter++;
- }
- }
-
- # Exit if an error occour
- if( $err_counter > 0 ) { &usage( "", 1 ); }
-}
-
-
-#=== FUNCTION ================================================================
-# NAME: check_pid
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: handels pid processing
-#===============================================================================
-sub check_pid {
- $pid = -1;
- # Check, if we are already running
- if( open( my $LOCK_FILE, "<", "$pid_file" ) ) {
- $pid = <$LOCK_FILE>;
- if( defined $pid ) {
- chomp( $pid );
- if( -f "/proc/$pid/stat" ) {
- my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
- if( $stat ) {
- print STDERR "\nERROR: Already running!\n";
- close( $LOCK_FILE );
- exit -1;
- }
- }
- }
- close( $LOCK_FILE );
- unlink( $pid_file );
- }
-
- # create a syslog msg if it is not to possible to open PID file
- if (not sysopen(my $LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
- my($msg) = "Couldn't obtain lockfile '$pid_file' ";
- if (open(my $LOCK_FILE, '<', $pid_file)
- && ($pid = <$LOCK_FILE>))
- {
- chomp($pid);
- $msg .= "(PID $pid)\n";
- } else {
- $msg .= "(unable to read PID)\n";
- }
- if( ! ($foreground) ) {
- openlog( $0, "cons,pid", "daemon" );
- syslog( "warning", $msg );
- closelog();
- }
- else {
- print( STDERR " $msg " );
- }
- exit( -1 );
- }
-}
-
#=== FUNCTION ================================================================
# NAME: import_modules
# PARAMETERS: module_path - string - abs. path to the directory the modules
daemon_log("shutting down gosa-si-server", 1);
- $global_kernel->yield('shutdown');
+ $global_kernel->yield(TCP_SERVER => 'shutdown');
# to be removed rather crude !!
#system("kill `ps -C gosa-si-server -o pid=`");
return;
}
+sub start_daemon {
+
+ #to prevent zombie child
+ $SIG{CHLD} = 'IGNORE';
+
+ if( ! $foreground ) {
+ chdir '/' or die "Can't chdir to /: $!";
+ umask 0;
+ open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!";
+ open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!";
+ open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!";
+ defined($pid = fork) or die "Can't fork: $!";
+ exit if $pid;
+ setsid or die "Can't start a new session: $!";
+ }
+ return;
+}
+
+sub put_version {
+
+ # parse head url and revision from svn
+ $server_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/;
+ $server_headURL = defined $1 ? $1 : 'unknown' ;
+ $server_revision = defined $2 ? $2 : 'unknown' ;
+ if ($server_headURL =~ /\/tag\// ||
+ $server_headURL =~ /\/branches\// ) {
+ $server_status = "stable";
+ } else {
+ $server_status = "developmental" ;
+ }
+ return;
+}
+
+sub get_perms_admin {
+# Determine root uid and adm gid, used for creating log files
+ $root_uid = getpwnam('root');
+ $adm_gid = getgrnam('adm');
+ if(not defined $adm_gid){
+ $adm_gid = getgrnam('root');
+ }
+ return;
+}
+
+sub open_log {
+ # Prepare log file and set permissions
+ open(my $log, ">>", "$log_file");
+ close($log);
+ chmod(0440, $log_file);
+ chown($root_uid, $adm_gid, $log_file);
+
+ return;
+}
+
+sub create_pid {
+ # Create the PID object
+ $pid = File::Pid->new({ file => $pid_file });
+
+ # Write the PID file
+ $pid->write;
+
+ return;
+}
+
#
#==== MAIN = main ==============================================================
#
}
# read and set config parameters
-#&check_cmdline_param ;
-#&read_configfile($cfg_file, %cfg_defaults);
&read_configfile($config, %cfg_defaults);
-#&check_pid;
-
-# not sure but seems to be for igonring phantom
-$SIG{CHLD} = 'IGNORE';
-
-# Create the PID object
-# Ensure you put a name that won't clobber
-# another program's PID file
-$pid = File::Pid->new({
- file => $pid_file,
-});
-
-# Write the PID file
-$pid->write;
-
-# forward error messages to logfile
-if( ! $foreground ) {
- open( STDIN, '+>/dev/null' );
- open( STDOUT, '+>&STDIN' );
- open( STDERR, '+>&STDIN' );
-}
-
-# Just fork, if we are not in foreground mode
-if( ! $foreground ) {
- chdir '/' or die "Can't chdir to /: $!";
- $pid = fork;
- setsid or die "Can't start a new session: $!";
- umask 0;
-#} else {
-# $pid = $$;
-}
-
-# Do something useful - put our PID into the pid_file
-#if( 0 != $pid ) {
-# open( my $LOCK_FILE, ">", "$pid_file" );
-# print $LOCK_FILE "$pid\n";
-# close( $LOCK_FILE );
-# if( !$foreground ) {
-# exit( 0 )
-# };
-#}
-
-# parse head url and revision from svn
-my $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'};
-$server_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/;
-$server_headURL = defined $1 ? $1 : 'unknown' ;
-$server_revision = defined $2 ? $2 : 'unknown' ;
-if ($server_headURL =~ /\/tag\// ||
- $server_headURL =~ /\/branches\// ) {
- $server_status = "stable";
-} else {
- $server_status = "developmental" ;
-}
-# Prepare log file and set permissions
-$root_uid = getpwnam('root');
-$adm_gid = getgrnam('adm');
-open(my $FH, ">>", "$log_file");
-close($FH);
-chmod(0440, $log_file);
-chown($root_uid, $adm_gid, $log_file);
-chown($root_uid, $adm_gid, "/var/lib/gosa-si");
+
+# daemonize the program
+&start_daemon($pid, $foreground);
+
+# create pid file
+&create_pid($pid, $pid_file);
+
+# Determine root uid and adm gid, used for creating log files
+&get_perms_admin($root_uid, $adm_gid);
+
+# put version
+&put_version($server_status_hash, $server_version, $server_headURL, $server_revision, $server_status);
+
+#open log file
+&open_log($root_uid, $adm_gid, $log_file);
+
+# prepare directory for databases
+mkpath('/var/lib/gosa-si', 0, {owner=>'root', group=>'root'});
+
+# remove leftover files in tmp for packaged.db populate
+rmtree( '/tmp/packages_list_db',0,1);
+
+# remove list of sources from apt.sources.list
+unlink '/tmp/gosa_si_tmp_sources_list';
+
+# remove marker that the list creation is in progress
+unlink '/tmp/packages_list_creation_in_progress';
daemon_log(" ", 1);
daemon_log("$0 started!", 1);
{
no strict "refs";
- if ($db_module eq "DBmysql") {
-
- daemon_log("0 INFO: importing database module '$db_module'", 1);
+ daemon_log("0 INFO: importing database module '$db_module'", 1);
+ if ($db_module eq "DBmysql") {
+
# connect to incoming_db
$incoming_db = ("GOsaSI::".$db_module)->new($main::mysql_database, $main::mysql_host, $main::mysql_username, $main::mysql_password);
} elsif ($db_module eq "DBsqlite") {
- daemon_log("0 INFO: importing database module '$db_module'", 1);
+ daemon_log("0 INFO: Removing SQLlite lock files", 1);
+
+ # delete old DBsqlite lock files to be replace by rmtree !!
+ system('rm -f /var/lib/gosa-si/*.si.lock*');
+ #rmtree( '/var/lib/gosa-si/',0,1);
# connect to incoming_db
unlink($incoming_file_name);
$incoming_db = ("GOsaSI::".$db_module)->new($incoming_file_name);
- chmod(0640, $incoming_file_name);
- chown($root_uid, $adm_gid, $incoming_file_name);
+ #chmod(0640, $incoming_file_name);
+ #chown($root_uid, $adm_gid, $incoming_file_name);
# connect to gosa-si job queue
$job_db = ("GOsaSI::".$db_module)->new($job_queue_file_name);
- chmod(0640, $job_queue_file_name);
- chown($root_uid, $adm_gid, $job_queue_file_name);
+ #chmod(0640, $job_queue_file_name);
+ #chown($root_uid, $adm_gid, $job_queue_file_name);
# connect to known_clients_db
#unlink($known_clients_file_name);
$known_clients_db = ("GOsaSI::".$db_module)->new($known_clients_file_name);
- chmod(0640, $known_clients_file_name);
- chown($root_uid, $adm_gid, $known_clients_file_name);
+ #chmod(0640, $known_clients_file_name);
+ #chown($root_uid, $adm_gid, $known_clients_file_name);
# connect to foreign_clients_db
#unlink($foreign_clients_file_name);
$foreign_clients_db = ("GOsaSI::".$db_module)->new($foreign_clients_file_name);
- chmod(0640, $foreign_clients_file_name);
- chown($root_uid, $adm_gid, $foreign_clients_file_name);
+ #chmod(0640, $foreign_clients_file_name);
+ #chown($root_uid, $adm_gid, $foreign_clients_file_name);
# connect to known_server_db
- unlink($known_server_file_name); # do not delete, gosa-si-server should be forced to check config file and dns at each start
+ #unlink($known_server_file_name); # do not delete, gosa-si-server should be forced to check config file and dns at each start
$known_server_db = ("GOsaSI::".$db_module)->new($known_server_file_name);
- chmod(0640, $known_server_file_name);
- chown($root_uid, $adm_gid, $known_server_file_name);
+ #chmod(0640, $known_server_file_name);
+ #chown($root_uid, $adm_gid, $known_server_file_name);
# connect to login_usr_db
#unlink($login_users_file_name);
$login_users_db = ("GOsaSI::".$db_module)->new($login_users_file_name);
- chmod(0640, $login_users_file_name);
- chown($root_uid, $adm_gid, $login_users_file_name);
+ #chmod(0640, $login_users_file_name);
+ #chown($root_uid, $adm_gid, $login_users_file_name);
# connect to fai_server_db
- unlink($fai_server_file_name);
+ #unlink($fai_server_file_name);
$fai_server_db = ("GOsaSI::".$db_module)->new($fai_server_file_name);
- chmod(0640, $fai_server_file_name);
- chown($root_uid, $adm_gid, $fai_server_file_name);
+ #chmod(0640, $fai_server_file_name);
+ #chown($root_uid, $adm_gid, $fai_server_file_name);
# connect to fai_release_db
- unlink($fai_release_file_name);
+ #unlink($fai_release_file_name);
$fai_release_db = ("GOsaSI::".$db_module)->new($fai_release_file_name);
- chmod(0640, $fai_release_file_name);
- chown($root_uid, $adm_gid, $fai_release_file_name);
+ #chmod(0640, $fai_release_file_name);
+ #chown($root_uid, $adm_gid, $fai_release_file_name);
# connect to packages_list_db
- unlink($packages_list_under_construction);
+ #unlink($packages_list_under_construction);
$packages_list_db = ("GOsaSI::".$db_module)->new($packages_list_file_name);
- chmod(0640, $packages_list_file_name);
- chown($root_uid, $adm_gid, $packages_list_file_name);
+ #chmod(0640, $packages_list_file_name);
+ #chown($root_uid, $adm_gid, $packages_list_file_name);
# connect to messaging_db
#unlink($messaging_file_name);
$messaging_db = ("GOsaSI::".$db_module)->new($messaging_file_name);
- chmod(0640, $messaging_file_name);
- chown($root_uid, $adm_gid, $messaging_file_name);
+ #chmod(0640, $messaging_file_name);
+ #chown($root_uid, $adm_gid, $messaging_file_name);
}
}
$opsi_client = new JSON::RPC::Client;
}
+daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port' ", 1);
POE::Component::Server::TCP->new(
Alias => "TCP_SERVER",
}
);
-daemon_log("0 INFO: start socket for incoming xml messages at port '$server_port' ", 1);
-
# create session for repeatedly checking the job queue for jobs
POE::Session->create(
inline_states => {
- _start => \&session_start,
+ _start => \&session_start,
register_at_foreign_servers => \®ister_at_foreign_servers,
- control_server_registration => \&control_server_registration,
+ control_server_registration => \&control_server_registration,
sig_handler => \&sig_handler,
next_task => \&next_task,
task_result => \&handle_task_result,
watch_for_new_messages => \&watch_for_new_messages,
watch_for_delivery_messages => \&watch_for_delivery_messages,
watch_for_done_messages => \&watch_for_done_messages,
- watch_for_new_jobs => \&watch_for_new_jobs,
+ watch_for_new_jobs => \&watch_for_new_jobs,
watch_for_modified_jobs => \&watch_for_modified_jobs,
watch_for_done_jobs => \&watch_for_done_jobs,
watch_for_opsi_jobs => \&watch_for_opsi_jobs,
create_packages_list_db => \&run_create_packages_list_db,
create_fai_server_db => \&run_create_fai_server_db,
create_fai_release_db => \&run_create_fai_release_db,
- recreate_packages_db => \&run_recreate_packages_db,
+ recreate_packages_db => \&run_recreate_packages_db,
session_run_result => \&session_run_result,
session_run_debug => \&session_run_debug,
session_run_done => \&session_run_done,