root/tags/omega-1.0.0-rc2/engine/ispcp-serv-mngr

Revision 479, 6.5 kB (checked in by malte, 2 years ago)

--

Line 
1 #!/usr/bin/perl
2
3 # ISPCP(tm) - Virtual Hosting Control System
4 # Copyright (c) 2001-2004 by moleSoftware GmbH
5 # http://www.molesoftware.com
6 #
7 #
8 # License:
9 #    This program is free software; you can redistribute it and/or
10 #    modify it under the terms of the MPL Mozilla Public License
11 #    as published by the Free Software Foundation; either version 1.1
12 #    of the License, or (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    MPL Mozilla Public License for more details.
18 #
19 #    You may have received a copy of the MPL Mozilla Public License
20 #    along with this program.
21 #
22 #    An on-line copy of the MPL Mozilla Public License can be found
23 #    http://www.mozilla.org/MPL/MPL-1.1.html
24 #
25 #
26 # The ISPCP Home Page is at:
27 #
28 #    http://www.vhcs.net
29
30
31 use FindBin;
32 use lib "$FindBin::Bin/";
33 require 'ispcp_common_code.pl';
34
35 use strict;
36
37 use warnings;
38
39 sub serv_mngr_start_up {
40
41     my ($rs, $rdata) = (undef, undef);
42
43     push_el(\@main::el, 'serv_mngr_start_up()', 'Starting...');
44
45     # checking for master process;
46
47     $rs = check_master();
48
49     return $rs if ($rs != 0);
50
51     # Let's clear Execution Logs, if any.
52
53     if (-e $main::ispcp_serv_mngr_el) {
54
55         $rs = del_file($main::ispcp_serv_mngr_el);
56
57         return $rs if ($rs != 0);
58
59     }
60
61     # config check;
62
63     $rs = get_conf();
64
65     return $rs if ($rs != 0);
66
67     # license request check;
68
69     #($rs, $rdata) = license_request();
70
71     #return $rs if ($rs != 0);
72
73     #
74     # License conditions must be stand here;
75     #
76
77     # sql check;
78
79     #
80     # getting initial data also must be done here;
81     #
82
83     my $sql = "select * from domain;";
84
85     ($rs, $rdata) = doSQL($sql);
86
87     return $rs if ($rs != 0);
88
89     $main::changed_dmn_cnt = $ARGV[0]."";
90
91     $main::changed_sub_cnt = $ARGV[1]."";
92
93     $main::changed_als_cnt = $ARGV[2]."";
94
95     $main::changed_mail_cnt = $ARGV[3]."";
96
97     push_el(\@main::el, 'serv_mngr_start_up()', 'Ending...');
98
99     return 0;
100
101 }
102
103 sub serv_mngr_shut_down {
104
105     my $rs = undef;
106
107     push_el(\@main::el, 'serv_mngr_shut_down()', 'Starting...');
108
109     push_el(\@main::el, 'serv_mngr_shut_down()', 'Ending...');
110
111     return 0;
112
113 }
114
115 sub restart_httpd {
116
117     my ($cmd, $rs, $rdata) = (undef, undef, undef);
118
119     push_el(\@main::el, 'restart_httpd()', 'Starting...');
120
121     $cmd = $main::cfg{'CMD_HTTPD'};
122
123     sys_command_rs("$cmd stop");
124
125     sleep(5);
126
127     sys_command_rs("$cmd start");
128
129     sleep(5);
130
131     push_el(\@main::el, 'restart_httpd()', 'Ending...');
132
133 }
134
135 sub check_httpd {
136
137     my ($cmd, $rs, $rdata) = (undef, undef, undef);
138
139     push_el(\@main::el, 'check_httpd()', 'Starting...');
140
141     $cmd = "export COLUMNS=120;$main::cfg{'CMD_PS'} aux | $main::cfg{'CMD_AWK'} '\$0 ~/$main::cfg{'APACHE_NAME'}/ {print \$0}' | $main::cfg{'CMD_WC'} | $main::cfg{'CMD_AWK'} '{print \$1}' 1>/tmp/httpd-run-check.stdout";
142
143     $rs = sys_command($cmd);
144
145     return ($rs, 0) if ($rs != 0);
146
147     ($rs, $rdata) = get_file("/tmp/httpd-run-check.stdout");
148
149     return ($rs, 0) if ($rs != 0);
150
151     push_el(\@main::el, 'check_httpd()', 'Ending...');
152
153     chop($rdata);
154
155     my $pids = $rdata;
156
157     ($rs, $rdata) = del_file("/tmp/httpd-run-check.stdout");
158
159     return ($rs, 0) if ($rs != 0);
160
161     return (0, $pids);
162
163 }
164
165 sub serv_mngr_engine {
166
167     my ($cmd, $rs, $rdata) = (undef, undef, undef);
168
169     push_el(\@main::el, 'serv_mngr_engine()', 'Starting...');
170
171
172     if ($main::changed_mail_cnt > 0 || $main::changed_dmn_cnt > 0 || $main::changed_sub_cnt > 0) {
173
174         if ($main::cfg{'CMD_MTA'} ne 'no') {
175
176             $cmd = $main::cfg{'CMD_MTA'};
177
178             sys_command_rs("$cmd stop");
179
180         }
181
182         if ($main::cfg{'CMD_AUTHD'} ne 'no') {
183
184             $cmd = $main::cfg{'CMD_AUTHD'};
185
186             sys_command_rs("$cmd stop");
187
188         }
189
190                 if ($main::cfg{'CMD_AMAVIS'} ne 'no') {
191
192                         $cmd = $main::cfg{'CMD_AMAVIS'};
193
194                         sys_command_rs("$cmd stop");
195
196                 }
197
198
199         if ($main::cfg{'CMD_IMAP'} ne 'no') {
200
201             $cmd = $main::cfg{'CMD_IMAP'};
202
203             sys_command_rs("$cmd stop");
204
205         }
206
207         if ($main::cfg{'CMD_POP'} ne 'no') {
208
209             $cmd = $main::cfg{'CMD_POP'};
210
211             sys_command_rs("$cmd stop");
212
213         }
214
215     }
216
217     if ($main::changed_dmn_cnt > 0 || $main::changed_sub_cnt > 0 || $main::changed_als_cnt > 0) {
218
219         if ($main::cfg{'CMD_NAMED'} ne 'no') {
220
221             $cmd = $main::cfg{'CMD_NAMED'};
222
223             sys_command_rs("$cmd restart");
224
225         }
226
227     }
228
229     if ($main::changed_mail_cnt > 0 || $main::changed_dmn_cnt > 0 ||
230         $main::changed_sub_cnt > 0 || $main::changed_als_cnt > 0) {
231
232         if ($main::cfg{'CMD_MTA'} ne 'no') {
233
234             $cmd = $main::cfg{'CMD_MTA'};
235
236             sys_command_rs("$cmd start");
237
238         }
239
240
241         if ($main::cfg{'CMD_AUTHD'} ne 'no') {
242
243             $cmd = $main::cfg{'CMD_AUTHD'};
244
245             sys_command_rs("$cmd start");
246
247         }
248
249                 if ($main::cfg{'CMD_AMAVIS'} ne 'no') {
250
251                 $cmd = $main::cfg{'CMD_AMAVIS'};
252
253                 sys_command_rs("$cmd start");
254
255                 }
256
257         if ($main::cfg{'CMD_IMAP'} ne 'no') {
258
259             $cmd = $main::cfg{'CMD_IMAP'};
260
261             sys_command_rs("$cmd start");
262
263         }
264
265         if ($main::cfg{'CMD_POP'} ne 'no') {
266
267             $cmd = $main::cfg{'CMD_POP'};
268
269             sys_command_rs("$cmd start");
270
271         }
272
273     }
274
275     if ($main::changed_dmn_cnt > 0 || $main::changed_sub_cnt > 0 || $main::changed_als_cnt > 0) {
276
277         if ($main::cfg{'CMD_HTTPD'} ne 'no') {
278
279             $cmd = $main::cfg{'CMD_HTTPD'};
280
281             sys_command_rs("$cmd restart");
282
283             sleep(3);
284
285         }
286
287         if ($main::cfg{'CMD_HTTPD'} ne 'no') {
288
289             ($rs, $rdata) = check_httpd();
290
291             return $rs if ($rs != 0);
292
293             if ($rdata == 0) {
294
295                 my $i = 1;
296
297                 do {
298
299                     restart_httpd();
300
301                     ($rs, $rdata) = check_httpd();
302
303                     return $rs if ($rs != 0);
304
305                     $i++;
306
307                 } while ($rdata == 0 && $i <= $main::cfg{'APACHE_RESTART_TRY'});
308             }
309
310         }
311
312     }
313
314     push_el(\@main::el, 'serv_mngr_engine()', 'Ending...');
315
316     return 0;
317
318 }
319
320 my $rs = undef;
321
322 $rs = serv_mngr_start_up();
323
324 if ($rs != 0) {
325
326     dump_el(\@main::el, $main::ispcp_serv_mngr_el);
327
328     serv_mngr_shut_down();
329
330     exit 1;
331
332 }
333
334 $rs = serv_mngr_engine();
335
336 if ($rs != 0) {
337
338     dump_el(\@main::el, $main::ispcp_serv_mngr_el);
339
340     serv_mngr_shut_down();
341
342     exit 1;
343
344 }
345
346 $rs = serv_mngr_shut_down();
347
348 if ($rs != 0) {
349
350     dump_el(\@main::el, $main::ispcp_serv_mngr_el);
351
352     exit 1;
353
354 }
355
356 exit 0;
Note: See TracBrowser for help on using the browser.