summaryrefslogtreecommitdiff
path: root/fs_selfservice/FS-SelfService/freeside-selfservice-soap-server
blob: 869a8aecc08ee04bd186dcb2abda22001c161200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w
#
# freeside-selfservice-soap-server
#

use strict;
use Fcntl qw(:flock);
use POSIX;
use Getopt::Std;
use SOAP::Transport::HTTP;
use FS::SelfService;

use vars qw( $opt_p $opt_d $opt_s );
use vars qw( $DEBUG );

getopts("s:p:d");
$DEBUG = $opt_d;
my $tag = $opt_s ? $opt_s : '';
$tag = ($opt_s ? ':' : '') . $opt_p ? ':'.$opt_p : '';

my $log_file = "/usr/local/freeside/selfservice.soap$tag.log";

my $pid = fork;
defined($pid) or die "Can't fork to start: $!";
print "Started daemon with pid $pid\n" if $pid;
exit if $pid;

POSIX::setsid();
open STDIN, "/dev/null" or die "Can't get rid of STDIN";
open STDOUT, ">/dev/null" or die "Can't get rid of STDOUT";
open STDERR, ">&STDOUT" or die "Can't get rid of STDERR";

$SIG{__WARN__} = \&_logmsg;
$SIG{__DIE__} = sub { &_logmsg(@_); exit };

my $daemon = SOAP::Transport::HTTP::Daemon
  ->new($opt_s ? (LocalAddr => $opt_s) : (), LocalPort => $opt_p ? $opt_p : 8080)
  ->dispatch_to('/usr/local/freeside/SOAP/') #, 'FS::SelfService'
  ->objects_by_reference('iZoomOnlineProvisionService')
  ->handle;

warn "Handling request at ", $daemon->url, "\n";
$daemon->handle;

sub _logmsg {
  chomp( my $msg = shift );
  my $log = new IO::File ">>$log_file";
  flock($log, LOCK_EX);
  seek($log, 0, 2);
  print $log "[". scalar(localtime). "] [$$] $msg\n";
  flock($log, LOCK_UN);
  close $log;
}