Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with shutdown command #113

Closed
cstosgale opened this issue Aug 2, 2020 · 4 comments
Closed

Issue with shutdown command #113

cstosgale opened this issue Aug 2, 2020 · 4 comments

Comments

@cstosgale
Copy link

Backstory

I've now got this working but wanted to log an issue to suggest that you add this to the Wiki so it can help others.

I have been trying to set up this plugin to power on and off a Windows PC, following the guide in the Wiki (I am using a Synology running homebridge in docker so this guide was invaluable!): https://github.com/AlexGustafsson/homebridge-wol/wiki/Running-on-Synology-Docker-and-turn-Windows-10-on-off-using-SSH-and-Samba

Issue

The issue I had was when I powered off my PC, the plugin would get stuck as the SSH command I was running to power off the Windows machine never returned. I was using PSShutdown with the following config:

ssh -o StrictHostKeyChecking=no -i /homebridge/id_rsa Chris@192.168.8.15 "C:\Data\PSTools\psshutdown -d -t 0"

What was happening was as this command was instantly suspending the machine, the SSH session hung and didn't close cleanly. This was stalling the plugin preventing me from powering my machine back on as it never transitioned to off correctly until I restarted home bridge.

I've found a workaround to this issue, which is to apply a 2 second delay to the psshutdown command. This gives the command enough time to finish cleanly before the PC is shutdown and resolves the issue:

ssh -o StrictHostKeyChecking=no -i /homebridge/id_rsa Chris@192.168.8.15 "C:\Data\PSTools\psshutdown -d -t 2"

As a further enhancement, it might be worth having a timeout that kills the terminal process if it hangs and allows the plugin to continue running?

The other thing that would be worth adding to the Wiki would be the use of PSShutdown as this allows suspend states. It's also important to ensure that this is run interactively by the user being used for SSH so you can accept the EULA, otherwise this hangs the SSH session.

@AlexGustafsson
Copy link
Owner

There might be another workaround which disables the waiting altogether. See #85 for more information. TLDR; try "returnEarly" : true in your config.

I've gone through the repository's settings to ensure that public edits of the wiki is allowed. Feel free to edit the parts you feel could be improved. If you think that what you want to change is too far from the original page, feel free to create a new one.

The suggestion about having timeouts is great, I'll see what I can do about that.

@cstosgale
Copy link
Author

That's great, thanks, I did try "returnEarly" : true, but this didn't resolve the issue, unfortunately.

I've updated the Wiki with some info on PSShutdown and my suggestion around the delay.

@AlexGustafsson
Copy link
Owner

I've released v4.3.0 which features a timeout option for each command (ping, start, wake and shutdown): shutdownCommandTimeout, wakeCommandTimeout etc. Note that if the timeout is reached, the command will be considered failed. For pinging that means that the device will be considered down, for start, wake and shutdown, that should mean that it "failed" and will wait for the grace time to pass before it starts pinging again. As a user, one shouldn't see any difference - but there may be errors thrown in the log.

@AlexGustafsson
Copy link
Owner

Closing as this should be solved by using the timeouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants