2024.8.23
|
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 | |
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 16 of file class.win32service.php.
Win32Service::__construct | ( | $name | ) |
Constructor for the Win32Service class.
string | $name | The name of the service. |
Definition at line 92 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 134 of file class.win32service.php.
References $result.
Referenced by create(), delete(), start(), status(), and stop().
Win32Service::create | ( | ) |
Creates the service.
Definition at line 187 of file class.win32service.php.
References $bearsamppBins, callWin32Service(), Util\getAppBinsRegKey(), getBinPath(), getDisplayName(), getErrorControl(), getName(), getNssm(), Util\getNssmEnvPaths(), getParams(), getStartType(), Batch\installFilezillaService(), Batch\installPostgresqlService(), isInstalled(), SERVER_ERROR_NORMAL, SERVICE_DEMAND_START, BinFilezilla\SERVICE_NAME, BinPostgresql\SERVICE_NAME, status(), WIN32_NO_ERROR, and writeLog().
Referenced by reset().
Win32Service::delete | ( | ) |
Deletes the service.
Definition at line 250 of file class.win32service.php.
References callWin32Service(), getName(), isInstalled(), BinFilezilla\SERVICE_NAME, BinPostgresql\SERVICE_NAME, status(), stop(), Batch\uninstallFilezillaService(), Batch\uninstallPostgresqlService(), WIN32_NO_ERROR, and writeLog().
Win32Service::getBinPath | ( | ) |
Gets the binary path of the service.
Definition at line 609 of file class.win32service.php.
References $binPath.
Referenced by create().
Win32Service::getDisplayName | ( | ) |
Gets the display name of the service.
Definition at line 589 of file class.win32service.php.
References $displayName.
Referenced by create().
Win32Service::getError | ( | ) |
Gets a detailed error message for the latest error encountered by the service.
Definition at line 735 of file class.win32service.php.
References $bearsamppLang, Lang\ERROR, getWin32ErrorCodeDesc(), getWin32ServiceStatusDesc(), and Lang\STATUS.
Win32Service::getErrorControl | ( | ) |
Gets the error control setting of the service.
Definition at line 669 of file class.win32service.php.
References $errorControl.
Referenced by create().
Win32Service::getLatestError | ( | ) |
Gets the latest error encountered by the service.
Definition at line 725 of file class.win32service.php.
References $latestError.
Win32Service::getLatestStatus | ( | ) |
Gets the latest status of the service.
Definition at line 715 of file class.win32service.php.
References $latestStatus.
Win32Service::getName | ( | ) |
Gets the name of the service.
Definition at line 569 of file class.win32service.php.
References $name.
Referenced by create(), delete(), infos(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), status(), and stop().
Win32Service::getNssm | ( | ) |
Win32Service::getParams | ( | ) |
Gets the parameters for the service.
Definition at line 629 of file class.win32service.php.
References $params.
Referenced by create().
Win32Service::getStartType | ( | ) |
Gets the start type of the service.
Definition at line 649 of file class.win32service.php.
References $startType.
Referenced by create().
|
static |
Returns an array of VBS keys used for service information.
Definition at line 114 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 553 of file class.win32service.php.
References WIN32_ERROR_ACCESS_DENIED.
Referenced by getError().
|
private |
Returns a description of the Win32 service status.
string | $status | The status code. |
Definition at line 505 of file class.win32service.php.
References WIN32_SERVICE_CONTINUE_PENDING, WIN32_SERVICE_NA, WIN32_SERVICE_PAUSE_PENDING, WIN32_SERVICE_PAUSED, WIN32_SERVICE_RUNNING, WIN32_SERVICE_START_PENDING, WIN32_SERVICE_STOP_PENDING, and WIN32_SERVICE_STOPPED.
Referenced by getError().
Win32Service::infos | ( | ) |
Retrieves information about the service.
Definition at line 424 of file class.win32service.php.
References getName(), getNssm(), and Vbs\getServiceInfos().
Win32Service::isInstalled | ( | ) |
Checks if the service is installed.
Definition at line 438 of file class.win32service.php.
References getName(), status(), WIN32_SERVICE_NA, and writeLog().
Referenced by create(), and delete().
Win32Service::isPaused | ( | ) |
Checks if the service is paused.
Definition at line 477 of file class.win32service.php.
References getName(), status(), WIN32_SERVICE_PAUSED, and writeLog().
Win32Service::isPending | ( | $status | ) |
Checks if the service is in a pending state.
string | $status | The status to check. |
Definition at line 492 of file class.win32service.php.
References WIN32_SERVICE_PAUSE_PENDING.
Referenced by status().
Win32Service::isRunning | ( | ) |
Checks if the service is running.
Definition at line 451 of file class.win32service.php.
References getName(), status(), WIN32_SERVICE_RUNNING, and writeLog().
Referenced by start().
Win32Service::isStopped | ( | ) |
Checks if the service is stopped.
Definition at line 464 of file class.win32service.php.
References getName(), status(), WIN32_SERVICE_STOPPED, and writeLog().
Referenced by stop().
Win32Service::reset | ( | ) |
Resets the service by deleting and recreating it.
Definition at line 285 of file class.win32service.php.
References create().
Win32Service::restart | ( | ) |
Restarts the service by stopping and then starting it.
Definition at line 410 of file class.win32service.php.
Win32Service::setBinPath | ( | $binPath | ) |
Sets the binary path of the service.
string | $binPath | The binary path to set. |
Definition at line 619 of file class.win32service.php.
References $binPath, and Util\formatWindowsPath().
Referenced by setNssm().
Win32Service::setDisplayName | ( | $displayName | ) |
Sets the display name of the service.
string | $displayName | The display name to set. |
Definition at line 599 of file class.win32service.php.
References $displayName.
Referenced by setNssm().
Win32Service::setErrorControl | ( | $errorControl | ) |
Sets the error control setting of the service.
string | $errorControl | The error control setting to set. |
Definition at line 679 of file class.win32service.php.
References $errorControl.
Win32Service::setName | ( | $name | ) |
Sets the name of the service.
string | $name | The name to set. |
Definition at line 579 of file class.win32service.php.
References $name.
Win32Service::setNssm | ( | $nssm | ) |
Sets the NSSM instance associated with the service.
Nssm | $nssm | The NSSM instance to set. |
Definition at line 699 of file class.win32service.php.
References $nssm, setBinPath(), setDisplayName(), setParams(), and setStartType().
Win32Service::setParams | ( | $params | ) |
Sets the parameters for the service.
string | $params | The parameters to set. |
Definition at line 639 of file class.win32service.php.
References $params.
Referenced by setNssm().
Win32Service::setStartType | ( | $startType | ) |
Sets the start type of the service.
string | $startType | The start type to set. |
Definition at line 659 of file class.win32service.php.
References $startType.
Referenced by setNssm().
Win32Service::start | ( | ) |
Starts the service.
Definition at line 301 of file class.win32service.php.
References $bearsamppBins, callWin32Service(), BinApache\CMD_SYNTAX_CHECK, BinMariadb\CMD_SYNTAX_CHECK, BinMysql\CMD_SYNTAX_CHECK, getName(), isRunning(), Util\logDebug(), Util\logError(), Util\logInfo(), BinApache\SERVICE_NAME, BinFilezilla\SERVICE_NAME, BinMailhog\SERVICE_NAME, BinMailpit\SERVICE_NAME, BinMariadb\SERVICE_NAME, BinMemcached\SERVICE_NAME, BinMysql\SERVICE_NAME, BinPostgresql\SERVICE_NAME, BinXlight\SERVICE_NAME, status(), and WIN32_NO_ERROR.
Referenced by restart().
Win32Service::status | ( | $timeout = true | ) |
Queries the status of the service.
bool | $timeout | Whether to use a timeout. |
Definition at line 154 of file class.win32service.php.
References $latestStatus, callWin32Service(), getName(), isPending(), PENDING_TIMEOUT, and WIN32_SERVICE_NA.
Referenced by create(), delete(), isInstalled(), isPaused(), isRunning(), isStopped(), start(), and stop().
Win32Service::stop | ( | ) |
Stops the service.
Definition at line 388 of file class.win32service.php.
References callWin32Service(), getName(), isStopped(), status(), WIN32_NO_ERROR, and writeLog().
Referenced by delete(), and restart().
|
private |
Writes a log entry.
string | $log | The log message. |
Definition at line 103 of file class.win32service.php.
References $bearsamppRoot, and Util\logDebug().
Referenced by create(), delete(), isInstalled(), isPaused(), isRunning(), isStopped(), and stop().
|
private |
Definition at line 78 of file class.win32service.php.
Referenced by getBinPath(), and setBinPath().
|
private |
Definition at line 77 of file class.win32service.php.
Referenced by getDisplayName(), and setDisplayName().
|
private |
Definition at line 81 of file class.win32service.php.
Referenced by getErrorControl(), and setErrorControl().
|
private |
Definition at line 85 of file class.win32service.php.
Referenced by getLatestError().
|
private |
Definition at line 84 of file class.win32service.php.
Referenced by getLatestStatus(), and status().
|
private |
Definition at line 76 of file class.win32service.php.
Referenced by __construct(), getName(), and setName().
|
private |
Definition at line 82 of file class.win32service.php.
|
private |
Definition at line 79 of file class.win32service.php.
Referenced by getParams(), and setParams().
|
private |
Definition at line 80 of file class.win32service.php.
Referenced by getStartType(), and setStartType().
const Win32Service::PENDING_TIMEOUT = 20 |
Definition at line 67 of file class.win32service.php.
Referenced by status().
const Win32Service::SERVER_ERROR_IGNORE = '0' |
Definition at line 60 of file class.win32service.php.
const Win32Service::SERVER_ERROR_NORMAL = '1' |
Definition at line 61 of file class.win32service.php.
Referenced by create(), BinFilezilla\reload(), BinMariadb\reload(), BinMysql\reload(), and BinPostgresql\reload().
const Win32Service::SERVICE_AUTO_START = '2' |
Definition at line 63 of file class.win32service.php.
const Win32Service::SERVICE_DEMAND_START = '3' |
Definition at line 64 of file class.win32service.php.
Referenced by create(), BinFilezilla\reload(), BinMariadb\reload(), BinMysql\reload(), and BinPostgresql\reload().
const Win32Service::SERVICE_DISABLED = '4' |
Definition at line 65 of file class.win32service.php.
const Win32Service::SLEEP_TIME = 500000 |
Definition at line 68 of file class.win32service.php.
const Win32Service::VBS_DESCRIPTION = 'Description' |
Definition at line 72 of file class.win32service.php.
const Win32Service::VBS_DISPLAY_NAME = 'DisplayName' |
Definition at line 71 of file class.win32service.php.
const Win32Service::VBS_NAME = 'Name' |
Definition at line 70 of file class.win32service.php.
const Win32Service::VBS_PATH_NAME = 'PathName' |
Definition at line 73 of file class.win32service.php.
Referenced by Nssm\infos(), and ActionStartup\installServices().
const Win32Service::VBS_STATE = 'State' |
Definition at line 74 of file class.win32service.php.
const Win32Service::WIN32_ERROR_ACCESS_DENIED = '5' |
Definition at line 29 of file class.win32service.php.
Referenced by getWin32ErrorCodeDesc().
const Win32Service::WIN32_ERROR_CIRCULAR_DEPENDENCY = '423' |
Definition at line 30 of file class.win32service.php.
const Win32Service::WIN32_ERROR_DATABASE_DOES_NOT_EXIST = '429' |
Definition at line 31 of file class.win32service.php.
const Win32Service::WIN32_ERROR_DEPENDENT_SERVICES_RUNNING = '41B' |
Definition at line 32 of file class.win32service.php.
const Win32Service::WIN32_ERROR_DUPLICATE_SERVICE_NAME = '436' |
Definition at line 33 of file class.win32service.php.
const Win32Service::WIN32_ERROR_FAILED_SERVICE_CONTROLLER_CONNECT = '427' |
Definition at line 34 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INSUFFICIENT_BUFFER = '7A' |
Definition at line 35 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_DATA = 'D' |
Definition at line 36 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_HANDLE = '6' |
Definition at line 37 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_LEVEL = '7C' |
Definition at line 38 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_NAME = '7B' |
Definition at line 39 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_PARAMETER = '57' |
Definition at line 40 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_SERVICE_ACCOUNT = '421' |
Definition at line 41 of file class.win32service.php.
const Win32Service::WIN32_ERROR_INVALID_SERVICE_CONTROL = '41C' |
Definition at line 42 of file class.win32service.php.
const Win32Service::WIN32_ERROR_PATH_NOT_FOUND = '3' |
Definition at line 43 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_ALREADY_RUNNING = '420' |
Definition at line 44 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_CANNOT_ACCEPT_CTRL = '425' |
Definition at line 45 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_DATABASE_LOCKED = '41F' |
Definition at line 46 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_DEPENDENCY_DELETED = '433' |
Definition at line 47 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_DEPENDENCY_FAIL = '42C' |
Definition at line 48 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_DISABLED = '422' |
Definition at line 49 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_DOES_NOT_EXIST = '424' |
Definition at line 50 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_EXISTS = '431' |
Definition at line 51 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_LOGON_FAILED = '42D' |
Definition at line 52 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_MARKED_FOR_DELETE = '430' |
Definition at line 53 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_NO_THREAD = '41E' |
Definition at line 54 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_NOT_ACTIVE = '426' |
Definition at line 55 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SERVICE_REQUEST_TIMEOUT = '41D' |
Definition at line 56 of file class.win32service.php.
const Win32Service::WIN32_ERROR_SHUTDOWN_IN_PROGRESS = '45B' |
Definition at line 57 of file class.win32service.php.
const Win32Service::WIN32_NO_ERROR = '0' |
const Win32Service::WIN32_SERVICE_CONTINUE_PENDING = '5' |
Definition at line 19 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc().
const Win32Service::WIN32_SERVICE_NA = '0' |
Definition at line 26 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc(), isInstalled(), and status().
const Win32Service::WIN32_SERVICE_PAUSE_PENDING = '6' |
Definition at line 20 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc(), and isPending().
const Win32Service::WIN32_SERVICE_PAUSED = '7' |
Definition at line 21 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc(), and isPaused().
const Win32Service::WIN32_SERVICE_RUNNING = '4' |
Definition at line 22 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc(), and isRunning().
const Win32Service::WIN32_SERVICE_START_PENDING = '2' |
Definition at line 23 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc().
const Win32Service::WIN32_SERVICE_STOP_PENDING = '3' |
Definition at line 24 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc().
const Win32Service::WIN32_SERVICE_STOPPED = '1' |
Definition at line 25 of file class.win32service.php.
Referenced by getWin32ServiceStatusDesc(), and isStopped().