Windows 서비스로 실행되는 CherryPy 서버에서 실행되는 Python 웹 응용 프로그램이 있습니다.이 응용 프로그램을 배포 할 배치 파일이 있지만 여전히 원격 데스크톱이 필요합니다. 서비스를 다시 시작할 서버입니다.이 스크립트를 작성할 방법이 있습니까?
나는 시도했다 :
psexec \\server "net restart cherrypyservice"
그러나 이것은 작동하지 않는 것 같습니다.
sc 명령 줄 도구를 사용할 수 있지만 파이썬에서 구체적으로 수행하는 방법을 모르겠습니다.
설명 : SC는 NT 서비스 컨트롤러 및 서비스와 통신하는 데 사용되는 명령 줄 프로그램입니다. 사용법 : sc [명령] [서비스 이름] ...
The option has the form "\\ServerName"
Further help on commands can be obtained by typing: "sc [command]"
Commands:
query-----------Queries the status for a service, or
enumerates the status for types of services.
queryex---------Queries the extended status for a service, or
enumerates the status for types of services.
start-----------Starts a service.
pause-----------Sends a PAUSE control request to a service.
interrogate-----Sends an INTERROGATE control request to a service.
continue--------Sends a CONTINUE control request to a service.
stop------------Sends a STOP request to a service.
config----------Changes the configuration of a service (persistant).
description-----Changes the description of a service.
failure---------Changes the actions taken by a service upon failure.
qc--------------Queries the configuration information for a service.
qdescription----Queries the description for a service.
qfailure--------Queries the actions taken by a service upon failure.
delete----------Deletes a service (from the registry).
create----------Creates a service. (adds it to the registry).
control---------Sends a control to a service.
sdshow----------Displays a service's security descriptor.
sdset-----------Sets a service's security descriptor.
GetDisplayName--Gets the DisplayName for a service.
GetKeyName------Gets the ServiceKeyName for a service.
EnumDepend------Enumerates Service Dependencies.
The following commands don't require a service name:
sc
boot------------(ok | bad) Indicates whether the last boot should
be saved as the last-known-good boot configuration
Lock------------Locks the Service Database
QueryLock-------Queries the LockStatus for the SCManager Database
예 : sc start MyService
Russinovich의 psservice 사용 :
psservice \\server restart cherrypyservice
Psexec를 사용하려는 경우 :
psexec \\Server cmd "/c net stop servicename"
psexec \\Server cmd "/c net start servicename"
이 경우에는 sc가 권장됩니다. Shell out을 사용하는 경우 필요한 모든 작업을 수행합니다.
시험
psexec \\server net stop cherrypyservice
psexec \\server net start cherrypyservice
net stop cherrypyservice
net start cherrypyservice
원하는 원격 실행 엔진으로.
대화식으로 PowerShell 사용 (로컬) :
get-service $servicename | restart-service
대화식으로 (원격) PowerShell 사용 :
(gwmi win32_service -computer $comp -Filter "name='$serviceName'").StopService()
(gwmi win32_service -computer $comp -Filter "name='$serviceName'").StartService()
함수에서 (원격) :
function restart-remoteservice{
param($servicename,$computer)
(gwmi win32_service -computer $computer -Filter "name='$serviceName'").StopService()
(gwmi win32_service -computer $computer -Filter "name='$serviceName'").StartService()
}
WMI 방법 사용
(Get-WmiObject win32_service -computer stp7cor1737ltv4 -filter "Name = 'SPtimerv3'"). invokemethod ( "StartService", $ null)
(gwmi win32_service -computer $ comp -Filter "name = '$ serviceName'"). StopService () (gwmi win32_service -computer $ comp -Filter "name = '$ serviceName'"). StartService ()
여보세요
위의 명령을 사용하여 서비스와 해당 종속성을 다시 시작할 수있는 방법이 있습니다. 강제로 수행하려면 어떻게해야합니까? 강제 명령이 있습니까?
Psservice에 -f가 있다는 것을 알고 있지만 여기서는 알아낼 수 없습니다.
psservice \\server restart cherrypyservice
(psservice가 다른 SysInternals 앱인 경우)
또는
sc \\server stop cherrypyservice
sc \\server start cherrypyservice