~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to tools/dynserv.pl

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use File::Path;
 
4
 
 
5
my $eucalyptus = $ENV{'EUCALYPTUS'};
 
6
my $dynpath = "$eucalyptus/var/lib/eucalyptus/dynserv";
 
7
my $rc;
 
8
my $dynpath = shift @ARGV;
 
9
my @allowhosts = @ARGV;
 
10
 
 
11
$rc = setup_dynpath($dynpath);
 
12
if ($rc) {
 
13
    print "ERROR: could not create directory structure\n";
 
14
    exit (1);
 
15
}
 
16
 
 
17
$rc = open(OFH, ">$dynpath/dynserv-httpd.conf");
 
18
if ($rc <= 0) {
 
19
    print "ERROR: could not create config file '$dynpath/dynserv-httpd.conf'\n";
 
20
    exit (1);
 
21
}
 
22
 
 
23
$authz = find_authz();
 
24
$apache = find_apache2();
 
25
if ($authz eq "none" || $apache eq "none") {
 
26
    print "ERROR: cannot find authz module ($authz) or apache2 ($apache)\n";
 
27
    exit (1);
 
28
}
 
29
 
 
30
$rc = prepare_configfile($eucalyptus, $dynpath, "eucalyptus", "eucalyptus", $authz, $apache, @allowhosts);
 
31
if ($rc) {
 
32
    print "ERROR: could not set up configfile\n";
 
33
    exit(1);
 
34
}
 
35
 
 
36
$rc = restart_apache($dynpath, $apache);
 
37
if ($rc) {
 
38
    print "ERROR: could not restart apache2\n";
 
39
    exit(1);
 
40
}
 
41
 
 
42
exit(0);
 
43
 
 
44
sub restart_apache() {
 
45
    my $dynpath = shift @_;
 
46
    my $apache = shift @_;
 
47
 
 
48
    my $cmd = "$apache -f $dynpath/dynserv-httpd.conf -k graceful";
 
49
    my $rc = system("$cmd");
 
50
    if ($rc) {
 
51
        print "ERROR: could not run cmd '$cmd'\n";
 
52
    }
 
53
    return($rc);
 
54
}
 
55
 
 
56
sub prepare_configfile() {
 
57
    my $eucalyptus = shift @_;
 
58
    my $dynpath = shift @_;
 
59
    my $user = shift @_;
 
60
    my $group = shift @_;
 
61
    my $authz = shift @_;
 
62
    my $apache = shift @_;
 
63
    my @allowhosts = @_;
 
64
 
 
65
    if (!-d "$eucalyptus/var/run/eucalyptus" || !-d "$eucalyptus/var/log/eucalyptus") {
 
66
        print "ERROR: eucalyptus root '$eucalyptus' not found\n";
 
67
        return(1);
 
68
    }
 
69
    if (!-d "$eucalyptus" || !-d "$dynpath" || !-e "$authz" || !-x "$apache") {
 
70
        print "ERROR: eucalyptus=$eucalyptus dynpath=$dynpath user=$user group=$group authz=$authz apache=$apache\n";
 
71
        return(1);
 
72
    }
 
73
 
 
74
    $allows = "127.0.0.0/8";
 
75
    foreach $host (@allowhosts) {
 
76
        $allows = $allows . " $host";
 
77
    }
 
78
 
 
79
    print OFH <<EOF;
 
80
ServerTokens OS
 
81
ServerRoot "$dynpath"
 
82
ServerName 127.0.0.1
 
83
Listen 8776
 
84
KeepAliveTimeout 30
 
85
PidFile $eucalyptus/var/run/eucalyptus/httpd-dynserv.pid
 
86
User $user
 
87
group $group
 
88
ErrorLog $eucalyptus/var/log/eucalyptus/httpd-dynserv-err.log
 
89
LogLevel warn
 
90
LoadModule authz_host_module $authz
 
91
DocumentRoot "$dynpath/data/"
 
92
<Directory "$dynpath/data/">
 
93
   Order deny,allow
 
94
#  Allow from 127.0.0.1
 
95
#  Allow from none
 
96
   Allow from $allows
 
97
   Deny from all
 
98
</Directory>
 
99
EOF
 
100
close(OFH);
 
101
return(0);
 
102
}
 
103
 
 
104
sub find_authz() {
 
105
    my @known_locations = ('/usr/lib64/httpd/modules/mod_authz_host.so',
 
106
                           '/usr/lib/httpd/modules/mod_authz_host.so',
 
107
                           '/usr/lib64/apache2/mod_authz_host.so',
 
108
                           '/usr/lib/apache2/mod_authz_host.so',
 
109
                           '/usr/lib/apache2/modules/mod_authz_host.so');
 
110
 
 
111
    $foundfile = "none";
 
112
    foreach $file (@known_locations) {
 
113
        if ( -f "$file" ) {
 
114
            $foundfile = $file;
 
115
        }
 
116
    }
 
117
    return($foundfile);
 
118
}
 
119
 
 
120
sub find_apache2() {
 
121
    my @known_locations = ('/usr/sbin/apache2',
 
122
                           '/usr/sbin/httpd2',
 
123
                           '/usr/sbin/httpd');
 
124
    $foundfile = "none";
 
125
    foreach $file (@known_locations) {
 
126
        if ( -x "$file" ) {
 
127
            $foundfile = $file;
 
128
        }
 
129
    }
 
130
    return($foundfile);
 
131
}
 
132
 
 
133
sub setup_dynpath() {
 
134
    my $root=shift @_;
 
135
 
 
136
    mkpath("$root/data/", {error => \my $err});
 
137
    if (@$err) {
 
138
        print "ERROR: could not create directory '$root/data'\n";
 
139
        return(1);
 
140
    }
 
141
 
 
142
    return(0);
 
143
}