Reputation: 757
I have looked at all the answers here on SOF, and not seen what would work.
Have a EC2 QA server halt itself 55 minutes after last usage
Everytime the remote machine is used, it is first checked to see if it is running. If it is, then do the following:
Go about my script's business
All commands work locally 1 and 2. Numbers 3 and 4 are partial as explained below.
The line invoking the new shutdown halt, it waits for the ssh connection to shutdown, which never does for the versions of the command without '&' at the end.
echo "nohup sudo shutdown -h +55; exit" | ssh -i $HOME/.ec2/cert_name [email protected]
echo "nohup sudo shutdown -h +55& exit" | ssh -i $HOME/.ec2/cert_name [email protected]
echo "sudo shutdown -h +55& exit" | ssh -i $HOME/.ec2/cert_name [email protected]
ssh -i $HOME/.ec2/cert_name [email protected] nohup sudo shutdown -h +55
ssh -i $HOME/.ec2/cert_name [email protected] nohup sudo shutdown -h +55; exit
ssh -i $HOME/.ec2/cert_name [email protected] nohup sudo shutdown -h +55&
ssh -i $HOME/.ec2/cert_name [email protected] sudo shutdown -h +55&
The partially successful commands set up the shutdown, and exit ssh just fine. But they fills the LOCAL screen buffer with the last command results on the REMOTE screen. And that comes out with the results of the next command in the script.
I suppose that I could just issue 'echo "flushing buffer"' twice in a row and clear it.
Anything more complete and cleaner out there?
TIA
Upvotes: 2
Views: 2894
Reputation: 856
This seems to shutdown after <time>
seconds even if you exit SSH-connection:
( sleep <time>; sudo shutdown now ) &
provided your sudoers file allows shutdown without password.
Upvotes: 0
Reputation: 757
OK, 4 days later, I have something that works pretty good. I did NOT see anything like this on google or stack overflow searches.
Essentially, a cheap server is used as a keep alive (for 120 minutes) or restart (if already timed out) controller for a more expensive server. There are hints on how to do it for more complex setups than (1 cheap server)->(1 expensive server). Otherwise known as a 'exercise for the reader' :-)
https://github.com/kwince/costlyServerShutDown
The trigger to keep alive or restart is doing a 'wget' to file on the apache server root of the cheap server. Again, quick and dirty, but very effective.
Upvotes: 1