![]() |
Bearsampp 2026.5.5
|
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 | 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() |
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 96 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 138 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 352 of file class.win32service.php.
References $bearsamppBins, $result, callWin32Service(), Util\getAppBinsRegKey(), getBinPath(), getDisplayName(), getErrorControl(), getLatestError(), getName(), getNssm(), Nssm\getNssmEnvPaths(), getParams(), getStartType(), Batch\installPostgresqlService(), isInstalled(), BinPostgresql\SERVICE_NAME, status(), Log\trace(), and writeLog().
Referenced by reset().
| delete | ( | ) |
Deletes the service.
Definition at line 464 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 1227 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 668 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 1037 of file class.win32service.php.
References $binPath.
| getDisplayName | ( | ) |
Gets the display name of the service.
Definition at line 1017 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 1163 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 1097 of file class.win32service.php.
References $errorControl.
Referenced by create().
| getLatestError | ( | ) |
Gets the latest error encountered by the service.
Definition at line 1153 of file class.win32service.php.
References $latestError.
Referenced by create().
| getLatestStatus | ( | ) |
Gets the latest status of the service.
Definition at line 1143 of file class.win32service.php.
References $latestStatus.
| getName | ( | ) |
Gets the name of the service.
Definition at line 997 of file class.win32service.php.
References $name.
Referenced by create(), delete(), ensureReset(), fastServiceCheck(), infos(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), status(), stop(), and waitForServiceDeletion().
| getNssm | ( | ) |
Gets the NSSM instance associated with the service.
Definition at line 1117 of file class.win32service.php.
References $nssm.
| getParams | ( | ) |
Gets the parameters for the service.
Definition at line 1057 of file class.win32service.php.
References $params.
Referenced by create().
| getStartType | ( | ) |
Gets the start type of the service.
Definition at line 1077 of file class.win32service.php.
References $startType.
Referenced by create().
|
static |
Returns an array of VBS keys used for service information.
Definition at line 118 of file class.win32service.php.
|
private |
Returns a description of the Win32 error code.
| string | $code | The error code. |
Definition at line 981 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 942 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 747 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 816 of file class.win32service.php.
References getName(), status(), Log\trace(), and writeLog().
| isPaused | ( | ) |
Checks if the service is paused.
Definition at line 893 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 913 of file class.win32service.php.
References Log\trace().
Referenced by status().
| isRunning | ( | ) |
Checks if the service is running.
Definition at line 857 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 875 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 515 of file class.win32service.php.
References create().
| restart | ( | ) |
Restarts the service by stopping and then starting it.
Definition at line 653 of file class.win32service.php.
| setBinPath | ( | $binPath | ) |
Sets the binary path of the service.
| string | $binPath | The binary path to set. |
Definition at line 1047 of file class.win32service.php.
References $binPath, and UtilPath\formatWindowsPath().
Referenced by setNssm().
| setDisplayName | ( | $displayName | ) |
Sets the display name of the service.
| string | $displayName | The display name to set. |
Definition at line 1027 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 1107 of file class.win32service.php.
References $errorControl.
| setName | ( | $name | ) |
Sets the name of the service.
| string | $name | The name to set. |
Definition at line 1007 of file class.win32service.php.
References $name.
| setNssm | ( | $nssm | ) |
Sets the NSSM instance associated with the service.
Definition at line 1127 of file class.win32service.php.
References $nssm, setBinPath(), setDisplayName(), setParams(), and setStartType().
| setParams | ( | $params | ) |
| setStartType | ( | $startType | ) |
Sets the start type of the service.
| string | $startType | The start type to set. |
Definition at line 1087 of file class.win32service.php.
References $startType.
Referenced by setNssm().
| start | ( | ) |
Starts the service.
Definition at line 531 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(), 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 251 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 618 of file class.win32service.php.
References $result, callWin32Service(), getName(), 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 1191 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 107 of file class.win32service.php.
References $bearsamppRoot, and Log\debug().
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 89 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().
|
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 SLEEP_TIME = 500000 |
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 VBS_STATE = 'State' |
Definition at line 75 of file class.win32service.php.
| 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.
| 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.