diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index bafe7e47060774bc804bcab0474ae8f0d1b9b656..b93f07cc7a58c9c717e13303941b4b720f0f92a0 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
#===============================================================================
sub read_configfile {
my $cfg;
#===============================================================================
sub read_configfile {
my $cfg;
- if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
+ if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
if( -r $cfg_file ) {
$cfg = Config::IniFiles->new( -file => $cfg_file );
} else {
if( -r $cfg_file ) {
$cfg = Config::IniFiles->new( -file => $cfg_file );
} else {
daemon_log("shutting down gosa-si-server", 1);
daemon_log("shutting down gosa-si-server", 1);
- system("killall gosa-si-server");
+ system("kill `ps -C gosa-si-server -o pid=`");
}
$SIG{INT} = \&sig_int_handler;
}
$SIG{INT} = \&sig_int_handler;
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
$kernel->sig(USR1 => "sig_handler");
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
$kernel->sig(USR1 => "sig_handler");
+ $kernel->sig(USR2 => "create_packages_list_db");
}
sub sig_handler {
}
sub sig_handler {
sub trigger_db_loop {
my ($kernel) = @_ ;
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
sub trigger_db_loop {
my ($kernel) = @_ ;
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
- $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay);
+ $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay);
}
sub watch_for_done_jobs {
}
sub watch_for_done_jobs {
my ($kernel,$heap) = @_[KERNEL, HEAP];
# check gosa job queue for jobs with executable timestamp
my ($kernel,$heap) = @_[KERNEL, HEAP];
# check gosa job queue for jobs with executable timestamp
- my $timestamp = &get_time();
- my $sql_statement = "SELECT * FROM ".$job_queue_tn.
- " WHERE status='waiting' AND timestamp<'$timestamp'";
- my $res = $job_db->select_dbentry( $sql_statement );
+ my $timestamp = &get_time();
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE status='waiting' AND (CAST (timestamp AS INTEGER) + 120) < $timestamp ORDER BY timestamp";
+ my $res = $job_db->exec_statement( $sql_statement );
+
+ # Merge all new jobs that would do the same actions
+ my @drops;
+ my $hits;
+ foreach my $hit (reverse @{$res} ) {
+ my $macaddress= lc @{$hit}[8];
+ my $headertag= @{$hit}[5];
+ if(defined($hits->{$macaddress}->{$headertag})) {
+ push @drops, "DELETE FROM $job_queue_tn WHERE id = '$hits->{$macaddress}->{$headertag}[0]'";
+ }
+ $hits->{$macaddress}->{$headertag}= $hit;
+ }
- while( my ($id, $hit) = each %{$res} ) {
- my $jobdb_id = $hit->{id};
- my $macaddress = $hit->{'macaddress'};
- my $job_msg = $hit->{'xmlmessage'};
- daemon_log("J DEBUG: its time to execute $job_msg", 7);
- my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$macaddress'";
- my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
- # expect macaddress is unique!!!!!!
- my $target = $res_hash->{1}->{hostname};
-
- # change header
- $job_msg =~ s/<header>job_/<header>gosa_/;
-
- # add sqlite_id
- $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
-
- $job_msg =~ /<header>(\S+)<\/header>/;
- my $header = $1 ;
- my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");
-
- # update status in job queue to 'processing'
- $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
- }
+ # Delete new jobs with a matching job in state 'processing'
+ foreach my $macaddress (keys %{$hits}) {
+ foreach my $jobdb_headertag (keys %{$hits->{$macaddress}}) {
+ my $jobdb_id = @{$hits->{$macaddress}->{$jobdb_headertag}}[0];
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE macaddress LIKE '$macaddress' AND headertag='$jobdb_headertag' AND status='processing'";
+ my $res = $job_db->exec_statement( $sql_statement );
+ foreach my $hit (@{$res}) {
+ push @drops, "DELETE FROM $job_queue_tn WHERE id = '$jobdb_id'";
+ }
+ }
+ }
+
+ # Commit deletion
+ $job_db->exec_statementlist(\@drops);
+
+ # Look for new jobs that could be executed
+ foreach my $macaddress (keys %{$hits}) {
+
+ # Look if there is an executing job
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE macaddress LIKE '$macaddress' AND status='processing'";
+ my $res = $job_db->exec_statement( $sql_statement );
+
+ # Skip new jobs for host if there is a processing job
+ if(defined($res) and defined @{$res}[0]) {
+ next;
+ }
+
+ foreach my $jobdb_headertag (keys %{$hits->{$macaddress}}) {
+ my $jobdb_id = @{$hits->{$macaddress}->{$jobdb_headertag}}[0];
+ my $job_msg = @{$hits->{$macaddress}->{$jobdb_headertag}}[7];
+
+ daemon_log("J DEBUG: its time to execute $job_msg", 7);
+ my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$macaddress'";
+ my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
+
+ # expect macaddress is unique!!!!!!
+ my $target = $res_hash->{1}->{hostname};
+
+ # change header
+ $job_msg =~ s/<header>job_/<header>gosa_/;
+
+ # add sqlite_id
+ $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
+
+ $job_msg =~ /<header>(\S+)<\/header>/;
+ my $header = $1 ;
+ my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");
+
+ # update status in job queue to 'processing'
+ $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'";
+ my $res = $job_db->update_dbentry($sql_statement);
+
+ # We don't want parallel processing
+ last;
+ }
+ }
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
}
$kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
}
my $heap;
my $ldap_handle;
my $heap;
my $ldap_handle;
- if (not defined $session_id ) { $session_id = 0 };
+ if (not defined $session_id ) { $session_id = 0 };
if ($session_id == 0) {
if ($session_id == 0) {
- daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7);
- $ldap_handle = Net::LDAP->new( $ldap_uri );
+ daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7);
+ $ldap_handle = Net::LDAP->new( $ldap_uri );
$ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
} else {
$ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
} else {
- my $session_reference = $global_kernel->ID_id_to_session($session_id);
- if( defined $session_reference ) {
- $heap = $session_reference->get_heap();
- }
+ my $session_reference = $global_kernel->ID_id_to_session($session_id);
+ if( defined $session_reference ) {
+ $heap = $session_reference->get_heap();
+ }
- if (not defined $heap) {
- daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7);
- return;
- }
+ if (not defined $heap) {
+ daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7);
+ return;
+ }
- if (not exists $heap->{ldap_handle}) {
- # create new ldap handle
- $ldap_handle = Net::LDAP->new( $ldap_uri );
+ # TODO: This "if" is nonsense, because it doesn't prove that the
+ # used handle is still valid - or if we've to reconnect...
+ #if (not exists $heap->{ldap_handle}) {
+ $ldap_handle = Net::LDAP->new( $ldap_uri );
$ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
$ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
- # add ldap handle to heap
- $heap->{ldap_handle} = $ldap_handle;
- }
- }
+ $heap->{ldap_handle} = $ldap_handle;
+ #}
+ }
return $ldap_handle;
}
return $ldap_handle;
}
filter => "$search"
);
filter => "$search"
);
- if ($mesg->count) {
- my @entries = $mesg->entries;
- foreach my $entry (@entries) {
- # Only modify entry if it is not set to '$state'
- if ($entry->get_value("FAIstate") ne "$state"){
- daemon_log("$session_id INFO: Setting FAIstate to '$state' for ".$entry->dn, 5);
- my $result;
- my %tmp = map { $_ => 1 } $entry->get_value("objectClass");
- if (exists $tmp{'FAIobject'}){
- if ($state eq ''){
- $result= $ldap_handle->modify($entry->dn, changes => [
- delete => [ FAIstate => [] ] ]);
- } else {
- $result= $ldap_handle->modify($entry->dn, changes => [
- replace => [ FAIstate => $state ] ]);
- }
- } elsif ($state ne ''){
- $result= $ldap_handle->modify($entry->dn, changes => [
- add => [ objectClass => 'FAIobject' ],
- add => [ FAIstate => $state ] ]);
- }
-
- # Errors?
- if ($result->code){
- daemon_log("$session_id Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
- }
-
- } else {
- daemon_log("$session_id DEBUG FAIstate at host '$_' already at state '$st'", 7);
- }
- }
- }
+ if ($mesg->count) {
+ my @entries = $mesg->entries;
+ foreach my $entry (@entries) {
+ # Only modify entry if it is not set to '$state'
+ if ($entry->get_value("FAIstate") ne "$state"){
+ daemon_log("$session_id INFO: Setting FAIstate to '$state' for ".$entry->dn, 5);
+ my $result;
+ my %tmp = map { $_ => 1 } $entry->get_value("objectClass");
+ if (exists $tmp{'FAIobject'}){
+ if ($state eq ''){
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ delete => [ FAIstate => [] ] ]);
+ } else {
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ replace => [ FAIstate => $state ] ]);
+ }
+ } elsif ($state ne ''){
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ add => [ objectClass => 'FAIobject' ],
+ add => [ FAIstate => $state ] ]);
+ }
+
+ # Errors?
+ if ($result->code){
+ daemon_log("$session_id Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
+ }
+ } else {
+ daemon_log("$session_id DEBUG FAIstate at host '".$entry->dn."' already at state '$st'", 7);
+ }
+ }
+ }
# if no ldap handle defined
} else {
daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1);
# if no ldap handle defined
} else {
daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1);
);
if($mesg->count) {
foreach my $entry(@{$mesg->{'entries'}}) {
);
if($mesg->count) {
foreach my $entry(@{$mesg->{'entries'}}) {
- my ($server, $tag, $release, $sections)= split /\|/, $entry->get_value('FAIrepository');
- my $line = "deb $server $release";
- $sections =~ s/,/ /g;
- $line.= " $sections";
- print $fh $line."\n";
+ foreach my $value(@{$entry->get_value('FAIrepository', asref => 1)}) {
+ my ($server, $tag, $release, $sections)= split /\|/, $value;
+ my $line = "deb $server $release";
+ $sections =~ s/,/ /g;
+ $line.= " $sections";
+ print $fh $line."\n";
+ }
}
}
}
}
}
}
sub create_packages_list_db {
my ($ldap_handle, $sources_file) = @_ ;
sub create_packages_list_db {
my ($ldap_handle, $sources_file) = @_ ;
- if (not defined $ldap_handle) {
- daemon_log("0 ERROR: no ldap_handle available to create_packages_list_db", 1);
- return;
- }
+ if (not defined $ldap_handle) {
+ $ldap_handle= &get_ldap_handle();
+
+ if (not defined $ldap_handle) {
+ daemon_log("0 ERROR: no ldap_handle available to create_packages_list_db", 1);
+ return;
+ }
+ }
+
if (not defined $sources_file) {
$sources_file = &create_sources_list($ldap_handle);
}
if (not defined $sources_file) {
$sources_file = &create_sources_list($ldap_handle);
}
$bus_activ = "false"
}
$bus_activ = "false"
}
-
-
-# delete old DBsqlite lock files
-#unlink('/tmp/gosa_si_lock*');
-
# connect to gosa-si job queue
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table($job_queue_tn, \@job_queue_col_names);
# connect to gosa-si job queue
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table($job_queue_tn, \@job_queue_col_names);
$login_users_db->create_table($login_users_tn, \@login_users_col_names);
# connect to fai_server_db and fai_release_db
$login_users_db->create_table($login_users_tn, \@login_users_col_names);
# connect to fai_server_db and fai_release_db
+unlink($fai_server_file_name);
$fai_server_db = GOSA::DBsqlite->new($fai_server_file_name);
$fai_server_db->create_table($fai_server_tn, \@fai_server_col_names);
$fai_server_db->create_table($fai_release_tn, \@fai_release_col_names);
$fai_server_db = GOSA::DBsqlite->new($fai_server_file_name);
$fai_server_db->create_table($fai_server_tn, \@fai_server_col_names);
$fai_server_db->create_table($fai_release_tn, \@fai_release_col_names);