Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.action.service.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
15{
16 const CREATE = 'create';
17 const START = 'start';
18 const STOP = 'stop';
19 const RESTART = 'restart';
20
21 const INSTALL = 'install';
22 const REMOVE = 'remove';
23
30 public function __construct($args)
31 {
32 global $bearsamppBins;
34
35 // Reload bins
36 $bearsamppBins->reload();
37
38 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
39 $sName = $args[0];
40 $bin = null;
41 $port = 0;
42 $syntaxCheckCmd = null;
43
44 if ($sName == BinMailpit::SERVICE_NAME) {
45 $bin = $bearsamppBins->getMailpit();
46 $port = $bin->getSmtpPort();
47 } elseif ($sName == BinMemcached::SERVICE_NAME) {
48 $bin = $bearsamppBins->getMemcached();
49 $port = $bin->getPort();
50 } elseif ($sName == BinApache::SERVICE_NAME) {
51 $bin = $bearsamppBins->getApache();
52 $port = $bin->getPort();
53 $syntaxCheckCmd = BinApache::CMD_SYNTAX_CHECK;
54 } elseif ($sName == BinMysql::SERVICE_NAME) {
55 $bin = $bearsamppBins->getMysql();
56 $port = $bin->getPort();
57 $syntaxCheckCmd = BinMysql::CMD_SYNTAX_CHECK;
58 } elseif ($sName == BinMariadb::SERVICE_NAME) {
59 $bin = $bearsamppBins->getMariadb();
60 $port = $bin->getPort();
61 $syntaxCheckCmd = BinMariadb::CMD_SYNTAX_CHECK;
62 } elseif ($sName == BinPostgresql::SERVICE_NAME) {
63 $bin = $bearsamppBins->getPostgresql();
64 $port = $bin->getPort();
65 } elseif ($sName == BinXlight::SERVICE_NAME) {
66 $bin = $bearsamppBins->getXlight();
67 $port = $bin->getPort();
68 }
69
70 $name = $bin->getName();
71 $service = $bin->getService();
72
73 if (!empty($service) && $service instanceof Win32Service) {
74 if ($args[1] == self::CREATE) {
75 $this->create($service);
76 } elseif ($args[1] == self::START) {
77 $this->start($bin, $syntaxCheckCmd);
78 } elseif ($args[1] == self::STOP) {
79 $this->stop($service);
80 } elseif ($args[1] == self::RESTART) {
81 $this->restart($bin, $syntaxCheckCmd);
82 } elseif ($args[1] == self::INSTALL) {
83 if (!empty($port)) {
84 $this->install($bin, $port, $syntaxCheckCmd);
85 }
86 } elseif ($args[1] == self::REMOVE) {
87 $this->remove($service, $name);
88 }
89 }
90 }
91
93 }
94
100 private function create($service)
101 {
102 $service->create();
103 }
104
111 private function start($bin, $syntaxCheckCmd)
112 {
113 // Update loading screen to show which service is starting
114 Util::updateLoadingText('Starting ' . $bin->getName() . '...');
115
116 ServiceHelper::startService($bin, $syntaxCheckCmd, true);
117 }
118
124 private function stop($service)
125 {
126 // Update loading screen to show which service is stopping
127 Util::updateLoadingText('Stopping ' . $service->getName() . '...');
128
129 $service->stop();
130 }
131
138 private function restart($bin, $syntaxCheckCmd)
139 {
140 // Update loading screen to show service is restarting
141 Util::updateLoadingText('Restarting ' . $bin->getName() . '...');
142
143 if ($bin->getService()->stop()) {
144 $this->start($bin, $syntaxCheckCmd);
145 }
146 }
147
155 private function install($bin, $port, $syntaxCheckCmd)
156 {
157 ServiceHelper::installService($bin, $port, $syntaxCheckCmd, true);
158 }
159
166 private function remove($service, $name)
167 {
168 ServiceHelper::removeService($service, $name);
169 }
170}
171
global $bearsamppBins
$port
start($bin, $syntaxCheckCmd)
restart($bin, $syntaxCheckCmd)
install($bin, $port, $syntaxCheckCmd)
const CMD_SYNTAX_CHECK
const SERVICE_NAME
const CMD_SYNTAX_CHECK
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)
static startService($bin, $syntaxCheckCmd=null, $showWindow=false)
static startLoading()
static stopLoading()
static updateLoadingText($text)