Koozali.org: home of the SME Server

Idiotproof shutdown

Michael Smith

Idiotproof shutdown
« on: October 22, 2002, 08:15:26 PM »
Could someone give me a hint as to the best way to construct a VERY simple way to send an e-smith server a shutdown command?  Ideally this would be a command-line script that could be launched from an icon at a workstation.

I'm not asking for a step-by-step handholding (though I wouldn't refuse same!!!) but some hints would be great.  Something with PuTTY, perhaps?

I should note that this issue arose when Hurricane Lili visited our part of the U.S. ... I was able to shut down several servers via VPN access to Server Manager but had to visit several sites in person as I hadn't trained anyone onsite to use the Server Manager to shut down.  I won't be caught THAT way again!

Nathan Fowler

Re: Idiotproof shutdown
« Reply #1 on: October 22, 2002, 09:04:00 PM »
This is untested of course, but I believe the logic is sound.

Login to your e-smith box as root.

pico /sbin/eshutdown
[Add these lines]
#!/bin/bash
/sbin/shutdown -h now
[Save Changes]

adduser -r eshutdown -c "Emergency Shutdown Account" -s /sbin/eshutdown
passwd eshutdown
[Set a password]

Now, to shut down the box, the user simply needs to login to that box using Putty and logon using the eshutdown/[password] account.  Immediately after logging in the box should start the shutdown process and halt after shutdown.

Let me know if this works, I believe it would.

Nathan

Charlie Brady

Re: Idiotproof shutdown
« Reply #2 on: October 22, 2002, 09:05:07 PM »
Michael Smith wrote:

> Could someone give me a hint as to the best way to construct
> a VERY simple way to send an e-smith server a shutdown
> command?  Ideally this would be a command-line script that
> could be launched from an icon at a workstation.

Can anyone spell Denial Of Service?

[Answer - walk to the server, C-A-D on the keyboard, then wait for the beep, then power off.]

[Better answer - install UPS interface software, pull power plug from wall - server will shut down when battery power gets low.]

Charlie

bob

Re: Idiotproof shutdown
« Reply #3 on: October 22, 2002, 09:12:27 PM »
Did you check this link out?

http://forums.contribs.org/index.php?topic=15108.msg57988#msg57988

Then the people at the site can just hit the switch and the server will gracefully shutdown.

Bill Talcott

Re: Idiotproof shutdown
« Reply #4 on: October 22, 2002, 09:23:29 PM »
You can always use http://www.dungog.net/sme/howto/delegate.php to give a user(s) the ability to shutdown the server. They would obviously still need to know how to do it, but then they don't have to remember "admin" stuff, just their own username and password.

Des Dougan

Re: Idiotproof shutdown
« Reply #5 on: October 23, 2002, 06:46:27 AM »
If you don't want to entrust the shutdown to users, you can use PuTTY with an ssh tunnel to access the Server Manager, which of course has a shutdown option.

I believe there's a How To for PuTTY on the e-smith site. If not, search the forums. Using PuTTY works really well...

Des Dougan

Michael Smith

Re: Idiotproof shutdown
« Reply #6 on: October 23, 2002, 08:33:41 AM »
This is close to what I had in mind ... I'd like to have a command-line solution that logs into the server via SSH and issues this command.  Hmmmm, looks like "plink" will do it.  Will set up a test box and let y'all know.

Charlie:  your three-finger solution would work if only the servers didn't usually run without keyboards.

Michael Smith

Re: Idiotproof shutdown
« Reply #7 on: October 23, 2002, 08:52:43 AM »
Hm, that didn't take long.  Reckon I got a bit lazy asking y'all for help but I didn't know the /sbin/shutdown command so that was really the big clue.  Plink defaults to ssh so you don't even need that option on the command line.

Mini-HowTO:

Get PuTTY.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Use PuTTY once to establish an SSH link so the fingerprint will be saved.

Put the following in a batch file or in an icon's properties:

plink -l root -pw [YOURPASSWORD] [SERVER_NAME_OR_IP] /sbin/shutdown -h now

For example, on machine at 192.168.1.1, root password blarney:

plink -l root -pw blarney 192.168.1.1 /sbin/shutdown -h now

Substitute -r for -h if you want to reboot a hung server that still responds to SSH.

Doesn't get much easier than that!!!  Nathan, thanks for the clue I needed.  Now I'll create icons, buried deep in the menu structure, that point to batch files that ask for confirmation before doing this, and clients can Do It Themselves.

Nathan Fowler

Re: Idiotproof shutdown
« Reply #8 on: October 23, 2002, 06:05:57 PM »
Excellent, I didn't know about plink, we both learned something.

Michael, for what it's worth, I would do anything possible to not disclose my root password in plain-text.  Any half-witted computer user can figure out how to view that batch file and play with your settings, or worse, use it to launch DoS attacks.  Perhaps you could use your above solution in conjunction with a "secure" user account.

My biggest concern would be security, since you are working with Win32 clients I would recommend you create a simple VB binary and at least attempt to obfuscate the root login/password.  I would be more than willing to help you out there if you don't know VB.  Personally, I'd do anything I could to avoid disclosing my root password to my production servers to end users.

Hope this helped,
Nathan

Michael Smith

Re: Idiotproof shutdown
« Reply #9 on: October 23, 2002, 06:37:12 PM »
Nathan, your concerns are well warranted, and a bit of VB wrapping this up would be most welcome.  I should note that the sites at which I would anticipate doing this are such that the set of all users who'd be capable of, much less inclined toward, parsing the command line & understanding it equals the null set.

I suppose I *should* create a user with powers to do this and rewrite for that user instead of root.  Best procedures, eh?

Nathan Fowler

Re: Idiotproof shutdown
« Reply #10 on: October 23, 2002, 06:44:39 PM »
Can you email me your command line to plink.exe and I'll create a VB application for you that would obfuscate the src code.  I'll provide the source as well as the primary binary.  This would be a one-click shutdown option that would at least be somewhat more secure.

Other than that you could use:
adduser -r eshutdown -c "Emergency Shutdown Account" -s /sbin/halt
passwd eshutdown
[Set a password]

Then batch:
plink -l eshutdown -pw [password] 192.168.1.1 /sbin/halt

Because the default shell is halt, which is basically shutdown + halt, when you successfully login using plink the server should begin shutting down immediately.  The command "/sbin/halt" after the IP in teh plink command-line is almost unncessary because the default shell is /sbin/halt for this user.

If that doesn't work, let me know, and we'll just obfuscate the login using VB.

Rob Walker

Re: Idiotproof shutdown
« Reply #11 on: October 23, 2002, 07:38:08 PM »
If we are going to be using the login shell as the shutdown
command, would it be wise to create a couple of different
users, for different roles?

ehalt, ereboot both come to mind.

rob

Michael Smith

Re: Idiotproof shutdown
« Reply #12 on: October 23, 2002, 08:51:03 PM »
Nathan, do you mean the full pathname, such as c:\util\putty\plink.exe?  Could your VB easily accommodate different hosts & passwords?  Seems as though creating a shutdown user would be the more elegant approach, not to mention less work for you.  

Many, many thanks to all who've thought about & commented on this one.  It seems that it'd be useful for many members of the community.

Nathan Fowler

Re: Idiotproof shutdown
« Reply #13 on: October 23, 2002, 09:05:03 PM »
Yes, creating a shutdown user would be much more secure, with respect to comprimising (spelling?) the system.  Rob's got a good idea also.  I would recommend using /sbin/halt instead of /sbin/shutdown as they both really accomplish the same thing.

NF

Marcos Migliorini

Re: Idiotproof shutdown
« Reply #14 on: October 24, 2002, 11:36:20 PM »
Hi to all,

This is very interesting!.
Two or three days a week, my wireless modem lost the connection (PPPoE) and I have to perform the following command:

service pppoe restart

Is possible to do with Putty and creating a restart user? I am a little bit newby so I will apreciate a mini how to!

Thanks in advance

Marcos Migliorini

Nathan Fowler

Re: Idiotproof shutdown
« Reply #15 on: October 24, 2002, 11:59:01 PM »
Login to your e-smith box as root.

pico /sbin/WirelessRestart
[Add these lines]
#!/bin/bash
/sbin/service ppoe restart (Isn't it ppoe, not pppoe?)
[Save Changes]

adduser -r wireless -c "Wireless Restart Account" -s /sbin/WirelessRestart
passwd wireless
[Set a password]

Then, using plink you could create a batch file that would:
plink -l wireless -pw [password] aaa.bbb.ccc.ddd /bin/false

Where, aaa.bbb.ccc.ddd is the IP Addr of your E-Smith box.

Hope this helped,
Nathan