quick hack to add extra 'config lines' to svc_www and otherwise enhance svc_www
[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 $dir $email $config);
40     $zone = $svc_www->domain_record->zone;
41     $username = $svc_www->svc_acct->username;
42     $dir = $svc_www->svc_acct->dir;
43     $email = $svc_www->svc_acct->email;
44     $config = $svc_www->config;
45     print HTTPD_CONF eval(qq("$template")). "\n\n";
46   }
47
48   my $user = $export->option('user');
49   my $httpd_conf = $export->option('httpd_conf');
50
51   $rsync->exec( {
52     src       => $file,
53     dest      => "$user\@$machine:$httpd_conf",
54   } ) or die "rsync to $machine failed: ". join(" / ", $rsync->err);
55  # warn $rsync->out;
56
57   my $restart = $export->option('restart') || 'apachectl graceful';
58
59   ssh("root\@$machine", $restart);
60
61 }
62
63 close HTTPD_CONF;
64
65 # -----
66
67 sub usage {
68   die "Usage:\n  apache.export user\n"; 
69 }
70