• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Correct way to shutdown a server?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

knoober

Member
Joined
Mar 18, 2015
Ive started building a server for home purposes: Here's the thread where I talk about it

Its been a few days and Im past the build stage finally, but Ive run into an other bump in the road. I chose ubuntu server (latest LTS -14.04?-) and have been happily jaunting down the road of a headless server. I set about initial hardening after install and lazily shutdown with the power switch when I was done. Today I cannot ssh into the machine and finally just reinstalled so I could quit looking for the answer. Now, I am hardening again but dont want to repeat my lazy mistake. What is the correct way to shutdown my system?

Will
Code:
sudo shutdown now
be enough? or is there a better procedure?

Another question quickly if I may? Is there a way to get use a GUI to ssh? I experimented with installing a GUI (Im Linux handicapped and need one for now. Im barely comfortable with the CLI) and it works on the monitor but now when I ssh into the machine (and as I explained this machine is meant to be headless) ? Thanks in advance :)
 
Ill look into the GUI links and thanks.

I was going to be more of a pest about the shutdown stuff but then I realized I could just try the different arguments. Im looking for the equivalent of the windows "shutdown" button and process :) Its the only thin that I can imagine caused my issue and "need" to reinstall.
 
There is a similar shutdown command in the windows commandline

https://technet.microsoft.com/en-us/library/bb491003.aspx

:p

Get to use that in Server 2012 a lot.


Also, trying to find a windows equivalent in linux..........Linux is about trying to make it more logical and faster than windows lol
once you get passed the formatting differences, it becomes much more simple
 
Last edited:
well here's what I can tell you...

the GUI links while informative (I never really knew to much of the differneces between GUI's) werent quite what I was looking for

Code:
sudo apt-get install name of GUI
will add it to the OS and *apparently*
Code:
startx
will begin a session. I cant get the GUI to load in ssh (probably not meant for it or something). Im not real certain what the technical difference between RDP and ssh is, but I think RDP may be more the experience that I am searching for. Ill let youy guys know when I get it figured out. All signs are pointing towards learning to live the the CLI though ;)

Code:
sudo shutdow -k now
will give you a shutdown and a halt (thanks for the links again) and afterwards you can *apparently* power down the machine without adverse effects. I gave it a try while I still had the monitor out and it did a few power cycles without wrecking anything. Id still like a clear cut shutdown command (fans , cpu and everything else OFF, not just in standby or not in use) but this is better than nothing.

So long story short Ive packed up the spare monitor to hopefully dig into the meat of this messy server business. I thought this project was going to be fun , but its just another pile of trial and error learning. WHoo-hoo! :bang head
 
The manual (man pages) will tell you how to use the command.

Code:
man shutdown

Code:
SHUTDOWN(8)                                                              shutdown                                                             SHUTDOWN(8)

NAME
       shutdown - Halt, power-off or reboot the machine

SYNOPSIS
       shutdown [OPTIONS...] [TIME] [WALL...]

DESCRIPTION
       shutdown may be used to halt, power-off or reboot the machine.

       The first argument may be a time string (which is usually "now"). Optionally, this may be followed by a wall message to be sent to all logged-in
       users before going down.

       The time string may either be in the format "hh:mm" for hour/minutes specifying the time to execute the shutdown at, specified in 24h clock
       format. Alternatively it may be in the syntax "+m" referring to the specified number of minutes m from now.  "now" is an alias for "+0", i.e. for
       triggering an immediate shutdown. If no time argument is specified, "+1" is implied.

       Note that to specify a wall message you must specify a time argument, too.

       If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be
       allowed.

OPTIONS
       The following options are understood:

       --help
           Prints a short help text and exits.

[B][COLOR=#ff0000]       -H, --halt
           Halt the machine.

       -P, --poweroff
           Power-off the machine (the default).

       -r, --reboot
           Reboot the machine.

       -h
           Equivalent to --poweroff, unless --halt is specified.[/COLOR][/B]

       -k
           Do not halt, power-off, reboot, just write wall message.

       --no-wall
           Do not send wall message before halt, power-off, reboot.

       -c
           Cancel a pending shutdown. This may be used cancel the effect of an invocation of shutdown with a time argument that is not "+0" or "now".

EXIT STATUS
       On success, 0 is returned, a non-zero failure code otherwise.

SEE ALSO
       systemd(1), systemctl(1), halt(8), wall(1)

The "-k" flag is not what you want. "shutdown now" is literally all you need.
 
Last edited:
when I use
Code:
shutdown now

I get a message that the "system is shutting down for maintenance" but my fans are still running. I will try the other arguments listed in the man (not that they werent in that link in post 2, but I didnt see the -P --poweroff part).
 
Yeah...Linux you have to be specific.

And yes, MAN pages are great, but can be annoying to navigate at times, specially coming from windows lol.

What behavior are you trying to get shutdown to accomplish exactly?

Also, what linux flavor are you running exactly?


There are other ways too.
Such as switching to certain run levels
runlevel 6: Restart
runlevel 0: Shutdown
 
Last edited:
just want to shut down the machine... have it turn off (operating system AND hardware) I dont want to leave it running all the time. Electricity isnt free after all :)

when I use
Code:
shutdown now

my ssh session ends but the hardware is still running. also happens when I use

Code:
shutdown -k now

Im getting ready to try with different arguments, but Im still working on stuff so Ill have to wait for a suitable time to restart

Code:
shutdown -r now
incidentally ;)

Trial and error is fun, as long as it doesnt mean trying every argument on the man page
 
I've had a machine not power off (fans still spin) when I tell Windows to shutdown.
At that point I hit the power button on the rig and all is kosher. :)
 
I'm not sure why "shutdown now" does not work on your install, but "shutdown -h now" should do a full shutdown and "shutdown -r now" should restart the system.
 
holding the power button killed my ability to ssh into the machine, and i wasnt savvy enough to fix without a reinstall

-P was the correct argument (does what I want it to do).I had planned on just doing things manually with a shutdown -k (or -h) and then hitting the power button, but as I already said -P did its job. The part where it said it was enabled by default is what was defeating me. It never occurs to me to "just try it" until after I hit the submit button.
 
Back