Problems with disabling Windows NT service
I have developed middleware that provides RPC functionality to multiple client applications across multiple platforms in our organization. The middle software is written in C # and runs like a Windows NT service. It handles things like file access for network shares, database access, etc. The middleware is hosted on two high-end Windows Server 2008 systems.
When one of our server administrators goes to restart the computer, primarily for Windows Updates, there are major issues with how the system behaves in relation to my NT service. My service is designed to immediately stop listening for new connections, immediately discard new requests on existing connections, and otherwise close as quickly as possible in the event of an OnStop or OnShutdown request from the SCM. However, in order to maintain the integrity of the system, operations that are currently in progress are allowed within a reasonable time. The server usually shuts down after 30 seconds (for example, when the service is manually stopped). However, when the system is prompted to restart, my service immediately loses access to network drives and UNC paths,which leads to data integrity issues for any open files and partial writes to those locations. My service lists the workstation (and therefore the SMB Redirector) as a dependency, so I think my service should be stopped before the Workstation / Redirector stops if Windows will run those dependencies.
Basically, my application is forced to crash and write, abandon RPCs, and ultimately force the operating system to terminate after a time-out period (seems to be on the order of 20-30 seconds).
Unlike the Windows application, my Windows NT service does not seem to have the ability to stop the system shutdown, delay the system shutdown, or even just keep all pending writes to the network drive until it is forcibly disabled and shut down. How is the NT service developer supposed to have any application integrity in this environment? Why does Forms Applications get all the power to shutdown their business before shutting down when services don't seem to get those benefits?
I tried:
Calling SetProcessShutdownParameters with p / invoke to try and notify my app to shutdown early to avoid closing the Redirector before I do.
Calling ServiceBase.RequestAdditionalTime with a value less than or equal to the two-minute limit.
Setting WaitToKillServiceTimeout
Anything I can think of to speed up my service.
But in the end, I still get ~ 30 seconds of problem time where my service was not even notified of the OnShutdown event, but requests fail due to the redirector no longer serving my network resource requests.
How should this issue be resolved? What can I do to delay or stop the shutdown, or at least allow my active tasks to close, without using Redirector services from under me? I can understand what Microsoft is trying to do to prevent dragging and dropping services and showing outages, but that seems like a big goal for Windows client operating systems, not servers. I don't want my servers to shutdown quickly, I want operational integrity and graceful shutdowns.
Thanks in advance for any help you can provide.
UPDATE: I did the exact timings. In a test termination, I received a close notification at 23:55:58 and noticed that I lost contact with network resources at 23:56:02. Thus, within four seconds, I lost the ability to maintain any active state.
a source to share
This question: https://serverfault.com/questions/34427/windows-service-dependencies on ServerFault should answer your question. He links to this article: http://blogs.technet.com/askperf/archive/2008/02/04/ws2008-service-shutdown-and-crash-handling.aspx , which should help you get the shutdown advance notice and stop service.
a source to share