![]() |
Bearsampp 2026.7.11
|
Public Member Functions | |
| __construct ($name) | |
| create () | |
| delete () | |
| ensureReset () | |
| fastServiceCheck () | |
| getBinPath () | |
| getDisplayName () | |
| getError () | |
| getErrorControl () | |
| getLatestError () | |
| getLatestStatus () | |
| getName () | |
| getNssm () | |
| getParams () | |
| getStartType () | |
| infos () | |
| isInstalled () | |
| isPaused () | |
| isPending ($status) | |
| isRunning () | |
| isStopped () | |
| reset () | |
| restart () | |
| setBinPath ($binPath) | |
| setDisplayName ($displayName) | |
| setErrorControl ($errorControl) | |
| setName ($name) | |
| setNssm ($nssm) | |
| setParams ($params) | |
| setStartType ($startType) | |
| start () | |
| status ($timeout=true) | |
| stop () | |
| waitForServiceDeletion ($maxWaitTime=30) | |
Static Public Member Functions | |
| static | getServices ($forceRefresh=false) |
| static | getVbsKeys () |
Private Member Functions | |
| callWin32Service ($function, $param, $checkError=false) | |
| getWin32ErrorCodeDesc ($code) | |
| getWin32ServiceStatusDesc ($status) | |
| writeLog ($log) | |
Private Attributes | |
| $binPath | |
| $displayName | |
| $errorControl | |
| $latestError | |
| $latestStatus | |
| $name | |
| $nssm | |
| $params | |
| $startType | |
Static Private Attributes | |
| static | $loggedFunctions = array() |
| static | $serviceListCache = null |
Class Win32Service
This class provides an interface to manage Windows services. It includes methods to create, delete, start, stop, and query the status of services. It also handles logging and error reporting for service operations.
Definition at line 17 of file class.win32service.php.
| __construct | ( | $name | ) |
Constructor for the Win32Service class.
| string | $name | The name of the service. |
Definition at line 99 of file class.win32service.php.
References $name, and Log\initClass().
|
private |
Calls a Win32 service function.
| string | $function | The function name. |
| mixed | $param | The parameter to pass to the function. |
| bool | $checkError | Whether to check for errors. |
Definition at line 170 of file class.win32service.php.
References $result, and Log\trace().
Referenced by create(), delete(), start(), status(), and stop().
| create | ( | ) |
Creates the service.
Definition at line 382 of file class.win32service.php.
References $bearsamppBins, $result, callWin32Service(), getBinPath(), getDisplayName(), getErrorControl(), getLatestError(), getName(), getNssm(), Path\getNssmEnvPaths(), getParams(), getStartType(), Batch\installPostgresqlService(), isInstalled(), Root\loadTools(), BinPostgresql\SERVICE_NAME, status(), Log\trace(), and writeLog().
Referenced by reset().
| delete | ( | ) |
Deletes the service.
Definition at line 502 of file class.win32service.php.
References $result, callWin32Service(), getBinPath(), getName(), getNssm(), isInstalled(), Win32Ps\killBins(), BinPostgresql\SERVICE_NAME, status(), stop(), Log\trace(), Batch\uninstallPostgresqlService(), and writeLog().
| ensureReset | ( | ) |
Ensures the service is properly reset (deleted and verified deleted). This is more robust than just calling delete() as it waits for confirmation.
Definition at line 1281 of file class.win32service.php.
References getName(), isRunning(), stop(), Log\trace(), and waitForServiceDeletion().
| fastServiceCheck | ( | ) |
Fast service check using sc.exe (Windows Service Control utility). This is much faster than WMI/VBS queries and less prone to hanging.
Definition at line 722 of file class.win32service.php.
References CommandRunner\execCombined(), getName(), and Log\trace().
Referenced by infos().
| getBinPath | ( | ) |
Gets the binary path of the service.
Definition at line 1091 of file class.win32service.php.
References $binPath.
Referenced by create(), and delete().
| getDisplayName | ( | ) |
Gets the display name of the service.
Definition at line 1071 of file class.win32service.php.
References $displayName.
Referenced by create().
| getError | ( | ) |
Gets a detailed error message for the latest error encountered by the service.
Definition at line 1217 of file class.win32service.php.
References $bearsamppLang, Lang\ERROR, getWin32ErrorCodeDesc(), getWin32ServiceStatusDesc(), and Lang\STATUS.
| getErrorControl | ( | ) |
Gets the error control setting of the service.
Definition at line 1151 of file class.win32service.php.
References $errorControl.
Referenced by create().
| getLatestError | ( | ) |
Gets the latest error encountered by the service.
Definition at line 1207 of file class.win32service.php.
References $latestError.
Referenced by create().
| getLatestStatus | ( | ) |
Gets the latest status of the service.
Definition at line 1197 of file class.win32service.php.
References $latestStatus.
| getName | ( | ) |
Gets the name of the service.
Definition at line 1051 of file class.win32service.php.
References $name.
Referenced by create(), delete(), ensureReset(), fastServiceCheck(), infos(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), status(), stop(), and waitForServiceDeletion().
| getNssm | ( | ) |
| getParams | ( | ) |
Gets the parameters for the service.
Definition at line 1111 of file class.win32service.php.
References $params.
Referenced by create().
|
static |
Retrieves all Windows services. Use $forceRefresh to ignore the cache.
| bool | $forceRefresh | Whether to force a refresh of the service list. |
Definition at line 139 of file class.win32service.php.
References Win32Native\listServices(), and Log\trace().
Referenced by ActionStartup\checkApacheServiceWithTimeout(), ActionStartup\checkMySQLServiceWithTimeout(), and ActionStartup\installServicesSequential().
| getStartType | ( | ) |
Gets the start type of the service.
Definition at line 1131 of file class.win32service.php.
References $startType.
Referenced by create().
|
static |
Returns an array of VBS keys used for service information.
Definition at line 121 of file class.win32service.php.
|
private |
Returns a description of the Win32 error code.
| string | $code | The error code. |
Definition at line 1035 of file class.win32service.php.
Referenced by getError().
|
private |
Returns a description of the Win32 service status.
| string | $status | The status code. |
Definition at line 996 of file class.win32service.php.
Referenced by getError().
| infos | ( | ) |
Retrieves information about the service. Performance optimization: Uses fast sc.exe check first, falls back to VBS if needed.
Definition at line 801 of file class.win32service.php.
References $result, Log\debug(), fastServiceCheck(), getName(), getNssm(), Win32Native\getServiceInfo(), and Log\trace().
| isInstalled | ( | ) |
Checks if the service is installed.
Definition at line 870 of file class.win32service.php.
References getName(), status(), Log\trace(), and writeLog().
Referenced by create(), and delete().
| isPaused | ( | ) |
Checks if the service is paused.
Definition at line 947 of file class.win32service.php.
References getName(), status(), Log\trace(), and writeLog().
| isPending | ( | $status | ) |
Checks if the service is in a pending state.
| string | $status | The status to check. |
Definition at line 967 of file class.win32service.php.
References Log\trace().
Referenced by start(), status(), and stop().
| isRunning | ( | ) |
Checks if the service is running.
Definition at line 911 of file class.win32service.php.
References getName(), status(), Log\trace(), and writeLog().
Referenced by ensureReset(), and start().
| isStopped | ( | ) |
Checks if the service is stopped.
Definition at line 929 of file class.win32service.php.
References getName(), status(), Log\trace(), and writeLog().
Referenced by stop().
| reset | ( | ) |
Resets the service by deleting and recreating it.
Definition at line 553 of file class.win32service.php.
References create().
| restart | ( | ) |
Restarts the service by stopping and then starting it.
Definition at line 707 of file class.win32service.php.
References start(), and stop().
| setBinPath | ( | $binPath | ) |
Sets the binary path of the service.
| string | $binPath | The binary path to set. |
Definition at line 1101 of file class.win32service.php.
References $binPath, and Path\formatWindowsPath().
Referenced by setNssm().
| setDisplayName | ( | $displayName | ) |
Sets the display name of the service.
| string | $displayName | The display name to set. |
Definition at line 1081 of file class.win32service.php.
References $displayName.
Referenced by setNssm().
| setErrorControl | ( | $errorControl | ) |
Sets the error control setting of the service.
| string | $errorControl | The error control setting to set. |
Definition at line 1161 of file class.win32service.php.
References $errorControl.
| setName | ( | $name | ) |
Sets the name of the service.
| string | $name | The name to set. |
Definition at line 1061 of file class.win32service.php.
References $name.
| setNssm | ( | $nssm | ) |
Sets the NSSM instance associated with the service.
| Nssm | $nssm | The NSSM instance to set. |
Definition at line 1181 of file class.win32service.php.
References $nssm, setBinPath(), setDisplayName(), setParams(), and setStartType().
| setParams | ( | $params | ) |
Sets the parameters for the service.
| string | $params | The parameters to set. |
Definition at line 1121 of file class.win32service.php.
References $params.
Referenced by setNssm().
| setStartType | ( | $startType | ) |
Sets the start type of the service.
| string | $startType | The start type to set. |
Definition at line 1141 of file class.win32service.php.
References $startType.
Referenced by setNssm().
| start | ( | ) |
Starts the service.
Definition at line 569 of file class.win32service.php.
References $bearsamppBins, $result, callWin32Service(), BinApache\CMD_SYNTAX_CHECK, BinMariadb\CMD_SYNTAX_CHECK, BinMysql\CMD_SYNTAX_CHECK, Log\debug(), Log\error(), getName(), Log\info(), isPending(), isRunning(), BinApache\SERVICE_NAME, BinMailpit\SERVICE_NAME, BinMariadb\SERVICE_NAME, BinMemcached\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, BinXlight\SERVICE_NAME, and status().
Referenced by restart().
| status | ( | $timeout = true | ) |
Queries the status of the service.
| bool | $timeout | Whether to use a timeout. |
Definition at line 283 of file class.win32service.php.
References $latestStatus, callWin32Service(), getName(), isPending(), and Log\trace().
Referenced by create(), delete(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), stop(), and waitForServiceDeletion().
| stop | ( | ) |
Stops the service.
Definition at line 664 of file class.win32service.php.
References $result, callWin32Service(), Log\error(), getName(), isPending(), isStopped(), status(), Log\trace(), and writeLog().
Referenced by delete(), ensureReset(), and restart().
| waitForServiceDeletion | ( | $maxWaitTime = 30 | ) |
Waits for the service to be completely removed from the SCM database. This is important after deletion because the SCM marks services for deletion but they remain visible briefly, preventing re-creation.
| int | $maxWaitTime | Maximum time to wait in seconds (default 30) |
Definition at line 1245 of file class.win32service.php.
References getName(), status(), and Log\trace().
Referenced by ensureReset().
|
private |
Writes a log entry.
| string | $log | The log message. |
Definition at line 110 of file class.win32service.php.
References $bearsamppRoot, Log\debug(), and Path\getServicesLogFilePath().
Referenced by create(), delete(), isInstalled(), isPaused(), isRunning(), isStopped(), and stop().
|
private |
Definition at line 79 of file class.win32service.php.
Referenced by getBinPath(), and setBinPath().
|
private |
Definition at line 78 of file class.win32service.php.
Referenced by getDisplayName(), and setDisplayName().
|
private |
Definition at line 82 of file class.win32service.php.
Referenced by getErrorControl(), and setErrorControl().
|
private |
Definition at line 86 of file class.win32service.php.
Referenced by getLatestError().
|
private |
Definition at line 85 of file class.win32service.php.
Referenced by getLatestStatus(), and status().
|
staticprivate |
Definition at line 92 of file class.win32service.php.
|
private |
Definition at line 77 of file class.win32service.php.
Referenced by __construct(), getName(), and setName().
|
private |
Definition at line 83 of file class.win32service.php.
|
private |
Definition at line 80 of file class.win32service.php.
Referenced by getParams(), and setParams().
|
staticprivate |
Definition at line 89 of file class.win32service.php.
|
private |
Definition at line 81 of file class.win32service.php.
Referenced by getStartType(), and setStartType().
| const PENDING_TIMEOUT = 20 |
Definition at line 68 of file class.win32service.php.
| const SERVER_ERROR_IGNORE = '0' |
Definition at line 61 of file class.win32service.php.
| const SERVER_ERROR_NORMAL = '1' |
Definition at line 62 of file class.win32service.php.
Referenced by BinMariadb\reload(), BinMysql\reload(), and BinPostgresql\reload().
| const SERVICE_AUTO_START = '2' |
Definition at line 64 of file class.win32service.php.
| const SERVICE_DEMAND_START = '3' |
Definition at line 65 of file class.win32service.php.
Referenced by BinMariadb\reload(), BinMysql\reload(), and BinPostgresql\reload().
| const SERVICE_DISABLED = '4' |
Definition at line 66 of file class.win32service.php.
| const SERVICE_STATE = 'State' |
Definition at line 75 of file class.win32service.php.
Referenced by ActionStartup\prepareService().
| const SLEEP_TIME = 100000 |
Definition at line 69 of file class.win32service.php.
| const VBS_DESCRIPTION = 'Description' |
Definition at line 73 of file class.win32service.php.
| const VBS_DISPLAY_NAME = 'DisplayName' |
Definition at line 72 of file class.win32service.php.
| const VBS_NAME = 'Name' |
Definition at line 71 of file class.win32service.php.
| const VBS_PATH_NAME = 'PathName' |
Definition at line 74 of file class.win32service.php.
Referenced by Nssm\infos(), and ActionStartup\prepareService().
| const WIN32_ERROR_ACCESS_DENIED = '5' |
Definition at line 30 of file class.win32service.php.
| const WIN32_ERROR_CIRCULAR_DEPENDENCY = '423' |
Definition at line 31 of file class.win32service.php.
| const WIN32_ERROR_DATABASE_DOES_NOT_EXIST = '429' |
Definition at line 32 of file class.win32service.php.
| const WIN32_ERROR_DEPENDENT_SERVICES_RUNNING = '41B' |
Definition at line 33 of file class.win32service.php.
| const WIN32_ERROR_DUPLICATE_SERVICE_NAME = '436' |
Definition at line 34 of file class.win32service.php.
| const WIN32_ERROR_FAILED_SERVICE_CONTROLLER_CONNECT = '427' |
Definition at line 35 of file class.win32service.php.
| const WIN32_ERROR_INSUFFICIENT_BUFFER = '7A' |
Definition at line 36 of file class.win32service.php.
| const WIN32_ERROR_INVALID_DATA = 'D' |
Definition at line 37 of file class.win32service.php.
| const WIN32_ERROR_INVALID_HANDLE = '6' |
Definition at line 38 of file class.win32service.php.
| const WIN32_ERROR_INVALID_LEVEL = '7C' |
Definition at line 39 of file class.win32service.php.
| const WIN32_ERROR_INVALID_NAME = '7B' |
Definition at line 40 of file class.win32service.php.
| const WIN32_ERROR_INVALID_PARAMETER = '57' |
Definition at line 41 of file class.win32service.php.
| const WIN32_ERROR_INVALID_SERVICE_ACCOUNT = '421' |
Definition at line 42 of file class.win32service.php.
| const WIN32_ERROR_INVALID_SERVICE_CONTROL = '41C' |
Definition at line 43 of file class.win32service.php.
| const WIN32_ERROR_PATH_NOT_FOUND = '3' |
Definition at line 44 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_ALREADY_RUNNING = '420' |
Definition at line 45 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_CANNOT_ACCEPT_CTRL = '425' |
Definition at line 46 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_DATABASE_LOCKED = '41F' |
Definition at line 47 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_DEPENDENCY_DELETED = '433' |
Definition at line 48 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_DEPENDENCY_FAIL = '42C' |
Definition at line 49 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_DISABLED = '422' |
Definition at line 50 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_DOES_NOT_EXIST = '424' |
Definition at line 51 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_EXISTS = '431' |
Definition at line 52 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_LOGON_FAILED = '42D' |
Definition at line 53 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_MARKED_FOR_DELETE = '430' |
Definition at line 54 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_NO_THREAD = '41E' |
Definition at line 55 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_NOT_ACTIVE = '426' |
Definition at line 56 of file class.win32service.php.
| const WIN32_ERROR_SERVICE_REQUEST_TIMEOUT = '41D' |
Definition at line 57 of file class.win32service.php.
| const WIN32_ERROR_SHUTDOWN_IN_PROGRESS = '45B' |
Definition at line 58 of file class.win32service.php.
| const WIN32_NO_ERROR = '0' |
Definition at line 59 of file class.win32service.php.
| const WIN32_SERVICE_CONTINUE_PENDING = '5' |
Definition at line 20 of file class.win32service.php.
| const WIN32_SERVICE_NA = '0' |
Definition at line 27 of file class.win32service.php.
| const WIN32_SERVICE_PAUSE_PENDING = '6' |
Definition at line 21 of file class.win32service.php.
| const WIN32_SERVICE_PAUSED = '7' |
Definition at line 22 of file class.win32service.php.
| const WIN32_SERVICE_RUNNING = '4' |
Definition at line 23 of file class.win32service.php.
Referenced by ActionStartup\prepareService().
| const WIN32_SERVICE_START_PENDING = '2' |
Definition at line 24 of file class.win32service.php.
| const WIN32_SERVICE_STOP_PENDING = '3' |
Definition at line 25 of file class.win32service.php.
| const WIN32_SERVICE_STOPPED = '1' |
Definition at line 26 of file class.win32service.php.