简体   繁体   中英

How to shut down the host from within the container?

I'm writing a UPS monitoring console application that will automatically shut down the server when the UPS battery reaches a predefined level of charge during a power outage.

I'd like to run this within a container if possible, as NUT (Network UPS Tools) is notoriously difficult to get working on a Windows system. I've configured it once, on bare metal, and I wish not to have to endure that pain a second time, or worse, a third. (But that's another discussion for another day.)

Back to today: how may I send a system shutdown command to the container's host? I've tried simply shutdown /s /t 0 , but that shuts down the container. I need to reach the host.

--NOTE TO CLOSE VOTERS--

This question is not off-topic. Note this Q&A , for one example, which currently bears upvotes numbering well over 2,000. There isn't a single programming concept mentioned in the question.

Docker is a tool used by developers. So its subject matter is very relevant on this forum. Run a quick query on the docker tag and you'll see what I mean.

psshutdown \\\\host -u ... -p ... should do the trick, assuming you are able / willing to store credentials with sufficient permissions in the container.

See https://technet.microsoft.com/en-us/sysinternals/psshutdown.aspx for more details and a download link.

Edit : I leave this here for documenting an approach that doesn't work because of changes in the way Windows handles security. Follow InteXXs link provided below, it clearly describes what would be necessary to get psshutdown working again and which security risks this brings.

An approach that involves a little bit of programming would be to create a small service that sits on the host and waits for incoming connections.

That service could then either execute the shutdown command or call the appropriate Windows API call.

I suggest giving this service a minimal http endpoint with a single URL and protect it with user / password and SSL/TLS.

You would then call this from the container using curl --user user:pass https://host/shutdown

It should be fairly easy to implement this with golang and nssm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM