本文介绍了停止服务 cmdlet 超时可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 stop-service cmdlet 来终止我们机器上的一些服务.大多数情况下,它运行良好,但我们有一两个服务(谁没有?)偶尔表现不佳.

We're using the stop-service cmdlet to kill a few services on our boxes. Most of the time it works great, however we have one or two services (who doesn't?) that occasionally don't play nice.

在这种情况下,有问题的服务之一将保持停止状态,并且 cmdlet 一遍又一遍地将其输出到控制台:

In this instance one of the services in question will remain in the stopping state, and the cmdlet puts this out to the console over and over:

[08:49:21]WARNING: Waiting for service 'MisbehavingService (MisbehavingService)' to finish
[08:49:21]stopping...
[08:49:23]WARNING: Waiting for service 'MisbehavingService (MisbehavingService)' to finish
[08:49:23]stopping...
[08:49:25]WARNING: Waiting for service 'MisbehavingService (MisbehavingService)' to finish
[08:49:25]stopping...

最终我们不得不终止任务管理器中的服务,然后我们的脚本继续运行.

Eventually we have to kill the service in the task manager, and our script then continues.

有没有办法让 stop-service cmdlet 在某个时间点后放弃或超时?我想我们可以稍后检查,如果服务仍在运行,请使用 kill-process cmdlet 提供最后的印章.

Is there a way to have the stop-service cmdlet give up or timeout after a certain point? I figure we can check afterward and if the service is still running, use the kill-process cmdlet to provide a final chop.

推荐答案

stop-service 没有超时选项,但是如果有依赖服务,可能需要使用-force.

There is no timeout option for stop-service, but if there are dependent services, you may need to use -force.

服务在启动时可以定义等待提示(指定超时),但超时由服务控制.任何服务控制请求(启动、停止、暂停、恢复)都通过服务控制管理器 (SCM) 并尊重每个服务的等待提示.如果超过等待提示,操作将失败并返回错误.

Services can define a wait hint (which specifies a timeout) when they start, but the timeout is controlled by the service. Any service control requests (start, stop, pause, resume) go through the service control manager (SCM) and will respect the wait hint for each service. If the wait hint is exceeded, the operation will fail and an error be returned.

您可以使用 invoke-command 将 Stop-Service 作为作业运行并定期检查.如果它还没有完成,你可以使用 Stop-Process 来终止进程并继续.

You could use invoke-command to run Stop-Service as a job and check it periodically. If it hasn't completed, you could use Stop-Process to kill the process and continue.

这篇关于停止服务 cmdlet 超时可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 20:14