2 ######################################################################
4 # SSLproxy process administration command.
6 # Copyright (C) 2008 NTT COMWARE Corporation.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 ######################################################################
27 our $LOGGER_DEBUG = 0;
29 # sslproxyadm define value.
34 our $SSLPROXY_PATH = "/usr/sbin/";
35 our $SSLPROXY = "sslproxy";
36 our $LOGGER_SECTION_KEY = "logger";
37 our $TARGET_SECTION_KEY = "target_.*";
38 our $LOGROTATE_CMD = "/usr/sbin/logrotate";
39 our $LOGROTATE_CONF_FILE = "/etc/logrotate.d/sslproxy";
40 our $LOGROTATE_STAT_FILE = "/var/lib/logrotate.status";
42 # sslproxyadm default parameter value.
43 our $CMD_OPT = "unknown";
44 our $CONFIG_FILE = "/etc/l7vs/sslproxy/sslproxyadm.cf";
45 our $LOG_FILE = "/var/log/l7vs/sslproxy/sslproxyadm.log";
46 our $LOG_LEVEL = "warn";
49 $ENV{LD_LIBRARY_PATH} = "/usr/local/lib/";
51 # sslproxyadm global data table
52 our %sslproxyadm_data = ();
53 our %target_data = ();
54 our %process_data = ();
60 # Here is not executed. However, it exists for safety.
65 # sslproxyadm command main routine.
67 # command argment check and command execution.
71 #--------- DEBUG LOG ---------#
73 &print_log("file", "DEBUG", "common", "10050001",
74 "in_function : do_main : ".
77 #------- DEBUG LOG END -------#
81 # Check command argment count.
83 $CONFIG_FILE = $ARGV[1];
84 #--------- DEBUG LOG ---------#
85 &print_log("file", "DEBUG", "common", "10050002",
86 "Command arg count is normal.");
87 #------- DEBUG LOG END -------#
88 } elsif (@ARGV == 1) {
89 #--------- DEBUG LOG ---------#
90 &print_log("file", "DEBUG", "common", "10050003",
91 "Command arg count is normal. Use default config file.");
92 #------- DEBUG LOG END -------#
94 &print_log("fcerr", "ERROR", "common", "40050001",
95 "Command arg count is abnormal.");
97 #--------- DEBUG LOG ---------#
98 &print_log("file", "DEBUG", "common", "10050004",
99 "out_function : do_main : Check argment NG");
100 #------- DEBUG LOG END -------#
104 #--------- DEBUG LOG ---------#
105 &print_log("file", "DEBUG", "common", "10050005",
106 "function : do_main : Check argment OK");
107 #------- DEBUG LOG END -------#
109 # Read sslproxyadm configration file.
110 ($result) = &read_adm_config;
111 if ($result == $NG) {
112 &print_log("fcerr", "ERROR", "common", "40050002",
113 "Config file read error. file = $CONFIG_FILE");
114 #--------- DEBUG LOG ---------#
115 &print_log("file", "DEBUG", "common", "10050006",
116 "out_function : do_main : read_adm_config NG");
117 #------- DEBUG LOG END -------#
120 #--------- DEBUG LOG ---------#
121 &print_log("file", "DEBUG", "common", "10050007",
122 "function : do_main : read_adm_config OK");
123 #------- DEBUG LOG END -------#
125 # Set logger configuration.
126 ($result) = &set_log;
127 if ($result == $NG) {
128 &print_log("fcerr", "ERROR", "common", "40050003",
129 "Logger setting error.");
130 #--------- DEBUG LOG ---------#
131 &print_log("file", "DEBUG", "common", "10050008",
132 "out_function : do_main : set_log NG");
133 #------- DEBUG LOG END -------#
136 #--------- DEBUG LOG ---------#
137 &print_log("file", "DEBUG", "common", "10050009",
138 "function : do_main : set_log OK");
139 #------- DEBUG LOG END -------#
141 # Check command option.
142 if ($CMD_OPT ne "start" &&
143 $CMD_OPT ne "stop" &&
144 $CMD_OPT ne "restart" &&
145 $CMD_OPT ne "reload" &&
146 $CMD_OPT ne "check" &&
147 $CMD_OPT ne "status" &&
148 $CMD_OPT ne "config") {
149 &print_log("fcerr", "ERROR", "common", "40050004",
150 "Invalid command. command = $CMD_OPT");
152 #--------- DEBUG LOG ---------#
153 &print_log("file", "DEBUG", "common", "10050010",
154 "out_function : do_main : Check command NG");
155 #------- DEBUG LOG END -------#
158 #--------- DEBUG LOG ---------#
159 &print_log("file", "DEBUG", "common", "10050011",
160 "function : do_main : Check command OK");
161 #------- DEBUG LOG END -------#
163 # Check target configration file.
164 ($result) = &check_target_config;
165 if ($result == $NG) {
166 &print_log("fcerr", "ERROR", "common", "40050005",
167 "Check target config file error.");
168 #--------- DEBUG LOG ---------#
169 &print_log("file", "DEBUG", "common", "10050012",
170 "out_function : do_main : check_target_config NG");
171 #------- DEBUG LOG END -------#
174 #--------- DEBUG LOG ---------#
175 &print_log("file", "DEBUG", "common", "10050013",
176 "function : do_main : check_target_config OK");
177 #------- DEBUG LOG END -------#
179 # Check target configration file format command execution.
180 if ($CMD_OPT eq "config") {
181 ($result) = &do_config;
182 #--------- DEBUG LOG ---------#
183 &print_log("file", "DEBUG", "common", "10050014",
184 "function : do_main : Command execute END. command = $CMD_OPT");
185 #------- DEBUG LOG END -------#
186 if ($result == $NG) {
187 &print_log("fcerr", "ERROR", "common", "40050006",
188 "Command execute error. command = $CMD_OPT");
189 #--------- DEBUG LOG ---------#
190 &print_log("file", "DEBUG", "common", "10050015",
191 "out_function : do_main : Command execute NG");
192 #------- DEBUG LOG END -------#
195 #--------- DEBUG LOG ---------#
196 &print_log("file", "DEBUG", "common", "10050016",
197 "out_function : do_main : Command execute OK. command = $CMD_OPT");
198 #------- DEBUG LOG END -------#
202 # Get sslproxy process status.
203 ($result) = &get_process_status;
204 if ($result == $NG) {
205 &print_log("fcerr", "ERROR", "common", "40050007",
206 "Get process status error.");
207 #--------- DEBUG LOG ---------#
208 &print_log("file", "DEBUG", "common", "10050017",
209 "out_function : do_main : get_process_status NG");
210 #------- DEBUG LOG END -------#
213 #--------- DEBUG LOG ---------#
214 &print_log("file", "DEBUG", "common", "10050018",
215 "function : do_main : get_process_status OK");
216 #------- DEBUG LOG END -------#
219 if ($CMD_OPT eq "start") {
220 ($result) = &do_start;
221 #--------- DEBUG LOG ---------#
222 &print_log("file", "DEBUG", "common", "10050019",
223 "function : do_main : Command execute END. command = $CMD_OPT");
224 #------- DEBUG LOG END -------#
225 } elsif ($CMD_OPT eq "stop") {
226 ($result) = &do_stop;
227 #--------- DEBUG LOG ---------#
228 &print_log("file", "DEBUG", "common", "10050020",
229 "function : do_main : Command execute END. command = $CMD_OPT");
230 #------- DEBUG LOG END -------#
231 } elsif ($CMD_OPT eq "restart") {
232 ($result) = &do_restart;
233 #--------- DEBUG LOG ---------#
234 &print_log("file", "DEBUG", "common", "10050021",
235 "function : do_main : Command execute END. command = $CMD_OPT");
236 #------- DEBUG LOG END -------#
237 } elsif ($CMD_OPT eq "reload") {
238 ($result) = &do_reload;
239 #--------- DEBUG LOG ---------#
240 &print_log("file", "DEBUG", "common", "10050022",
241 "function : do_main : Command execute END. command = $CMD_OPT");
242 #------- DEBUG LOG END -------#
243 } elsif ($CMD_OPT eq "check") {
244 ($result) = &do_check;
245 #--------- DEBUG LOG ---------#
246 &print_log("file", "DEBUG", "common", "10050023",
247 "function : do_main : Command execute END. command = $CMD_OPT");
248 #------- DEBUG LOG END -------#
249 } elsif ($CMD_OPT eq "status") {
250 ($result) = &do_status;
251 #--------- DEBUG LOG ---------#
252 &print_log("file", "DEBUG", "common", "10050024",
253 "function : do_main : Command execute END. command = $CMD_OPT");
254 #------- DEBUG LOG END -------#
256 # Here is not executed. However, it exists for safety.
257 &print_log("fcerr", "ERROR", "common", "40050008",
258 "Invalid command. command = $CMD_OPT");
260 #--------- DEBUG LOG ---------#
261 &print_log("file", "DEBUG", "common", "10050025",
262 "out_function : do_main : Check command NG");
263 #------- DEBUG LOG END -------#
266 if ($result == $NG) {
267 &print_log("fcerr", "ERROR", "common", "40050009",
268 "Command execute error. command = $CMD_OPT");
269 #--------- DEBUG LOG ---------#
270 &print_log("file", "DEBUG", "common", "10050026",
271 "out_function : do_main : Command execute NG");
272 #------- DEBUG LOG END -------#
275 #--------- DEBUG LOG ---------#
276 &print_log("file", "DEBUG", "common", "10050027",
277 "out_function : do_main : Command execute OK. command = $CMD_OPT");
278 #------- DEBUG LOG END -------#
283 # Read sslproxyadm configration file.
285 # @retval OK/NG read result
289 #--------- DEBUG LOG ---------#
290 &print_log("file", "DEBUG", "config", "10030001",
291 "in_function : read_adm_config");
292 #------- DEBUG LOG END -------#
295 %sslproxyadm_data = ();
296 ($result) = &read_config($CONFIG_FILE, "adm");
297 if ($result == $NG) {
298 &print_log("file", "ERROR", "config", "40030001",
299 "Read sslproxyadm configration file error. file = $CONFIG_FILE");
303 #&print_table_data(%sslproxyadm_data);
305 #--------- DEBUG LOG ---------#
306 &print_log("file", "DEBUG", "config", "10030002",
307 "out_function : read_adm_config : result = $result");
308 #------- DEBUG LOG END -------#
313 # Check target configration files. exist or not.
315 # @retval OK/NG check result
317 sub check_target_config
319 #--------- DEBUG LOG ---------#
320 &print_log("file", "DEBUG", "config", "10030003",
321 "in_function : check_target_config");
322 #------- DEBUG LOG END -------#
325 # Search target configration file.
326 foreach my $section (sort keys(%sslproxyadm_data)) {
327 #--------- DEBUG LOG ---------#
328 &print_log("file", "DEBUG", "config", "10030004",
330 "section = $section");
331 #------- DEBUG LOG END -------#
332 my $target_conf_file = "";
333 # Check target section.
334 next if ($section !~ /^$TARGET_SECTION_KEY$/);
335 # Get target configration file name.
336 $target_conf_file = $sslproxyadm_data{$section}{"conf_file"};
337 # Open target configration file for exist check.
338 if(!open(CONFIG, "<$target_conf_file")) {
339 &print_log("file", "ERROR", "config", "40030002",
340 "Cannot open target config file. file = $target_conf_file");
346 #--------- DEBUG LOG ---------#
347 &print_log("file", "DEBUG", "config", "10030005",
348 "Target config file open OK. ".
349 "target_conf_file = $target_conf_file");
350 #------- DEBUG LOG END -------#
353 #--------- DEBUG LOG ---------#
354 &print_log("file", "DEBUG", "config", "10030006",
355 "out_function : check_target_config : ".
357 #------- DEBUG LOG END -------#
362 # Read specified configration file.
364 # @param[in] conf_file configration file
365 # @param[in] conf_kind configration file kind(adm or target)
366 # @retval OK/NG read result
371 my ($conf_file, $conf_kind) = (@_);
373 #--------- DEBUG LOG ---------#
374 &print_log("file", "DEBUG", "config", "10030007",
375 "in_function : read_config : ".
376 "conf_file = $conf_file ".
377 "conf_kind = $conf_kind");
378 #------- DEBUG LOG END -------#
380 # Check config file kind. "adm" or "target"
381 if ($conf_kind ne "adm" && $conf_kind ne "target") {
382 &print_log("file", "ERROR", "config", "40030003",
383 "Invalid config file kind. kind = $conf_kind");
386 } elsif(!open(CONFIG, "<$conf_file")) {
387 &print_log("file", "ERROR", "config", "40030004",
388 "Cannot open config file. file = $conf_file");
391 # Read data and Set to data table.
393 my $section_flag = $OFF;
394 my $now_section = "";
397 # Set section keyword.
398 if ($conf_kind eq "adm") {
399 $sec_key = $TARGET_SECTION_KEY;
400 } elsif ($conf_kind eq "target") {
401 $sec_key = $SSLPROXY;
403 while ($line_data = <CONFIG>) {
404 # Read one line data.
406 # Skip Null line and comment line.
407 next if ($line_data =~ /^\s*$|^\s*#/);
408 # Cut space, tab, \n.
409 $line_data =~ s/\s|\t|\n//g;
410 #--------- DEBUG LOG ---------#
411 &print_log("file", "DEBUG", "config", "10030008",
412 "Read line data [$now_line] = $line_data");
413 #------- DEBUG LOG END -------#
415 # Check section line. (include [logger] [$sec_key])
417 /^\[$LOGGER_SECTION_KEY\]$|^\[$sec_key\]$/) {
418 # Check start of first section.
421 $line_data =~ s/\[|\]//g;
422 # Check duplication of section name. "adm" or "target"
423 if ($conf_kind eq "adm") {
424 while (my ($section_name, $section_data) = each (%sslproxyadm_data)) {
425 #--------- DEBUG LOG ---------#
426 &print_log("file", "DEBUG", "config", "10030009",
427 "Check section name. ".
428 "read line = $line_data, ".
429 "saved data = $section_name");
430 #------- DEBUG LOG END -------#
431 if ($line_data eq $section_name) {
432 &print_log("file", "ERROR", "config", "40030005",
433 "Section name is duplicated. ".
434 "section = $section_name Line:$now_line");
439 } elsif ($conf_kind eq "target") {
440 while (my ($section_name, $section_data) = each (%target_data)) {
441 #--------- DEBUG LOG ---------#
442 &print_log("file", "DEBUG", "config", "10030010",
443 "Check section name. ".
444 "read line = $line_data, ".
445 "saved data = $section_name");
446 #------- DEBUG LOG END -------#
447 if ($line_data eq $section_name) {
448 &print_log("file", "ERROR", "config", "40030006",
449 "Section name is duplicated. ".
450 "section = $section_name Line:$now_line");
456 if ($result == $NG) {
457 #--------- DEBUG LOG ---------#
458 &print_log("file", "DEBUG", "config", "10030011",
459 "Check section name NG.");
460 #------- DEBUG LOG END -------#
463 $now_section = $line_data;
464 #--------- DEBUG LOG ---------#
465 &print_log("file", "DEBUG", "config", "10030012",
466 "New section found. section = $now_section");
467 #------- DEBUG LOG END -------#
471 # Check parameter line. (include "=")
472 if ($line_data =~ /=/) {
474 if ($section_flag == $OFF) {
475 &print_log("file", "ERROR", "config", "40030007",
476 "Ivalid parameter line. ".
477 "Out of section. Line:$now_line");
481 # Split by "=" delimiter to key and value.
482 my @param = split /=/, $line_data, 2;
484 if ($param[0] eq "") {
485 &print_log("file", "ERROR", "config", "40030008",
486 "Ivalid parameter line. ".
487 "Parameter key is NULL. Line:$now_line");
491 # Cut char value's ".
493 # Parameter data set to data table. "adm" or "target"
494 if ($conf_kind eq "adm") {
495 $sslproxyadm_data{$now_section}{$param[0]} = $param[1];
496 } elsif ($conf_kind eq "target") {
497 $target_data{$now_section}{$param[0]} = $param[1];
499 #--------- DEBUG LOG ---------#
500 &print_log("file", "DEBUG", "config", "10030013",
502 "section = $now_section, ".
504 "value = $param[1]");
505 #------- DEBUG LOG END -------#
510 &print_log("file", "ERROR", "config", "40030009",
511 "Ivalid parameter line. ".
512 "Unknown line. Line:$now_line");
517 #--------- DEBUG LOG ---------#
518 &print_log("file", "DEBUG", "config", "10030014",
519 "Config file read and Set data END.");
520 #------- DEBUG LOG END -------#
522 # Check read and data set result.
523 # $result is OK? section is exist?
524 if ($result == $OK) {
525 # Check section count. "adm" or "target"
526 my $logger_section_count = 0;
527 my $section_count = 0;
528 if ($conf_kind eq "adm") {
529 foreach my $adm_section (sort keys(%sslproxyadm_data)) {
530 if ($adm_section =~ /^$LOGGER_SECTION_KEY$/) {
531 $logger_section_count++;
533 if ($adm_section =~ /^$sec_key$/) {
537 } elsif ($conf_kind eq "target") {
538 foreach my $target_section (sort keys(%target_data)) {
539 if ($target_section =~ /^$LOGGER_SECTION_KEY$/) {
540 $logger_section_count++;
542 if ($target_section =~ /^$sec_key$/) {
547 if ($logger_section_count == 0) {
548 &print_log("file", "ERROR", "config", "40030010",
549 "[logger] section nothing in config file. ".
550 "file = $conf_file");
552 } elsif ($section_count == 0) {
553 &print_log("file", "ERROR", "config", "40030011",
554 "[$sec_key] section nothing in config file. ".
555 "file = $conf_file");
558 #--------- DEBUG LOG ---------#
559 &print_log("file", "DEBUG", "config", "10030015",
560 "Read and data set result OK.");
561 #------- DEBUG LOG END -------#
567 #&print_table_data(%sslproxyadm_data);
568 #&print_table_data(%target_data);
570 #--------- DEBUG LOG ---------#
571 &print_log("file", "DEBUG", "config", "10030016",
572 "out_function : read_config : result = $result");
573 #------- DEBUG LOG END -------#
578 # Get sslproxy process status.
580 # Collect sslproxy process info and Check status.
581 # and Judge sslproxy process status.
583 # @retval OK/NG get result
585 sub get_process_status
587 #--------- DEBUG LOG ---------#
588 &print_log("file", "DEBUG", "status", "10020001",
589 "in_function : get_process_status");
590 #------- DEBUG LOG END -------#
594 # Collect SSLproxy process information.
595 ($result) = &collect_process_info;
596 if ($result == $NG) {
597 &print_log("file", "ERROR", "status", "40020001",
598 "Collect sslproxy process info error.");
600 #--------- DEBUG LOG ---------#
601 &print_log("file", "DEBUG", "status", "10020002",
602 "Check sslproxy process start.");
603 #------- DEBUG LOG END -------#
604 foreach my $conf_target (sort keys(%sslproxyadm_data)) {
605 # Get target id from sslproxyadm_data
606 # Check target section. (other is skip)
607 next if ($conf_target !~ /^$TARGET_SECTION_KEY$/);
609 # Check list for sslproxy process status.
610 # is_start Starting or Stopped
611 # cmp_config match or not
612 # start_info file exist or not
613 # cmp_start_info match or not
615 my $cmp_config = $NG;
616 my $start_info = $NG;
617 my $cmp_start_info = $NG;
618 # proc_status judge result
619 my $proc_status = $NG;
621 # Check is_start. Exist target id in process_data or not.
622 #--------- DEBUG LOG ---------#
623 &print_log("file", "DEBUG", "status", "10020003",
624 "Check is_start. target = $conf_target");
625 #------- DEBUG LOG END -------#
626 foreach my $proc_target (sort keys(%process_data)) {
627 #--------- DEBUG LOG ---------#
628 &print_log("file", "DEBUG", "status", "10020004",
629 "Check process = $proc_target");
630 #------- DEBUG LOG END -------#
631 if ($proc_target eq $conf_target) {
632 #--------- DEBUG LOG ---------#
633 &print_log("file", "DEBUG", "status", "10020005",
634 "$proc_target is Starting.");
635 #------- DEBUG LOG END -------#
638 $sslproxyadm_data{$proc_target}{"pid"} =
639 $process_data{$proc_target}{"pid"};
640 # Set known sslproxy process flag.
641 # (Not set process is unknown sslproxy process)
642 $process_data{$proc_target}{"known"} = $ON;
646 $sslproxyadm_data{$conf_target}{"is_start"} = $is_start;
648 # Check cmp_config. Compare target conf file name.
649 # (Starting process only)
650 if ($is_start == $OK) {
651 #--------- DEBUG LOG ---------#
652 &print_log("file", "DEBUG", "status", "10020006",
653 "Check cmp_config. target = $conf_target");
654 #------- DEBUG LOG END -------#
655 if ($sslproxyadm_data{$conf_target}{"conf_file"} eq
656 $process_data{$conf_target}{"conf_file"}) {
657 #--------- DEBUG LOG ---------#
658 &print_log("file", "DEBUG", "status", "10020007",
659 "Config file matched.");
660 #------- DEBUG LOG END -------#
663 $sslproxyadm_data{$conf_target}{"cmp_config"} = $cmp_config;
666 # Check start_info. Try open start_info file for exist check.
667 # start_info file name = target_conf_file + "." + target_id
668 my $start_info_file = $sslproxyadm_data{$conf_target}{"conf_file"}.
671 #--------- DEBUG LOG ---------#
672 &print_log("file", "DEBUG", "status", "10020008",
673 "Check start_info. file = $start_info_file");
674 #------- DEBUG LOG END -------#
675 if (open(STARTFILE, "<$start_info_file")) {
676 #--------- DEBUG LOG ---------#
677 &print_log("file", "DEBUG", "status", "10020009",
678 "Start info file existed.");
679 #------- DEBUG LOG END -------#
683 $sslproxyadm_data{$conf_target}{"start_info"} = $start_info;
685 # Check cmp_start_info. Compare start_info file and conf file.
686 # (start_info OK only)
687 if ($start_info == $OK) {
688 #--------- DEBUG LOG ---------#
689 &print_log("file", "DEBUG", "status", "10020010",
690 "Check cmp_start_info. target = $conf_target");
691 #------- DEBUG LOG END -------#
692 # Open diff command output.
693 my $diff_cmd = "/usr/bin/diff $start_info_file ".
694 $sslproxyadm_data{$conf_target}{"conf_file"}.
696 if (open(DIFFDATA, $diff_cmd)) {
697 #--------- DEBUG LOG ---------#
698 &print_log("file", "DEBUG", "status", "10020011",
699 "Get diff command output.");
700 #------- DEBUG LOG END -------#
701 my @diff_data = <DIFFDATA>;
702 my $diff_cnt = @diff_data;
703 # Check diff output size. 0 is matched.
704 if ($diff_cnt == 0) {
705 #--------- DEBUG LOG ---------#
706 &print_log("file", "DEBUG", "status", "10020012",
707 "Start info file matched.");
708 #------- DEBUG LOG END -------#
709 $cmp_start_info = $OK;
713 $sslproxyadm_data{$conf_target}{"cmp_start_info"} = $cmp_start_info;
716 # Judge sslproxy process status. Check normal start/stop state.
717 #--------- DEBUG LOG ---------#
718 &print_log("file", "DEBUG", "status", "10020013",
719 "Judge sslproxy process status by check result. ".
720 "target = $conf_target");
721 #------- DEBUG LOG END -------#
722 if (($is_start == $OK &&
723 $cmp_config == $OK &&
724 $start_info == $OK &&
725 $cmp_start_info == $OK) ||
727 $start_info == $NG)) {
728 #--------- DEBUG LOG ---------#
729 &print_log("file", "DEBUG", "status", "10020014",
730 "Result sslproxy process status is OK. ".
731 "Normal Starting or Stopped.");
732 #------- DEBUG LOG END -------#
735 $sslproxyadm_data{$conf_target}{"proc_status"} = $proc_status;
737 # now_start flag initialize.
738 $sslproxyadm_data{$conf_target}{"now_start"} = $OFF;
740 #--------- DEBUG LOG ---------#
741 &print_log("file", "DEBUG", "status", "10020015",
742 "Check and Judge sslproxy process status END.");
743 #------- DEBUG LOG END -------#
746 #&print_table_data(%process_data);
747 #&print_table_data(%sslproxyadm_data);
750 #--------- DEBUG LOG ---------#
751 &print_log("file", "DEBUG", "status", "10020016",
752 "out_function : get_process_status : result = $result");
753 #------- DEBUG LOG END -------#
758 # Collect sslproxy process information.
760 # @retval OK/NG collect result
762 sub collect_process_info
764 #--------- DEBUG LOG ---------#
765 &print_log("file", "DEBUG", "status", "10020017",
766 "in_function : collect_process_info");
767 #------- DEBUG LOG END -------#
771 # Collect sslproxy process information from ps command output.
772 # Set to process_data.
774 my $ps_cmd = "/bin/ps -C $SSLPROXY -o pid=,cmd= |";
775 if(!open(PROCESS, $ps_cmd)) {
776 &print_log("file", "ERROR", "status", "40020002",
777 "Cannot open ps command output.");
780 # Read ps command data and Set to data table.
782 while ($line_data = <PROCESS>) {
783 # Read one line data. (one process)
785 $line_data =~ s/^\s*|\n$//g;
786 #--------- DEBUG LOG ---------#
787 &print_log("file", "DEBUG", "status", "10020018",
788 "Read one process line data = $line_data");
789 #------- DEBUG LOG END -------#
791 # Split @param by " " delimiter.
793 # $param[1] -> cmd (ex. "./sslproxy")
794 # $param[2] -> target id
795 # $param[3] -> target config file
796 my @param = split /\s/, $line_data, 4;
797 # Parameter data set to data table.
798 $process_data{$param[2]}{"pid"} = $param[0];
799 $process_data{$param[2]}{"conf_file"} = $param[3];
800 $process_data{$param[2]}{"known"} = $OFF;
801 #--------- DEBUG LOG ---------#
802 &print_log("file", "DEBUG", "status", "10020019",
804 "target_id = $param[2], ".
806 "conf_file = $param[3]");
807 #------- DEBUG LOG END -------#
810 #--------- DEBUG LOG ---------#
811 &print_log("file", "DEBUG", "status", "10020020",
812 "Process info read and Set data END.");
813 #------- DEBUG LOG END -------#
815 # Check process count.
816 my $proc_count = keys(%process_data);
817 if ($proc_count == 0) {
818 &print_log("file", "INFO", "status", "20020001",
819 "Executing SSLproxy process is nothing.");
823 #&print_table_data(%process_data);
826 #--------- DEBUG LOG ---------#
827 &print_log("file", "DEBUG", "status", "10020021",
828 "out_function : collect_process_info : result = $result");
829 #------- DEBUG LOG END -------#
834 # Update sslproxy process status.
835 # Set Starting <-> Stopped status.
837 # @param[in] target_id target id
838 # @param[in] flag update kind flag
839 # @retval OK/NG update result
841 sub update_process_status
844 # flag ig ON(Starting) or OFF(Stopped).
845 my ($target_id, $flag) = (@_);
847 #--------- DEBUG LOG ---------#
848 &print_log("file", "DEBUG", "status", "10020022",
849 "in_function : update_process_status : ".
850 "target_id = $target_id, ".
852 #------- DEBUG LOG END -------#
854 # Create or Delete start information file.
855 ($result) = &manage_start_info($target_id, $flag);
856 if ($result == $OK) {
857 # Set start status. (is_start)
859 $sslproxyadm_data{$target_id}{"is_start"} = $OK;
860 #--------- DEBUG LOG ---------#
861 &print_log("file", "DEBUG", "status", "10020023",
862 "Set is_start \"OK\". ".
863 "target_id = $target_id");
864 #------- DEBUG LOG END -------#
866 $sslproxyadm_data{$target_id}{"is_start"} = $NG;
867 #--------- DEBUG LOG ---------#
868 &print_log("file", "DEBUG", "status", "10020024",
869 "Set is_start \"NG\". ".
870 "target_id = $target_id");
871 #------- DEBUG LOG END -------#
873 # Set started flag. (now_start)
874 $sslproxyadm_data{$target_id}{"now_start"} = $flag;
877 #--------- DEBUG LOG ---------#
878 &print_log("file", "DEBUG", "status", "10020025",
879 "out_function : update_process_status : result = $result");
880 #------- DEBUG LOG END -------#
885 # Manage start information.
886 # Create and Delete start information file.
888 # @param[in] target_id target id
889 # @param[in] flag manage kind flag
890 # @retval OK/NG manage result
892 sub manage_start_info
895 # flag ig ON(Starting) or OFF(Stopped).
896 my ($target_id, $flag) = (@_);
898 #--------- DEBUG LOG ---------#
899 &print_log("file", "DEBUG", "status", "10020026",
900 "in_function : manage_start_info : ".
901 "target_id = $target_id, ".
903 #------- DEBUG LOG END -------#
905 # start_info file name = target_conf_file + "." + target_id
906 my $config_file = $sslproxyadm_data{$target_id}{"conf_file"};
907 my $start_info_file = $config_file.".".$target_id;
910 # Copy conf file to start information file.
911 my $cp_cmd = "/bin/cp -a $config_file $start_info_file";
912 ($result) = system($cp_cmd);
913 if ($result != $OK) {
914 &print_log("file", "ERROR", "status", "40020003",
915 "Copy command execute error. : $!");
918 #--------- DEBUG LOG ---------#
919 &print_log("file", "DEBUG", "status", "10020027",
920 "Copy start information file END. ".
921 "config_file = $config_file, ".
922 "start_info_file = $start_info_file");
923 #------- DEBUG LOG END -------#
924 } elsif ($flag == $OFF) {
925 # Delete start information file.
926 my $rm_cmd = "/bin/rm -f $start_info_file";
927 ($result) = system($rm_cmd);
928 if ($result != $OK) {
929 &print_log("file", "ERROR", "status", "40020004",
930 "Remove command execute error. : $!");
933 #--------- DEBUG LOG ---------#
934 &print_log("file", "DEBUG", "status", "10020028",
935 "Delete start information file END. ".
936 "config_file = $config_file, ".
937 "start_info_file = $start_info_file");
938 #------- DEBUG LOG END -------#
941 #--------- DEBUG LOG ---------#
942 &print_log("file", "DEBUG", "status", "10020029",
943 "out_function : manage_start_info : result = $result");
944 #------- DEBUG LOG END -------#
949 # Start sslproxy process.
951 # @retval OK/NG start result
955 #--------- DEBUG LOG ---------#
956 &print_log("file", "DEBUG", "control", "10010001",
957 "in_function : do_start");
958 #------- DEBUG LOG END -------#
963 # Search start target in sslproxyadm_data.
964 foreach my $target (sort keys(%sslproxyadm_data)) {
965 #--------- DEBUG LOG ---------#
966 &print_log("file", "DEBUG", "control", "10010002",
967 "Search start target. ".
969 #------- DEBUG LOG END -------#
970 # Check target section. (other is skip)
971 next if ($target !~ /^$TARGET_SECTION_KEY$/);
973 # Start executing, when target status Stopped.
974 if ($sslproxyadm_data{$target}{"is_start"} == $NG) {
976 # Start one target process.
977 ($result) = &start_process($target);
978 if ($result == $NG) {
979 &print_log("file", "ERROR", "control", "40010001",
980 "Start process error. ".
984 #--------- DEBUG LOG ---------#
985 &print_log("file", "DEBUG", "control", "10010003",
986 "Start target END. ".
988 #------- DEBUG LOG END -------#
990 &print_log("file", "WARN", "control", "30010001",
991 "Process already starting. ".
996 # Check start target count.
997 if ($start_cnt == 0) {
998 &print_log("file", "WARN", "control", "30010002",
999 "Target process not found for start.");
1000 # When process start failed, already Starting process will be Stopped.
1001 } elsif ($result == $NG) {
1002 #--------- DEBUG LOG ---------#
1003 &print_log("file", "DEBUG", "control", "10010004",
1004 "Start recover target.");
1005 #------- DEBUG LOG END -------#
1007 # Search recover target in sslproxyadm_data.
1008 foreach my $recover_target (sort keys(%sslproxyadm_data)) {
1009 #--------- DEBUG LOG ---------#
1010 &print_log("file", "DEBUG", "control", "10010005",
1011 "Search recover target. ".
1012 "recover_target = $recover_target");
1013 #------- DEBUG LOG END -------#
1014 # Check target section. (other is skip)
1015 next if ($recover_target !~ /^$TARGET_SECTION_KEY$/);
1017 # "now_start" flag is "ON" is Stopped.
1018 if ($sslproxyadm_data{$recover_target}{"now_start"} == $ON) {
1019 my $recover_result = $NG;
1020 # Recover(stop) one target process.
1021 ($recover_result) = &stop_process($recover_target);
1022 if ($recover_result == $NG) {
1023 &print_log("file", "ERROR", "control", "40010002",
1024 "Recover process error. ".
1025 "recover_target = $recover_target");
1027 #--------- DEBUG LOG ---------#
1028 &print_log("file", "DEBUG", "control", "10010006",
1029 "Recover target END. ".
1030 "recover_target = $recover_target");
1031 #------- DEBUG LOG END -------#
1036 #--------- DEBUG LOG ---------#
1037 &print_log("file", "DEBUG", "control", "10010007",
1038 "out_function : do_start : result = $result");
1039 #------- DEBUG LOG END -------#
1044 # Stop sslproxy process.
1046 # @retval OK/NG start result
1050 #--------- DEBUG LOG ---------#
1051 &print_log("file", "DEBUG", "control", "10010008",
1052 "in_function : do_stop");
1053 #------- DEBUG LOG END -------#
1058 # Search stop target in sslproxyadm_data.
1059 foreach my $target (sort keys(%sslproxyadm_data)) {
1060 #--------- DEBUG LOG ---------#
1061 &print_log("file", "DEBUG", "control", "10010009",
1062 "Search stop target. ".
1063 "target = $target");
1064 #------- DEBUG LOG END -------#
1065 # Check target section. (other is skip)
1066 next if ($target !~ /^$TARGET_SECTION_KEY$/);
1068 # Stop executing, when target status Starting.
1069 if ($sslproxyadm_data{$target}{"is_start"} == $OK) {
1071 # Stop one target process.
1072 ($result) = &stop_process($target);
1073 if ($result == $NG) {
1074 &print_log("file", "ERROR", "control", "40010003",
1075 "Stop process error. ".
1076 "target = $target");
1079 #--------- DEBUG LOG ---------#
1080 &print_log("file", "DEBUG", "control", "10010010",
1081 "Stop target END. ".
1082 "target = $target");
1083 #------- DEBUG LOG END -------#
1085 &print_log("file", "WARN", "control", "30010003",
1086 "Process already stopped. ".
1087 "target = $target");
1091 # Check stop target count.
1092 if ($stop_cnt == 0) {
1093 &print_log("file", "WARN", "control", "30010004",
1094 "Target process not found for stop.");
1097 #--------- DEBUG LOG ---------#
1098 &print_log("file", "DEBUG", "control", "10010011",
1099 "out_function : do_stop : result = $result");
1100 #------- DEBUG LOG END -------#
1105 # Restart sslproxy process.
1107 # @retval OK/NG start result
1111 #--------- DEBUG LOG ---------#
1112 &print_log("file", "DEBUG", "control", "10010012",
1113 "in_function : do_restart");
1114 #------- DEBUG LOG END -------#
1120 # Search restart target in sslproxyadm_data.
1121 foreach my $target (sort keys(%sslproxyadm_data)) {
1122 #--------- DEBUG LOG ---------#
1123 &print_log("file", "DEBUG", "control", "10010013",
1124 "Search restart target. ".
1125 "target = $target");
1126 #------- DEBUG LOG END -------#
1127 # Check target section. (other is skip)
1128 next if ($target !~ /^$TARGET_SECTION_KEY$/);
1130 # Stop executing for restart, when target status Starting.
1131 if ($sslproxyadm_data{$target}{"is_start"} == $OK) {
1133 # Stop one target process.
1134 ($result) = &stop_process($target);
1135 if ($result == $NG) {
1136 &print_log("file", "ERROR", "control", "40010004",
1137 "Stop process for restart error. ".
1138 "target = $target");
1141 #--------- DEBUG LOG ---------#
1142 &print_log("file", "DEBUG", "control", "10010014",
1143 "Stop target for restart END. ".
1144 "target = $target");
1145 #------- DEBUG LOG END -------#
1147 &print_log("file", "WARN", "control", "30010005",
1148 "Process already stopped for restart. ".
1149 "target = $target");
1152 # Start executing for restart, when target status Stopped.
1153 if ($sslproxyadm_data{$target}{"is_start"} == $NG) {
1155 # Start one target process.
1156 ($result) = &start_process($target);
1157 if ($result == $NG) {
1158 &print_log("file", "ERROR", "control", "40010005",
1159 "Start process for restart error. ".
1160 "target = $target");
1163 #--------- DEBUG LOG ---------#
1164 &print_log("file", "DEBUG", "control", "10010015",
1165 "Start target for restart END. ".
1166 "target = $target");
1167 #------- DEBUG LOG END -------#
1169 &print_log("file", "WARN", "control", "30010006",
1170 "Process already starting for restart. ".
1171 "target = $target");
1175 # Check stop target for restart count.
1176 if ($stop_cnt == 0) {
1177 &print_log("file", "WARN", "control", "30010007",
1178 "Target process not found for stop (restart).");
1181 # Check start target for restart count.
1182 if ($start_cnt == 0) {
1183 &print_log("file", "WARN", "control", "30010008",
1184 "Target process not found for start (restart).");
1185 # When process start for restart failed, already Starting process will be Stopped.
1186 } elsif ($result == $NG) {
1187 #--------- DEBUG LOG ---------#
1188 &print_log("file", "DEBUG", "control", "10010016",
1189 "Start recover target for restart.");
1190 #------- DEBUG LOG END -------#
1192 # Search recover target in sslproxyadm_data.
1193 foreach my $recover_target (sort keys(%sslproxyadm_data)) {
1194 #--------- DEBUG LOG ---------#
1195 &print_log("file", "DEBUG", "control", "10010017",
1196 "Search recover target for restart. ".
1197 "recover_target = $recover_target");
1198 #------- DEBUG LOG END -------#
1199 # Check target section. (other is skip)
1200 next if ($recover_target !~ /^$TARGET_SECTION_KEY$/);
1202 # "now_start" flag is "ON" is Stopped.
1203 if ($sslproxyadm_data{$recover_target}{"now_start"} == $ON) {
1204 my $recover_result = $NG;
1205 # Recover(stop) one target process.
1206 ($recover_result) = &stop_process($recover_target);
1207 if ($recover_result == $NG) {
1208 &print_log("file", "ERROR", "control", "40010006",
1209 "Recover process for restart error. ".
1210 "recover_target = $recover_target");
1212 #--------- DEBUG LOG ---------#
1213 &print_log("file", "DEBUG", "control", "10010018",
1214 "Recover target for restart END. ".
1215 "recover_target = $recover_target");
1216 #------- DEBUG LOG END -------#
1221 #--------- DEBUG LOG ---------#
1222 &print_log("file", "DEBUG", "control", "10010019",
1223 "out_function : do_restart : result = $result");
1224 #------- DEBUG LOG END -------#
1229 # Reload sslproxy process.
1231 # @retval OK/NG start result
1235 #--------- DEBUG LOG ---------#
1236 &print_log("file", "DEBUG", "control", "10010020",
1237 "in_function : do_reload");
1238 #------- DEBUG LOG END -------#
1244 # Search reload target in sslproxyadm_data.
1245 foreach my $target (sort keys(%sslproxyadm_data)) {
1246 #--------- DEBUG LOG ---------#
1247 &print_log("file", "DEBUG", "control", "10010021",
1248 "Search reload target. ".
1249 "target = $target");
1250 #------- DEBUG LOG END -------#
1251 # Check target section. (other is skip)
1252 next if ($target !~ /^$TARGET_SECTION_KEY$/);
1254 # Stop executing for reload, when target status Starting
1255 # and process status Abnormal(NG).
1256 if ($sslproxyadm_data{$target}{"is_start"} == $OK) {
1257 if ($sslproxyadm_data{$target}{"proc_status"} != $OK) {
1259 # Stop one target process.
1260 ($result) = &stop_process($target);
1261 if ($result == $NG) {
1262 &print_log("file", "ERROR", "control", "40010007",
1263 "Stop process for reload error. ".
1264 "target = $target");
1267 #--------- DEBUG LOG ---------#
1268 &print_log("file", "DEBUG", "control", "10010022",
1269 "Stop target for reload END. ".
1270 "target = $target");
1271 #------- DEBUG LOG END -------#
1273 #--------- DEBUG LOG ---------#
1274 &print_log("file", "DEBUG", "control", "10010023",
1275 "Process normal starting for reload. ".
1276 "target = $target");
1277 #------- DEBUG LOG END -------#
1280 &print_log("file", "WARN", "control", "30010009",
1281 "Process already stopped for reload. ".
1282 "target = $target");
1285 # Start executing for reload, when target status Stopped.
1286 if ($sslproxyadm_data{$target}{"is_start"} == $NG) {
1288 # Start one target process.
1289 ($result) = &start_process($target);
1290 if ($result == $NG) {
1291 &print_log("file", "ERROR", "control", "40010008",
1292 "Start process for reload error. ".
1293 "target = $target");
1296 #--------- DEBUG LOG ---------#
1297 &print_log("file", "DEBUG", "control", "10010024",
1298 "Start target for reload END. ".
1299 "target = $target");
1300 #------- DEBUG LOG END -------#
1302 &print_log("file", "WARN", "control", "30010010",
1303 "Process already starting for reload. ".
1304 "target = $target");
1308 # Check stop target for reload count.
1309 if ($stop_cnt == 0) {
1310 &print_log("file", "WARN", "control", "30010011",
1311 "Target process not found for stop (reload).");
1314 # Check start target for reload count.
1315 if ($start_cnt == 0) {
1316 &print_log("file", "WARN", "control", "30010012",
1317 "Target process not found for start (reload).");
1318 # When process start for reload failed, already Starting process will be Stopped.
1319 } elsif ($result == $NG) {
1320 #--------- DEBUG LOG ---------#
1321 &print_log("file", "DEBUG", "control", "10010025",
1322 "Start recover target for reload.");
1323 #------- DEBUG LOG END -------#
1325 # Search recover target in sslproxyadm_data.
1326 foreach my $recover_target (sort keys(%sslproxyadm_data)) {
1327 #--------- DEBUG LOG ---------#
1328 &print_log("file", "DEBUG", "control", "10010026",
1329 "Search recover target for reload. ".
1330 "recover_target = $recover_target");
1331 #------- DEBUG LOG END -------#
1332 # Check target section. (other is skip)
1333 next if ($recover_target !~ /^$TARGET_SECTION_KEY$/);
1335 # "now_start" flag is "ON" is Stopped.
1336 if ($sslproxyadm_data{$recover_target}{"now_start"} == $ON) {
1337 my $recover_result = $NG;
1338 # Recover(stop) one target process.
1339 ($recover_result) = &stop_process($recover_target);
1340 if ($recover_result == $NG) {
1341 &print_log("file", "ERROR", "control", "40010009",
1342 "Recover process for reload error. ".
1343 "recover_target = $recover_target");
1345 #--------- DEBUG LOG ---------#
1346 &print_log("file", "DEBUG", "control", "10010027",
1347 "Recover target for reload END. ".
1348 "recover_target = $recover_target");
1349 #------- DEBUG LOG END -------#
1354 #--------- DEBUG LOG ---------#
1355 &print_log("file", "DEBUG", "control", "10010028",
1356 "out_function : do_reload : result = $result");
1357 #------- DEBUG LOG END -------#
1362 # Check all target is normal Starting.
1364 # @retval OK/NG check result
1368 #--------- DEBUG LOG ---------#
1369 &print_log("file", "DEBUG", "status", "10020030",
1370 "in_function : do_check");
1371 #------- DEBUG LOG END -------#
1375 # Check all target in sslproxyadm_data.
1376 foreach my $target (sort keys(%sslproxyadm_data)) {
1377 # Get target id from sslproxyadm_data
1378 # Check target section. (other is skip)
1379 next if ($target !~ /^$TARGET_SECTION_KEY$/);
1380 #--------- DEBUG LOG ---------#
1381 &print_log("file", "DEBUG", "status", "10020031",
1382 "Check target = $target");
1383 #------- DEBUG LOG END -------#
1385 # Check proc_status is OK and prosess is Starting.
1386 if ($sslproxyadm_data{$target}{"proc_status"} != $OK ||
1387 $sslproxyadm_data{$target}{"is_start"} != $OK) {
1388 &print_log("file", "WARN", "status", "30020001",
1389 "Check NG. Found NG target. target = $target");
1395 #--------- DEBUG LOG ---------#
1396 &print_log("file", "DEBUG", "status", "10020032",
1397 "out_function : do_check : result = $result");
1398 #------- DEBUG LOG END -------#
1404 # Logger, Target, Process.
1406 # @retval OK/NG print result (always OK)
1410 #--------- DEBUG LOG ---------#
1411 &print_log("file", "DEBUG", "status", "10020033",
1412 "in_function : do_status");
1413 #------- DEBUG LOG END -------#
1417 print STDOUT "----- Print SSLproxyadm status start -----\n";
1419 # Print common information.
1420 print STDOUT "[ Common Data ]\n";
1421 print STDOUT "Common config file : $CONFIG_FILE\n";
1422 print STDOUT "Output log file : $LOG_FILE\n";
1423 print STDOUT "Output log level : $LOG_LEVEL\n";
1424 print STDOUT "Log rotate config file : $LOGROTATE_CONF_FILE\n";
1425 print STDOUT "Log rotate status file : $LOGROTATE_STAT_FILE\n";
1428 # Print all target information in sslproxyadm_data.
1429 print STDOUT "[ Target Data ]\n";
1430 my $target_data_count = keys(%sslproxyadm_data);
1431 if ($target_data_count == 0) {
1432 print STDOUT " Target nothing.\n";
1434 foreach my $target (sort keys(%sslproxyadm_data)) {
1435 # Get target id from sslproxyadm_data
1436 # Check target section. (other is skip)
1437 next if ($target !~ /^$TARGET_SECTION_KEY$/);
1439 print STDOUT "TargetID : $target\n";
1440 print STDOUT " Config file : " .
1441 $sslproxyadm_data{$target}{"conf_file"} .
1444 if ($sslproxyadm_data{$target}{"proc_status"} == $OK) {
1445 print STDOUT " Process status : Normal.\n";
1447 print STDOUT " Process status : Abnormal.\n";
1450 if ($sslproxyadm_data{$target}{"is_start"} == $OK) {
1451 print STDOUT " Execute status : Starting. " .
1453 $sslproxyadm_data{$target}{"pid"} .
1456 print STDOUT " Execute status : Stopped.\n";
1459 if ($sslproxyadm_data{$target}{"proc_status"} == $NG) {
1460 print STDOUT " Status detail : \n";
1461 if ($sslproxyadm_data{$target}{"is_start"} == $OK) {
1462 if ($sslproxyadm_data{$target}{"cmp_config"} == $NG) {
1464 ": Different configuration file is used now.\n";
1466 if ($sslproxyadm_data{$target}{"start_info"} == $NG) {
1468 ": Start information file nothing. (Manual start?)\n";
1471 ": Start information file exist. (Change config?)\n";
1472 if ($sslproxyadm_data{$target}{"cmp_start_info"} == $NG) {
1474 ": Start information file is Different. \n";
1478 if ($sslproxyadm_data{$target}{"start_info"} == $OK) {
1480 ": Start information file exist. (Change config or Manual stop?)\n";
1481 if ($sslproxyadm_data{$target}{"cmp_start_info"} == $NG) {
1483 ": Start information file is Different. \n";
1492 # Print unknown process information in process_data.
1493 print STDOUT "[ Unknown SSLproxy process ]\n";
1494 my $process_data_count = keys(%process_data);
1495 if ($process_data_count == 0) {
1496 print STDOUT " Process nothing.\n";
1498 foreach my $proc_target (sort keys(%process_data)) {
1499 if ($process_data{$proc_target}{"known"} != $ON) {
1500 print STDOUT "TargetID : $proc_target\n";
1501 print STDOUT " Config file : " .
1502 $process_data{$proc_target}{"conf_file"} .
1504 print STDOUT " PID : " .
1505 $process_data{$proc_target}{"pid"} .
1511 print STDOUT "----- Print SSLproxyadm status end -----\n";
1513 #--------- DEBUG LOG ---------#
1514 &print_log("file", "DEBUG", "status", "10020034",
1515 "out_function : do_status : result = $result");
1516 #------- DEBUG LOG END -------#
1521 # Check target configuration file format.
1523 # @retval OK/NG check result
1527 #--------- DEBUG LOG ---------#
1528 &print_log("file", "DEBUG", "config", "10030017",
1529 "in_function : do_config");
1530 #------- DEBUG LOG END -------#
1534 # Search target configration file.
1535 foreach my $section (sort keys(%sslproxyadm_data)) {
1536 #--------- DEBUG LOG ---------#
1537 &print_log("file", "DEBUG", "config", "10030018",
1539 "section = $section");
1540 #------- DEBUG LOG END -------#
1541 my $target_conf_file = "";
1542 # Check target section.
1543 next if ($section !~ /^$TARGET_SECTION_KEY$/);
1544 # Get target configration file name.
1545 $target_conf_file = $sslproxyadm_data{$section}{"conf_file"};
1546 # Read target configration file for format check.
1548 ($result) = &read_config($target_conf_file, "target");
1549 if ($result == $NG) {
1550 &print_log("file", "ERROR", "config", "40030012",
1551 "Target config file format error. ".
1552 "file = $target_conf_file");
1555 #--------- DEBUG LOG ---------#
1556 &print_log("file", "DEBUG", "config", "10030019",
1557 "Target config file format OK. ".
1558 "target_conf_file = $target_conf_file");
1559 #------- DEBUG LOG END -------#
1562 #&print_table_data(%target_data);
1565 #--------- DEBUG LOG ---------#
1566 &print_log("file", "DEBUG", "config", "10030020",
1567 "out_function : do_config : ".
1568 "result = $result");
1569 #------- DEBUG LOG END -------#
1574 # Start specified sslproxy process.
1575 # Start process and Create start information and Update process status.
1577 # @param[in] target_id target id
1578 # @retval OK/NG start result
1583 my ($target_id) = (@_);
1585 #--------- DEBUG LOG ---------#
1586 &print_log("file", "DEBUG", "control", "10010029",
1587 "in_function : start_process : ".
1588 "target_id = $target_id");
1589 #------- DEBUG LOG END -------#
1591 my $config_file = $sslproxyadm_data{$target_id}{"conf_file"};
1593 # Check sslproxy command file. Try open for exist check.
1594 if (open(TEMP, "<$SSLPROXY_PATH$SSLPROXY")) {
1596 # Execute sslproxy start command.
1597 # /usr/sbin/sslproxy target_id config_file
1598 my $cmd_result = system("$SSLPROXY_PATH$SSLPROXY $target_id $config_file");
1599 # Check command result.
1600 if ($cmd_result != 0) {
1601 &print_log("file", "ERROR", "control", "40010010",
1602 "sslproxy command execution error.");
1604 # Check Starting sslproxy exist or not.
1605 # Open ps command output.
1606 my $ps_cmd = "/bin/ps -C $SSLPROXY -o pid=,cmd= |";
1607 if (!open(PROCESS, $ps_cmd)) {
1608 &print_log("file", "ERROR", "control", "40010011",
1609 "Cannot open ps command output.");
1611 # Read ps command data.
1613 while ($line_data = <PROCESS>) {
1614 # Read one line data. (one process)
1616 $line_data =~ s/^\s*|\n$//g;
1617 #--------- DEBUG LOG ---------#
1618 &print_log("file", "DEBUG", "control", "10010030",
1619 "Read one process line data = $line_data");
1620 #------- DEBUG LOG END -------#
1622 # Split @param by " " delimiter.
1624 # $param[1] -> cmd (ex. "./sslproxy")
1625 # $param[2] -> target id
1626 # $param[3] -> target config file
1627 my @param = split /\s/, $line_data, 4;
1628 # Check target_id exist or not.
1629 if ($param[2] eq $target_id) {
1630 # Target process found. Save pid.
1631 $sslproxyadm_data{$target_id}{"pid"} = $param[0];
1633 #--------- DEBUG LOG ---------#
1634 &print_log("file", "DEBUG", "control", "10010031",
1635 "Starting target process found.");
1636 #------- DEBUG LOG END -------#
1644 &print_log("file", "ERROR", "control", "40010012",
1645 "SSLproxy command file not exist.");
1648 if ($result == $NG) {
1649 &print_log("file", "ERROR", "control", "40010013",
1650 "Start target process error. ".
1651 "target_id = $target_id");
1653 # Set and update process status. (Starting)
1654 ($result) = &update_process_status($target_id, $ON);
1655 if ($result == $NG) {
1656 &print_log("file", "ERROR", "control", "40010014",
1657 "Update target process status (Starting) error. ".
1658 "target_id = $target_id");
1659 &stop_process($target_id);
1661 #--------- DEBUG LOG ---------#
1662 &print_log("file", "DEBUG", "control", "10010032",
1663 "Update target process status (Starting) END.");
1664 #------- DEBUG LOG END -------#
1667 if ($result == $OK) {
1668 &print_log("file", "INFO", "control", "20010001",
1669 "SSLproxy process start OK. ".
1670 "target_id = $target_id");
1673 #--------- DEBUG LOG ---------#
1674 &print_log("file", "DEBUG", "control", "10010033",
1675 "out_function : start_process : ".
1676 "result = $result");
1677 #------- DEBUG LOG END -------#
1682 # Stop specified sslproxy process.
1683 # Stop process and Delete start information and Update process status.
1685 # @param[in] target_id target id
1686 # @retval OK/NG start result
1691 my ($target_id) = (@_);
1693 #--------- DEBUG LOG ---------#
1694 &print_log("file", "DEBUG", "control", "10010034",
1695 "in_function : stop_process : ".
1696 "target_id = $target_id");
1697 #------- DEBUG LOG END -------#
1699 my $pid = $sslproxyadm_data{$target_id}{"pid"};
1701 # Execute sslproxy stop command.
1702 # /bin/kill sslproxy_pid
1703 system("/bin/kill $pid");
1705 # Check Stopped sslproxy exist or not.
1706 # Open grep command output.
1707 my $grep_cmd = "/bin/ps -C $SSLPROXY -o args --no-headers | ".
1708 "/bin/cut -d\" \" -f2 | ".
1709 "/bin/grep $target_id |";
1710 if (!open(GREPDATA, $grep_cmd)) {
1711 &print_log("file", "ERROR", "control", "40010015",
1712 "Cannot open shell command output.");
1714 #--------- DEBUG LOG ---------#
1715 &print_log("file", "DEBUG", "control", "10010035",
1716 "Get grep command output.");
1717 #------- DEBUG LOG END -------#
1718 my @grep_data = <GREPDATA>;
1719 my $grep_cnt = @grep_data;
1720 # Check grep output size. 0 is target process not found.
1721 if ($grep_cnt == 0) {
1722 #--------- DEBUG LOG ---------#
1723 &print_log("file", "DEBUG", "control", "10010036",
1724 "Stopped target process not found (stop OK).");
1725 #------- DEBUG LOG END -------#
1731 if ($result == $NG) {
1732 &print_log("file", "ERROR", "control", "40010016",
1733 "Stop target process error. ".
1734 "target_id = $target_id");
1736 # Set and update process status. (Stopped)
1737 ($result) = &update_process_status($target_id, $OFF);
1738 if ($result == $NG) {
1739 &print_log("file", "ERROR", "control", "40010017",
1740 "Update target process status (Stopped) error. ".
1741 "target_id = $target_id");
1743 #--------- DEBUG LOG ---------#
1744 &print_log("file", "DEBUG", "control", "10010037",
1745 "Update target process status (Stopped) END.");
1746 #------- DEBUG LOG END -------#
1749 if ($result == $OK) {
1750 &print_log("file", "INFO", "control", "20010002",
1751 "SSLproxy process stop OK. ".
1752 "target_id = $target_id");
1755 #--------- DEBUG LOG ---------#
1756 &print_log("file", "DEBUG", "control", "10010038",
1757 "out_function : stop_process : ".
1758 "result = $result");
1759 #------- DEBUG LOG END -------#
1765 # Set logfile/loglevel and Execute logrotate.
1767 # @retval OK/NG check result
1771 #--------- DEBUG LOG ---------#
1772 &print_log("file", "DEBUG", "logger", "10040001",
1773 "in_function : set_log");
1774 #------- DEBUG LOG END -------#
1777 #--------- DEBUG LOG ---------#
1778 &print_log("file", "DEBUG", "logger", "10040002",
1779 "Config before value. ".
1780 "LOG_LEVEL = $LOG_LEVEL, ".
1781 "LOG_FILE = $LOG_FILE");
1782 #------- DEBUG LOG END -------#
1784 # Get loglevel from logger configuration.
1785 my $loglevel = $sslproxyadm_data{$LOGGER_SECTION_KEY}{"log_level"};
1786 if ($loglevel eq "") {
1787 &print_log("file", "WARN", "logger", "30040001",
1788 "Log level not found in config. ".
1789 "Use default log level. ".
1790 "level = $LOG_LEVEL");
1791 $loglevel = $LOG_LEVEL;
1793 # Check config log level range.
1794 if ($loglevel ne "debug" &&
1795 $loglevel ne "info" &&
1796 $loglevel ne "warn" &&
1797 $loglevel ne "error" &&
1798 $loglevel ne "fatal") {
1799 &print_log("file", "ERROR", "logger", "40040001",
1800 "Invalid config log level. ".
1801 "level = $loglevel");
1804 #--------- DEBUG LOG ---------#
1805 &print_log("file", "DEBUG", "logger", "10040003",
1806 "Config log level is $loglevel.");
1807 #------- DEBUG LOG END -------#
1811 # Get logfile from logger configuration.
1812 my $logfile = $sslproxyadm_data{$LOGGER_SECTION_KEY}{"log_filename"};
1813 if ($result == $OK) {
1814 if ($logfile eq "") {
1815 &print_log("file", "WARN", "logger", "30040002",
1816 "Log file not found in config. ".
1817 "Use default log file. ".
1818 "file = $LOG_FILE");
1819 $logfile = $LOG_FILE;
1821 # Check log file. Try open.
1822 if(!open(LOGFILE, ">>$logfile")) {
1823 &print_log("file", "ERROR", "logger", "40040002",
1824 "Cannot open config log file. ".
1829 if ($logfile ne $LOG_FILE) {
1830 &print_log("file", "WARN", "logger", "30040003",
1831 "Log file is chaged. ".
1832 "$LOGROTATE_CONF_FILE file ".
1833 "should also change for log rotate.");
1835 #--------- DEBUG LOG ---------#
1836 &print_log("file", "DEBUG", "logger", "10040004",
1837 "Log file is still default.");
1838 #------- DEBUG LOG END -------#
1844 # Execute logrotate command.
1845 if ($result == $OK) {
1846 ($result) = system("$LOGROTATE_CMD $LOGROTATE_CONF_FILE");
1847 if ($result != $OK) {
1848 &print_log("file", "ERROR", "logger", "40040003",
1849 "Logrotate execute error. : $!");
1851 #--------- DEBUG LOG ---------#
1852 &print_log("file", "DEBUG", "logger", "10040005",
1853 "Not change logger setteing.");
1854 #------- DEBUG LOG END -------#
1856 # Change logger setteing.
1857 $LOG_LEVEL = $loglevel;
1858 $LOG_FILE = $logfile;
1859 #--------- DEBUG LOG ---------#
1860 &print_log("file", "DEBUG", "logger", "10040006",
1861 "Change logger setteing. ".
1862 "level = $LOG_LEVEL, ".
1863 "file = $LOG_FILE");
1864 #------- DEBUG LOG END -------#
1868 #--------- DEBUG LOG ---------#
1869 &print_log("file", "DEBUG", "logger", "10040007",
1870 "out_function : set_log : ".
1871 "result = $result");
1872 #------- DEBUG LOG END -------#
1877 # Output log message to console or log file.
1879 # output device string -> cout/cerr/file/fcout/fcerr
1880 # log level string -> DEBUG/INFO/WARN/ERROR/FATAL (1-5)
1881 # log category string -> control/status/config/logger/common (1-5)
1882 # (sslproxyadm_xxxxx)
1883 # message number -> level_numberX + category_numberXXX + XXXX
1886 # @param[in] outdev output device
1887 # @param[in] level message log level
1888 # @param[in] category log category
1889 # @param[in] msgid message number
1890 # @param[in] msg message string
1895 my ($outdev, $level, $category, $msgid, $msg) = (@_);
1897 #--------- DEBUG LOG ---------#
1898 if ($LOGGER_DEBUG) {
1899 print STDOUT "in_function : print_log : ".
1900 "outdev = $outdev, ".
1902 "category = $category, ".
1906 #------- DEBUG LOG END -------#
1908 # Check message and output log level.
1909 ($result) =&check_log_level($level);
1910 if ($result == $OK) {
1911 # Check log category range.
1912 if ($category ne "control" &&
1913 $category ne "status" &&
1914 $category ne "config" &&
1915 $category ne "logger" &&
1916 $category ne "common") {
1917 print STDERR "Print log error : Invalid log category.\n";
1918 # Check log output device range.
1919 } elsif ($outdev ne "cout" &&
1920 $outdev ne "cerr" &&
1921 $outdev ne "file" &&
1922 $outdev ne "fcout" &&
1923 $outdev ne "fcerr") {
1924 print STDERR "Print log error : Invalid log output device.\n";
1927 if ($outdev eq "cout" || $outdev eq "fcout") {
1928 print STDOUT "$msg\n";
1929 } elsif ($outdev eq "cerr" || $outdev eq "fcerr") {
1930 print STDERR "$msg\n";
1932 # Print to lof file.
1933 if ($outdev eq "file" || $outdev eq "fcout" || $outdev eq "fcerr") {
1934 if(!open(LOGFILE, ">>$LOG_FILE")) {
1935 print STDERR "Cannot open log file.\n";
1937 my $now_date = localtime();
1938 print LOGFILE "$now_date ".
1940 "sslproxyadm_$category ".
1949 #--------- DEBUG LOG ---------#
1950 if ($LOGGER_DEBUG) {
1951 print STDOUT "out_function : print_log\n";
1953 #------- DEBUG LOG END -------#
1957 # Check message and output log level.
1959 # @param[in] level message log level
1960 # @retval OK/NG check result
1967 #--------- DEBUG LOG ---------#
1968 if ($LOGGER_DEBUG) {
1969 print STDOUT "in_function : check_log_level : level = $level\n";
1971 #------- DEBUG LOG END -------#
1973 # Check message log level range.
1974 if ($level ne "DEBUG" &&
1977 $level ne "ERROR" &&
1978 $level ne "FATAL") {
1979 print STDERR "Print log error : Invalid message log level.\n";
1980 # Check output log level.
1981 } elsif ($LOG_LEVEL eq "debug") {
1983 #--------- DEBUG LOG ---------#
1984 if ($LOGGER_DEBUG) {
1985 print STDOUT "Logout level OK. out[$LOG_LEVEL] msg[$level]\n";
1987 #------- DEBUG LOG END -------#
1988 } elsif ($LOG_LEVEL eq "info") {
1989 if ($level eq "INFO" ||
1991 $level eq "ERROR" ||
1992 $level eq "FATAL") {
1994 #--------- DEBUG LOG ---------#
1995 if ($LOGGER_DEBUG) {
1996 print STDOUT "Logout level OK. out[$LOG_LEVEL] msg[$level]\n";
1998 #------- DEBUG LOG END -------#
2000 #--------- DEBUG LOG ---------#
2001 if ($LOGGER_DEBUG) {
2002 print STDOUT "Logout level NG. out[$LOG_LEVEL] msg[$level]\n";
2004 #------- DEBUG LOG END -------#
2006 } elsif ($LOG_LEVEL eq "warn") {
2007 if ($level eq "WARN" ||
2008 $level eq "ERROR" ||
2009 $level eq "FATAL") {
2011 #--------- DEBUG LOG ---------#
2012 if ($LOGGER_DEBUG) {
2013 print STDOUT "Logout level OK. out[$LOG_LEVEL] msg[$level]\n";
2015 #------- DEBUG LOG END -------#
2017 #--------- DEBUG LOG ---------#
2018 if ($LOGGER_DEBUG) {
2019 print STDOUT "Logout level NG. out[$LOG_LEVEL] msg[$level]\n";
2021 #------- DEBUG LOG END -------#
2023 } elsif ($LOG_LEVEL eq "error") {
2024 if ($level eq "ERROR" ||
2025 $level eq "FATAL") {
2027 #--------- DEBUG LOG ---------#
2028 if ($LOGGER_DEBUG) {
2029 print STDOUT "Logout level OK. out[$LOG_LEVEL] msg[$level]\n";
2031 #------- DEBUG LOG END -------#
2033 #--------- DEBUG LOG ---------#
2034 if ($LOGGER_DEBUG) {
2035 print STDOUT "Logout level NG. out[$LOG_LEVEL] msg[$level]\n";
2037 #------- DEBUG LOG END -------#
2039 } elsif ($LOG_LEVEL eq "fatal") {
2040 if ($level eq "FATAL") {
2042 #--------- DEBUG LOG ---------#
2043 if ($LOGGER_DEBUG) {
2044 print STDOUT "Logout level OK. out[$LOG_LEVEL] msg[$level]\n";
2046 #------- DEBUG LOG END -------#
2048 #--------- DEBUG LOG ---------#
2049 if ($LOGGER_DEBUG) {
2050 print STDOUT "Logout level NG. out[$LOG_LEVEL] msg[$level]\n";
2052 #------- DEBUG LOG END -------#
2055 print STDERR "Print log error : Invalid output log level.\n";
2058 #--------- DEBUG LOG ---------#
2059 if ($LOGGER_DEBUG) {
2060 print STDOUT "out_function : check_log_level : result = $result\n";
2062 #------- DEBUG LOG END -------#
2067 # Show command usage.
2071 #--------- DEBUG LOG ---------#
2072 &print_log("file", "DEBUG", "common", "10050028",
2073 "in_function : usage");
2074 #------- DEBUG LOG END -------#
2076 print STDERR "\nUsage : sslproxyadm ".
2077 "\{start|stop|restart|reload|check|status|config\} ".
2078 "[config_file_name]\n".
2079 " start Start SSLproxy process.\n".
2080 " stop Stop SSLproxy process.\n".
2081 " restart Restart SSLproxy process.\n".
2082 " reload Re-configure SSLproxy process.\n".
2083 " check Check SSLproxy process status.\n".
2084 " status Print SSLproxy process status.\n".
2085 " config Check SSLproxy configration file.\n\n";
2087 #--------- DEBUG LOG ---------#
2088 &print_log("file", "DEBUG", "common", "10050029",
2089 "out_function : usage");
2090 #------- DEBUG LOG END -------#
2094 # Exit sslproxyadm command.
2096 # @param[in] result command result
2101 my ($result) = (@_);
2102 #--------- DEBUG LOG ---------#
2103 &print_log("file", "DEBUG", "common", "10050030",
2104 "in_function : do_exit : result = $result");
2105 #------- DEBUG LOG END -------#
2107 if ($result == $OK) {
2108 &print_log("fcout", "INFO", "common", "20050001",
2109 "SSLproxyadm command ($CMD_OPT) is successful.");
2110 } elsif ($result == $NG) {
2111 &print_log("fcerr", "INFO", "common", "20050002",
2112 "SSLproxyadm command ($CMD_OPT) is failure.");
2115 #--------- DEBUG LOG ---------#
2116 &print_log("file", "DEBUG", "common", "10050031",
2117 "out_function : do_exit");
2118 #------- DEBUG LOG END -------#
2123 # Print specified table data to STDOUT for debug.
2125 # @param[in] table_data command result
2127 sub print_table_data
2129 my (%table_data) = (@_);
2130 print STDOUT "\n*** Print table data ***\n";
2131 my $section_count = keys(%table_data);
2132 print STDOUT "Section count[$section_count]\n";
2133 while (my ($section_name, $section_data) = each (%table_data)) {
2134 my $key_count = keys(%$section_data);
2135 print STDOUT " [$section_name] section. Key count[$key_count]\n";
2136 while (my ($key, $value) = each (%$section_data)) {
2137 print STDOUT " Key[$key] Value[$value]\n";