fix FS::Record::qsearch to (hopefully) work as before and cluck loudly when the FS...
[freeside.git] / bin / apache.export
1 #!/usr/bin/perl -w
2
3 use strict;
4 #use File::Path;
5 use File::Rsync;
6 use Net::SSH qw(ssh);
7 use FS::UID qw(adminsuidsetup datasrc);
8 use FS::Record qw(qsearch qsearchs);
9 use FS::part_export;
10 use FS::cust_svc;
11 use FS::svc_www;
12
13 my $user = shift or die &usage;
14 adminsuidsetup $user;
15
16 #needs the export number in there somewhere too...?
17 my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/apache";
18 mkdir $spooldir, 0700 unless -d $spooldir;
19
20 my @exports = qsearch('part_export', { 'exporttype' => 'apache' } );
21
22 my $rsync = File::Rsync->new({
23   rsh     => 'ssh',
24 #  dry_run => 1,
25 });
26
27 foreach my $export ( @exports ) {
28
29   my $machine = $export->machine;
30   my $file = "$spooldir/$machine.conf";
31
32   open(HTTPD_CONF,">$file") or die "can't open $file: $!";
33
34   my $template = $export->option('template');
35
36   my @svc_www = $export->svc_x;
37
38   foreach my $svc_www ( @svc_www ) {
39     use vars qw($zone $username);
40     $zone = $svc_www->domain_record->zone;
41     $username = $svc_www->svc_acct->username;
42     print HTTPD_CONF eval(qq("$template")). "\n\n";
43   }
44
45   my $user = $export->option('user');
46   my $httpd_conf = $export->option('httpd_conf');
47
48   $rsync->exec( {
49     src       => $file,
50     dest      => "$user\@$machine:$httpd_conf",
51   } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err);
52  # warn $rsync->out;
53
54   my $restart = $export->option('restart') || 'apachectl graceful';
55
56   ssh("root\@$machine", $restart);
57
58 }
59
60 close HTTPD_CONF;
61
62 # -----
63
64 sub usage {
65   die "Usage:\n  apache.export user\n"; 
66 }
67