root/trunk/engine/ispcp-serv-mngr

Revision 1384, 7.4 kB (checked in by scitech, 1 month ago)

Restoring active folder creation for subdomains

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