Changeset 1188 for obs_notify_generic/obs_notify_generic.pm
- Timestamp:
- Jun 17, 2015, 6:03:16 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
obs_notify_generic/obs_notify_generic.pm
r1184 r1188 34 34 use Data::Dumper; 35 35 use IPC::Run; 36 use Proc::Daemon; 36 37 use Time::Piece; 37 38 38 39 #use XML::Simple; 40 41 # stdout goes to /srv/obs/log/src_server.log 39 42 40 43 sub new … … 57 60 58 61 $type = "UNKNOWN" unless $type; 59 62 60 63 my $cfg_type; 61 64 if ( $self->{'cfg'}->{$type} ) { … … 72 75 #print "key: $key\n"; 73 76 #print "value: $value\n"; 74 if ( not( $paramRef->{$key} =~ /$value/ ) ) { 77 if ( not( exists($paramRef->{$key}) ) ) { 78 error_msg( "$type (". Data::Dumper->new( [$paramRef] )->Indent(0)->Dump ."): filter for '". $key ."' is invalid" ); 79 $match = 0; 80 # exit loop 81 last; 82 } elsif ( not( $paramRef->{$key} =~ /$value/ ) ) { 75 83 $match = 0; 76 84 } … … 86 94 $paramRef->{'project_path'}="/srv/obs/repos/" . $project; 87 95 } 88 my $check = join '|', keys %{$paramRef}; 96 # create regex, 97 # test against longest string first to avoid partial replacement ($repo, $repository) 98 my $check = join '|', sort { 99 length($b) <=> length($a) 100 } keys %{$paramRef}; 89 101 my $action = $entry->{'action'}; 90 102 $action =~ s/\$($check)/$paramRef->{$1}/g; 91 103 92 #print $action, "\n"; 93 my $in = undef; 94 my $out; 95 my $err; 96 my $rc; 97 eval { 98 my $process = 99 IPC::Run::start( [ "sh", "--login", "-c", "HOME=/usr/lib/obs $action", "2>&1" ], 100 \$in, \$out, \$err ); 101 $process->finish(); 102 $rc = $process->result(0); 103 }; 104 if ($@) { 105 106 #print "eval: ", $@; 107 $out = join( "\n", $@ ); 108 $rc = 127; 109 } 110 111 #print "rc: ", $rc, "\n"; 112 #print "out: ", $out, "\n"; 113 chomp($out); 114 115 #print "err: ", $err, "\n"; 116 $extra = { 117 'action_template' => $entry->{'action'}, 118 'action' => $action, 119 'returncode' => $rc, 120 'output' => $out, 121 }; 104 $extra = { 105 'action_template' => $entry->{'action'}, 106 'action' => $action, 107 }; 108 109 #$self->run_wait( $action, $extra ); 110 $self->run_daemon( $action, $extra ); 122 111 } 123 112 if ( $entry->{'log'} ) { … … 129 118 } 130 119 } 131 120 } 121 122 sub run_wait 123 { 124 my ( $self, $action, $extra ) = @_; 125 126 #print $action, "\n"; 127 my $in = undef; 128 my $out; 129 my $err; 130 my $rc; 131 eval { 132 my $process = 133 IPC::Run::start( [ "sh", "--login", "-c", "HOME=/usr/lib/obs $action", "2>&1" ], 134 \$in, \$out, \$err ); 135 $process->finish(); 136 $rc = $process->result(0); 137 }; 138 if ($@) { 139 140 #print "eval: ", $@; 141 $out = join( "\n", $@ ); 142 $rc = 127; 143 } 144 145 #print "rc: ", $rc, "\n"; 146 #print "out: ", $out, "\n"; 147 chomp($out); 148 149 #print "err: ", $err, "\n"; 150 $extra->{'returncode'} = $rc; 151 $extra->{'output'} = $out; 152 } 153 154 sub run_daemon 155 { 156 my ( $self, $action, $extra ) = @_; 157 158 my $daemon=Proc::Daemon->new(); 159 my $pid=$daemon->Init( { 160 exec_command => "date --rfc-3339=seconds; echo '$action'; $action", 161 child_STDOUT => "+>>" . $self->{'logfile'} . ".out.log", 162 child_STDERR => "+>>" . $self->{'logfile'} . ".out.log", 163 } ); 164 165 #print $daemon->Status($pid); 166 167 $extra->{'pid'} = $pid; 132 168 } 133 169
Note:
See TracChangeset
for help on using the changeset viewer.