Bearsampp 2026.5.5
Loading...
Searching...
No Matches
ActionRestartAllServices Class Reference

Public Member Functions

 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)

Data Fields

const GAUGE_PER_SERVICE = 2

Private Member Functions

 getServiceShutdownOrder ()
 getServiceStartupOrder ()

Private Attributes

 $processed = false
 $splash

Detailed Description

Class ActionRestartAllServices Handles restarting all services with a single splash screen showing progress. Stops all services first, then starts them all.

Definition at line 15 of file class.action.restartAllServices.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

ActionRestartAllServices constructor. Initializes the restarting process, displays the splash screen, and sets up the main loop.

Parameters
array$argsCommand line arguments.

Definition at line 38 of file class.action.restartAllServices.php.

39 {
40 global $bearsamppCore, $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
41
42 // Count enabled services for progress bar
43 $enabledServicesCount = count($bearsamppBins->getServices());
44
45 // Start splash screen (2 operations per service: stop + start)
46 $this->splash = new Splash();
47 $this->splash->init(
49 self::GAUGE_PER_SERVICE * $enabledServicesCount + 1,
51 );
52
53 // Set handler for the splash screen window with 1000ms timeout
54 $bearsamppWinbinder->setHandler($this->splash->getWbWindow(), $this, 'processWindow', 1000);
55 $bearsamppWinbinder->mainLoop();
56 $bearsamppWinbinder->reset();
57 }
global $bearsamppBins
global $bearsamppLang
global $bearsamppCore
const MENU_RESTART_SERVICES
const LOADING_RESTART_SERVICES

References $bearsamppBins, $bearsamppCore, $bearsamppLang, Lang\LOADING_RESTART_SERVICES, and Lang\MENU_RESTART_SERVICES.

Member Function Documentation

◆ getServiceShutdownOrder()

getServiceShutdownOrder ( )
private

Get the optimal service shutdown order based on dependencies. Services are ordered to stop dependent services first, then core services. This is the reverse of the startup order.

Returns
array Array of service names in shutdown order

Definition at line 66 of file class.action.restartAllServices.php.

67 {
68 // Define shutdown order: dependent services first, then core services
69 // This prevents connection errors and ensures clean shutdown
70 return [
71 // Tier 1: Application services (no dependencies on other services)
72 BinMailpit::SERVICE_NAME, // Mail testing tool
73 BinMemcached::SERVICE_NAME, // Caching service
74 BinXlight::SERVICE_NAME, // FTP server
75
76 // Tier 2: Database services (web server depends on these)
77 BinPostgresql::SERVICE_NAME, // PostgreSQL database
78 BinMariadb::SERVICE_NAME, // MariaDB database
79 BinMysql::SERVICE_NAME, // MySQL database
80
81 // Tier 3: Web server (depends on databases and other services)
82 BinApache::SERVICE_NAME, // Apache web server (stopped last)
83 ];
84 }
const SERVICE_NAME

References BinApache\SERVICE_NAME, BinMailpit\SERVICE_NAME, BinMariadb\SERVICE_NAME, BinMemcached\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, and BinXlight\SERVICE_NAME.

Referenced by processWindow().

◆ getServiceStartupOrder()

getServiceStartupOrder ( )
private

Get the optimal service startup order based on dependencies. Services are ordered to start core services first, then dependent services. This is the reverse of the shutdown order.

Returns
array Array of service names in startup order

Definition at line 93 of file class.action.restartAllServices.php.

94 {
95 // Define startup order: core services first, then dependent services
96 // This ensures dependencies are available when needed
97 return [
98 // Tier 1: Web server (should start first as it's the foundation)
99 BinApache::SERVICE_NAME, // Apache web server (started first)
100
101 // Tier 2: Database services (web server may depend on these)
102 BinMysql::SERVICE_NAME, // MySQL database
103 BinMariadb::SERVICE_NAME, // MariaDB database
104 BinPostgresql::SERVICE_NAME, // PostgreSQL database
105
106 // Tier 3: Application services (no dependencies on other services)
107 BinXlight::SERVICE_NAME, // FTP server
108 BinMemcached::SERVICE_NAME, // Caching service
109 BinMailpit::SERVICE_NAME, // Mail testing tool
110 ];
111 }

References BinApache\SERVICE_NAME, BinMailpit\SERVICE_NAME, BinMariadb\SERVICE_NAME, BinMemcached\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, and BinXlight\SERVICE_NAME.

Referenced by processWindow().

◆ processWindow()

processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes the splash screen window events. Stops all services in shutdown order, then starts them in startup order with progress updates.

Parameters
resource$windowThe window resource.
int$idThe event ID.
int$ctrlThe control ID.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.

Definition at line 123 of file class.action.restartAllServices.php.

124 {
125 global $bearsamppBins, $bearsamppLang, $bearsamppWinbinder;
126
127 // Only process once
128 if ($this->processed) {
129 return;
130 }
131 $this->processed = true;
132
133 // Get all available services
134 $allServices = $bearsamppBins->getServices();
135
136 // Get optimal shutdown order
137 $shutdownOrder = $this->getServiceShutdownOrder();
138
139 // First, stop all services in optimal shutdown order
140 foreach ($shutdownOrder as $serviceName) {
141 // Check if this service exists and is enabled
142 if (!isset($allServices[$serviceName])) {
143 continue;
144 }
145
146 $service = $allServices[$serviceName];
148
149 if ($bin !== null) {
150 $name = ServiceHelper::getServiceDisplayName($bin, $service);
151
152 $this->splash->incrProgressBar();
153 $this->splash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::LOADING_STOP_SERVICE), $name));
154
155 // Stop the service
157 }
158 }
159
160 // Get optimal startup order
161 $startupOrder = $this->getServiceStartupOrder();
162
163 // Then, start all services in optimal startup order
164 foreach ($startupOrder as $serviceName) {
165 // Check if this service exists and is enabled
166 if (!isset($allServices[$serviceName])) {
167 continue;
168 }
169
170 $service = $allServices[$serviceName];
172 $syntaxCheckCmd = ServiceHelper::getSyntaxCheckCmd($serviceName);
173
174 if ($bin !== null) {
175 $name = ServiceHelper::getServiceDisplayName($bin, $service);
176
177 $this->splash->incrProgressBar();
178 $this->splash->setTextLoading(sprintf($bearsamppLang->getValue(Lang::LOADING_START_SERVICE), $name));
179
180 // Start the service
181 ServiceHelper::startService($bin, $syntaxCheckCmd, false);
182 }
183 }
184
185 // Final update
186 $this->splash->incrProgressBar();
187 $this->splash->setTextLoading($bearsamppLang->getValue(Lang::LOADING_COMPLETE));
188
189 // Close the splash screen and exit cleanly
190 $bearsamppWinbinder->destroyWindow($window);
191 $bearsamppWinbinder->reset();
192 exit(0);
193 }
const LOADING_COMPLETE
const LOADING_START_SERVICE
const LOADING_STOP_SERVICE
static getServiceDisplayName($bin, $service)
static stopService($service)
static getSyntaxCheckCmd($serviceName, $bearsamppBins=null)
static startService($bin, $syntaxCheckCmd=null, $showErrors=true)
static getBinFromServiceName($serviceName, $bearsamppBins)

References $bearsamppBins, $bearsamppLang, exit, ServiceHelper\getBinFromServiceName(), ServiceHelper\getServiceDisplayName(), getServiceShutdownOrder(), getServiceStartupOrder(), ServiceHelper\getSyntaxCheckCmd(), Lang\LOADING_COMPLETE, Lang\LOADING_START_SERVICE, Lang\LOADING_STOP_SERVICE, ServiceHelper\startService(), and ServiceHelper\stopService().

Field Documentation

◆ $processed

$processed = false
private

Definition at line 25 of file class.action.restartAllServices.php.

◆ $splash

$splash
private

Definition at line 20 of file class.action.restartAllServices.php.

◆ GAUGE_PER_SERVICE

const GAUGE_PER_SERVICE = 2

Gauge value for progress bar increments.

Definition at line 30 of file class.action.restartAllServices.php.


The documentation for this class was generated from the following file: