use FS::cust_bill;
use FS::cust_pkg;
-$Debug = 2; # >= 2 will log packet contents, including potentially compromising
+$Debug = 1; # >= 2 will log packet contents, including potentially compromising
# information
$shutdown = 0;
my $user = shift or die &usage;
my $machine = shift or die &usage;
-my $pid_file = "/var/run/freeside-selfservice-server.$user.pid";
-#my $pid_file = "/var/run/freeside-selfservice-server.$user.pid"; $FS::UID::datasrc not posible, but should include machine name at least, hmm
+my $tag = scalar(@ARGV) ? shift : '';
+
+# $FS::UID::datasrc not posible
+my $pid_file = "/var/run/freeside-selfservice-server.$user.$machine.pid";
my $lock_file = "/usr/local/etc/freeside/selfservice.$machine.writelock";
open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!";
my $conf = new FS::Conf;
-if ($conf->exists('selfservice_server-quiet')) {
- $FS::cust_bill::quiet = 1;
- $FS::cust_pkg::quiet = 1;
-}
-
my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name?
my $warnkids=0;
my($writer,$reader,$error) = (new IO::Handle, new IO::Handle, new IO::Handle);
warn "connecting to $machine\n" if $Debug;
- $ssh_pid = sshopen2($machine,$reader,$writer,$clientd);
+ $ssh_pid = sshopen2($machine,$reader,$writer,$clientd,$tag);
# nstore_fd(\*writer, {'hi'=>'there'});
warn "receiving packet from client\n" if $Debug;
- my $packet = fd_retrieve($reader);
+ my $packet = eval { fd_retrieve($reader); };
+ if ( $@ ) {
+ warn "Storable error receiving packet from client".
+ " (assuming lost connection): $@\n"
+ if $Debug;
+ if ( $ssh_pid ) {
+ warn "sending TERM signal to ssh process $ssh_pid\n" if $Debug;
+ kill 'TERM', $ssh_pid;
+ $ssh_pid = 0;
+ }
+ last;
+ }
warn "packet received\n".
join('', map { " $_=>$packet->{$_}\n" } keys %$packet )
if $Debug > 1;
}
+ warn "connection lost, reconnecting\n" if $Debug;
+ sleep 3;
+
}
###