Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
226 liveuser 6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
3 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/>.
226 liveuser 22
 
3 liveuser 23
*/
24
 
25
/*
26
安裝方式:
27
將該檔案移動到 /usr/bin/ 底下
28
 
29
描述:
30
確認 mariabdb 有在運作
31
*/
32
 
33
#使用命名空間qbpwcf
34
namespace qbpwcf;
35
 
36
#取得 lib path
37
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
38
 
39
#如果執行失敗
40
if($status!==0){
41
 
42
	#debug
43
	var_dump(__LINE__,$output);
44
 
45
	#結束執行,回傳shell 1.
46
	exit(1);
47
 
48
	}#if end
49
 
50
#儲存lib path
51
$folderOfUsrLib=$output[0];
52
 
53
#以該檔案的實際位置的 lib path 為 include path 首位
54
$output=array();
55
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
56
 
57
#如果執行失敗
58
if($status!==0){
59
 
60
	#debug
61
	var_dump(__LINE__,$output);
62
 
63
	#結束執行,回傳shell 1.
64
	exit(1);
65
 
66
	}#if end
67
 
226 liveuser 68
#設置 include path
3 liveuser 69
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
70
 
71
#匯入外部套件
72
include("allInOne.php");
73
 
74
#無窮迴圈
75
while(true){
226 liveuser 76
 
3 liveuser 77
	#查詢服務啟動沒
78
	#涵式說明:
79
	#執行 systemd 程序來管理服務.
80
	#回傳結果:
81
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
82
	#$result["error"],錯誤訊息.
83
	#$result["function"],當前執行的函數名稱.
84
	#$result["argu"],所使用的參數.
85
	#$result["content"],執行的結果.
226 liveuser 86
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
87
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 88
	#必填參數:
89
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
90
	$conf["fileArgu"]=__FILE__;
91
	#$conf["name"],字串,服務名稱.
92
	$conf["name"]="mariadb";
93
	#可省略參數:
94
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
95
	$conf["operation"]="status";
96
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
97
	#$conf["username"]="";
98
	#$conf["password"],字串,使用者的密碼,預設不使用.
99
	#$conf["password"]="";
100
	$systemd=cmd::systemd($conf);
101
	unset($conf);
226 liveuser 102
 
3 liveuser 103
	#若運行出錯
104
	if($systemd["status"]==="false"){
226 liveuser 105
 
3 liveuser 106
		#debug
107
		var_dump($systemd);
226 liveuser 108
 
3 liveuser 109
		#停止執行
110
		exit;
226 liveuser 111
 
3 liveuser 112
		}#if end
226 liveuser 113
 
3 liveuser 114
	#如果服務沒啟動
115
	if($systemd["content"]["srerviceInfo"]["on"]==="false"){
226 liveuser 116
 
3 liveuser 117
		#啟動服務
118
		#涵式說明:
119
		#執行 systemd 程序來管理服務.
120
		#回傳結果:
121
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
122
		#$result["error"],錯誤訊息.
123
		#$result["function"],當前執行的函數名稱.
124
		#$result["argu"],所使用的參數.
125
		#$result["content"],執行的結果.
226 liveuser 126
		#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
127
		#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 128
		#必填參數:
129
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
130
		$conf["fileArgu"]=__FILE__;
131
		#$conf["name"],字串,服務名稱.
132
		$conf["name"]="mariadb";
133
		#可省略參數:
134
		#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
135
		$conf["operation"]="start";
136
		#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
137
		#$conf["username"]="";
138
		#$conf["password"],字串,使用者的密碼,預設不使用.
139
		#$conf["password"]="";
140
		$systemd=cmd::systemd($conf);
141
		unset($conf);
226 liveuser 142
 
3 liveuser 143
		#若運行出錯
144
		if($systemd["status"]==="false"){
226 liveuser 145
 
3 liveuser 146
			#debug
147
			var_dump($systemd);
226 liveuser 148
 
3 liveuser 149
			#停止執行
150
			exit;
226 liveuser 151
 
3 liveuser 152
			}#if end
226 liveuser 153
 
3 liveuser 154
		}#if end
226 liveuser 155
 
3 liveuser 156
	#過30秒再檢查一次
157
	sleep(30);
226 liveuser 158
 
3 liveuser 159
	#下一輪
160
	continue;
226 liveuser 161
 
3 liveuser 162
	}#while end
163
 
164
?>