X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-queued;h=398b03d1293aa9341d81a2e3fd00f11ef181b68c;hb=cc4b5ec5fdbf35c919cf7903b67cf6a1309a229d;hp=4786132c62837152f59c14de6aa1c15ea00577f0;hpb=ae02d1178c6859f7a0a5e4a22c685de5f0477568;p=freeside.git diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 4786132c6..398b03d12 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -38,16 +38,15 @@ drop_root(); $ENV{HOME} = (getpwuid($>))[7]; #for ssh warn "connecting to database\n" if $DEBUG; -#$@ = 'not connected'; -#while ( $@ ) { -# eval { adminsuidsetup $user; }; -# if ( $@ ) { -# warn $@; -# warn "sleeping for reconnect...\n"; -# sleep 5; -# } -#} -adminsuidsetup $user; +$@ = 'not connected'; +while ( $@ ) { + eval { adminsuidsetup $user; }; + if ( $@ ) { + warn $@; + warn "sleeping for reconnect...\n"; + sleep 5; + } +} my $log = FS::Log->new('queue'); logfile( "%%%FREESIDE_LOG%%%/queuelog.". $FS::UID::datasrc ); @@ -219,8 +218,13 @@ while (1) { # don't put @args in the log, may expose passwords $log->info('starting job ('.$ljob->job.')'); warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG; + # switch user only if a job user is available + my $oldCurrentUser = $FS::CurrentUser::CurrentUser; + my $jobuser = $ljob->access_user; + local $FS::CurrentUser::CurrentUser = $jobuser if $jobuser; local $FS::UID::AutoCommit = 0; # so that we can clean up failures eval $eval; #throw away return value? suppose so + $FS::CurrentUser::CurrentUser = $oldCurrentUser if $jobuser; if ( $@ ) { dbh->rollback; my %hash = $ljob->hash;