![]() |
Bearsampp 2025.8.29
|
Public Member Functions | |
__construct ($name) | |
create () | |
delete () | |
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 () |
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 Util\logInitClass().
|
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 Util\logTrace().
Referenced by create(), delete(), start(), status(), and stop().
create | ( | ) |
Creates the service.
Definition at line 351 of file class.win32service.php.
References $bearsamppBins, $result, callWin32Service(), Util\getAppBinsRegKey(), getBinPath(), getDisplayName(), getErrorControl(), getLatestError(), getName(), getNssm(), Util\getNssmEnvPaths(), getParams(), getStartType(), Batch\installPostgresqlService(), isInstalled(), Util\logTrace(), BinPostgresql\SERVICE_NAME, status(), and writeLog().
Referenced by reset().
delete | ( | ) |
Deletes the service.
Definition at line 453 of file class.win32service.php.
References $result, callWin32Service(), getName(), isInstalled(), Util\logTrace(), BinPostgresql\SERVICE_NAME, status(), stop(), Batch\uninstallPostgresqlService(), and writeLog().
getBinPath | ( | ) |
Gets the binary path of the service.
Definition at line 918 of file class.win32service.php.
References $binPath.
Referenced by create().
getDisplayName | ( | ) |
Gets the display name of the service.
Definition at line 898 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 1044 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 978 of file class.win32service.php.
References $errorControl.
Referenced by create().
getLatestError | ( | ) |
Gets the latest error encountered by the service.
Definition at line 1034 of file class.win32service.php.
References $latestError.
Referenced by create().
getLatestStatus | ( | ) |
Gets the latest status of the service.
Definition at line 1024 of file class.win32service.php.
References $latestStatus.
getName | ( | ) |
Gets the name of the service.
Definition at line 878 of file class.win32service.php.
References $name.
Referenced by create(), delete(), infos(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), status(), and stop().
getNssm | ( | ) |
Gets the NSSM instance associated with the service.
Definition at line 998 of file class.win32service.php.
References $nssm.
getParams | ( | ) |
Gets the parameters for the service.
Definition at line 938 of file class.win32service.php.
References $params.
Referenced by create().
getStartType | ( | ) |
Gets the start type of the service.
Definition at line 958 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.
Referenced by Vbs\getServiceInfos().
|
private |
Returns a description of the Win32 error code.
string | $code | The error code. |
Definition at line 862 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 823 of file class.win32service.php.
Referenced by getError().
infos | ( | ) |
Retrieves information about the service.
Definition at line 647 of file class.win32service.php.
References $result, getName(), getNssm(), Vbs\getServiceInfos(), and Util\logTrace().
isInstalled | ( | ) |
Checks if the service is installed.
Definition at line 697 of file class.win32service.php.
References getName(), Util\logTrace(), status(), and writeLog().
isPaused | ( | ) |
Checks if the service is paused.
Definition at line 774 of file class.win32service.php.
References getName(), Util\logTrace(), status(), and writeLog().
isPending | ( | $status | ) |
Checks if the service is in a pending state.
string | $status | The status to check. |
Definition at line 794 of file class.win32service.php.
References Util\logTrace().
Referenced by status().
isRunning | ( | ) |
Checks if the service is running.
Definition at line 738 of file class.win32service.php.
References getName(), Util\logTrace(), status(), and writeLog().
Referenced by start().
isStopped | ( | ) |
Checks if the service is stopped.
Definition at line 756 of file class.win32service.php.
References getName(), Util\logTrace(), status(), and writeLog().
Referenced by stop().
reset | ( | ) |
Resets the service by deleting and recreating it.
Definition at line 498 of file class.win32service.php.
References create().
restart | ( | ) |
Restarts the service by stopping and then starting it.
Definition at line 633 of file class.win32service.php.
setBinPath | ( | $binPath | ) |
Sets the binary path of the service.
string | $binPath | The binary path to set. |
Definition at line 928 of file class.win32service.php.
References $binPath, and Util\formatWindowsPath().
Referenced by setNssm().
setDisplayName | ( | $displayName | ) |
Sets the display name of the service.
string | $displayName | The display name to set. |
Definition at line 908 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 988 of file class.win32service.php.
References $errorControl.
setName | ( | $name | ) |
Sets the name of the service.
string | $name | The name to set. |
Definition at line 888 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 1008 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 948 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 968 of file class.win32service.php.
References $startType.
Referenced by setNssm().
start | ( | ) |
Starts the service.
Definition at line 514 of file class.win32service.php.
References $bearsamppBins, $result, callWin32Service(), BinApache\CMD_SYNTAX_CHECK, BinMariadb\CMD_SYNTAX_CHECK, BinMysql\CMD_SYNTAX_CHECK, getName(), isRunning(), Util\logDebug(), Util\logError(), Util\logInfo(), 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 Util\logTrace().
Referenced by create(), delete(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), and stop().
stop | ( | ) |
Stops the service.
Definition at line 598 of file class.win32service.php.
References $result, callWin32Service(), getName(), isStopped(), Util\logTrace(), status(), and writeLog().
|
private |
Writes a log entry.
string | $log | The log message. |
Definition at line 107 of file class.win32service.php.
References $bearsamppRoot, and Util\logDebug().
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\installServices().
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.