8 use FS::UID qw(adminsuidsetup datasrc);
9 use FS::Record qw(qsearch qsearchs);
17 my $user = shift or die &usage;
20 #needs the export number in there somewhere too...?
21 my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/apache";
22 mkdir $spooldir, 0700 unless -d $spooldir;
24 my @exports = qsearch('part_export', { 'exporttype' => 'apache' } );
26 my $rsync = File::Rsync->new({
31 foreach my $export ( @exports ) {
33 my $machine = $export->machine;
34 my $exportnum = $export->exportnum;
35 my $file = "$spooldir/$machine.exportnum$exportnum.conf";
37 warn "exporting apache configuration for $machine to $file\n"
40 open(HTTPD_CONF,">$file") or die "can't open $file: $!";
42 my $template = $export->option('template');
44 my @svc_www = $export->svc_x;
46 foreach my $svc_www ( @svc_www ) {
47 use vars qw($zone $username $dir $email $config);
48 $zone = $svc_www->domain_record->zone;
49 $config = $svc_www->config;
51 my $cust_pkg = $svc_www->cust_svc->cust_pkg;
52 if ( $cust_pkg->getfield('susp') or $cust_pkg->getfield('cancel') ) {
53 $template = $export->option('template_inactive');
55 # Use the regular template if the pkg is live
56 # or if template_inactive doesn't exist.
57 $template ||= $export->option('template');
58 if ( $svc_www->svc_acct ) {
59 $username = $svc_www->svc_acct->username;
60 $dir = $svc_www->svc_acct->dir;
61 $email = $svc_www->svc_acct->email;
68 warn " adding configuration section for $zone\n"
71 print HTTPD_CONF eval(qq("$template")). "\n\n";
74 my $user = $export->option('user');
75 my $httpd_conf = $export->option('httpd_conf');
77 warn "syncing $file to $httpd_conf on $machine\n"
82 dest => "$user\@$machine:$httpd_conf",
83 } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err);
86 my $restart = $export->option('restart') || 'apachectl graceful';
88 warn "running restart command $restart on $machine\n"
91 ssh("root\@$machine", $restart);
100 die "Usage:\n apache.export [ -d ] user\n";