/[pxelator]/lib/PXElator/daemons.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/daemons.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 321 by dpavlin, Fri Aug 28 16:20:43 2009 UTC revision 390 by dpavlin, Mon Sep 7 21:34:05 2009 UTC
# Line 35  sub audit { Line 35  sub audit {
35  mkdir "$server::conf/pid" unless -d "$server::conf/pid";  mkdir "$server::conf/pid" unless -d "$server::conf/pid";
36    
37  sub start_stop {  sub start_stop {
38          my $daemon = shift;          my ($daemon,$param) = @_;
39    
40            $daemon .= '.' . $param->{nr} if defined $param->{nr}; # XXX nr for kvm
41    
42          my $pid = $pids->{$daemon};          my $pid = $pids->{$daemon};
43          my $pid_path = $daemon;          my $pid_path = $daemon;
44          $pid_path =~ s{/}{-}g;          $pid_path =~ s{/}{-}g;
45          $pid_path = "$server::conf/pid/$pid_path";          $pid_path = "$server::conf/pid/$pid_path";
46    
47            warn "# start_stop $daemon ",dump( $param );
48    
49          if ( ! $pid && -e $pid_path ) {          if ( ! $pid && -e $pid_path ) {
50                  my $p = read_file $pid_path;                  my $p = read_file $pid_path;
51                  if ( kill 0, $p ) {                  if ( kill 0, $p ) {
# Line 72  sub start_stop { Line 76  sub start_stop {
76                  audit 'stopped', $daemon, pid => $pid;                  audit 'stopped', $daemon, pid => $pid;
77                  return qq|$daemon pid $pid stopped|;                  return qq|$daemon pid $pid stopped|;
78          } else {          } else {
79    
80                    $ENV{$_} = $param->{$_} foreach keys %$param;
81    
82                  if ( $pid = fork ) {                  if ( $pid = fork ) {
83                          # parent                          # parent
84                          $pids->{$daemon} = $pid;                          $pids->{$daemon} = $pid;
85                          write_file $pid_path, $pid;                          write_file $pid_path, $pid;
86                          audit 'forked', $daemon, pid => $pid;                          audit 'forked', $daemon, pid => $pid;
87    
88                            delete $ENV{$_} foreach keys %$param; # cleanup enviroment
89    
90                          return qq|$daemon pid $pid started|;                          return qq|$daemon pid $pid started|;
91                  } elsif ( defined $pid ) {                  } elsif ( defined $pid ) {
92                          # child                          # child
93                          my $invoke = 'start';                          my $invoke = 'start';
94                          $invoke = $1 if $daemon =~ s{/(.+)}{};                          $invoke = $1 if $daemon =~ s{/(.+)}{};
95    warn "XXX child ",dump( %ENV );
96                          if ( $daemon =~ m{dhcpd|tftpd|dnsd|syslogd} ) {                          if ( $daemon =~ m{dhcpd|tftpd|dnsd|syslogd} ) {
97                                  my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}";                                  my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}";
98                                  audit 'exec', $daemon, 'exec' => $exec;                                  audit 'exec', $daemon, 'exec' => $exec;
99                                  x11::xterm( $daemon => $exec );                                  x11::xterm( $daemon => $exec );
100                          } else {                          } else {
101                                  my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';                                  $daemon =~ s{\.\d+$}{} if defined $ENV{nr};
102    warn "XXXX $daemon\n";
103                                    my $eval = $daemon . '::' . $invoke . '(' . dump( $param ) . ')';
104                                  audit 'eval', $daemon, 'eval' => $eval;                                  audit 'eval', $daemon, 'eval' => $eval;
105                                  eval $eval;                                  eval $eval;
106                                  audit 'error', $daemon, error => $@  if $@;                                  audit 'error', $daemon, error => $@  if $@;

Legend:
Removed from v.321  
changed lines
  Added in v.390

  ViewVC Help
Powered by ViewVC 1.1.26