Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 548 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
548 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
639 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
548 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#匯入套件
29
require_once("qbpwcf/allInOne.php");
30
 
31
#建議的log位置
32
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
33
 
34
#函式說明:
35
#執行 systemd 程序來確保服務是運行中.
36
#回傳結果:
37
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
38
#$result["error"],錯誤訊息.
39
#$result["function"],當前執行的函式名稱.
40
#$result["argu"],所使用的參數.
41
#$result["content"],執行的結果.
42
#必填參數:
43
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
44
$conf["fileArgu"]=__FILE__;
45
#$conf["name"],字串,服務名稱.
46
$conf["name"]="httpd";
47
#可省略參數:
48
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
49
#$conf["username"]="";
50
#$conf["password"],字串,使用者的密碼,預設不使用.
51
#$conf["password"]="";
52
#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
53
#$conf["checkListen"]=array(array("ip"=>"169.254.1.1:443/tcp"));
54
$conf["checkListen"]=array(array("ip"=>"169.254.1.1:443/tcp"),array("name"=>"httpd"));
55
#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
56
#$conf["interval"]="30";
57
#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
58
$conf["reportOnly"]="true";
59
#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
60
$conf["verbose"]="true";
61
#參考資料:
62
#無.
63
#備註:
64
#無.
65
$keepServiceUp=cmd::keepServiceUp($conf);
66
 
67
#如果執行失敗
68
if($keepServiceUp["status"]==="false"){
69
 
70
	#函式說明:
71
	#撰寫log
72
	#回傳結果:
73
	#$result["status"],狀態,"true"或"false".
74
	#$result["error"],錯誤訊息陣列.
75
	#$result["function"],當前函式的名稱.
76
	#$result["argu"],使用的參數.
77
	#必填參數:
78
	#$conf["path"],字串,log檔案的路徑與名稱.
79
	$conf["path"]=$logFile;
80
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
81
	$conf["content"]=$keepServiceUp;
82
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
83
	$conf["fileArgu"]=__FILE__;
84
	#可省略參數:
85
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
86
	#$conf["rewrite"]="false";
87
	#參考資料:
88
	#無.
89
	#備註:
90
	#無.
91
	$record=logs::record($conf);
92
	unset($conf);
93
 
94
	#如果寫log失敗
95
	if($record["status"]==="false"){
96
 
97
		#印出結果
98
		var_dump($record);
99
 
100
		}#if end
101
 
102
	#結束執行,回傳錯誤代碼1
103
	exit(1);
104
 
105
	}#if end
106
 
107
#debug
108
var_dump($keepServiceUp);
109
 
110
?>