shutdown properly via bash

Forum rules
Before you post please read how to get help

shutdown properly via bash

Postby Otyugh on Fri Feb 01, 2013 8:48 am

Hey,
I wonder how i could shutdown normally a systemn with a bash command.
The one I used actually is "sudo shutdown -h now".

But I also noticied it wasn't a normal shutdown. Actually when I shut my pc through mint I have to wait a few seconds to see some service being stoped. With shutdown command I feel like I'm doing it "barbarian way".
Otyugh
Level 3
Level 3
 
Posts: 125
Joined: Wed Jan 02, 2013 9:52 pm

Linux Mint is funded by ads and donations.
 

Re: shutdown properly via bash

Postby SiKing on Fri Feb 01, 2013 4:08 pm

Code: Select all
sudo init 0
SiKing
Level 5
Level 5
 
Posts: 576
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas

Re: shutdown properly via bash

Postby Otyugh on Fri Feb 01, 2013 7:51 pm

Hey,
I used your command and I don't quite see the difference with the shutdown. It don't display any "step" before shuting down. It's strange to me.
Otyugh
Level 3
Level 3
 
Posts: 125
Joined: Wed Jan 02, 2013 9:52 pm

Re: shutdown properly via bash

Postby kwisher on Sat Feb 02, 2013 11:13 am

How about "sudo poweroff" ?
The instructions suggested Windows XP or better, so I installed Linux :)
User avatar
kwisher
Level 5
Level 5
 
Posts: 643
Joined: Wed Mar 05, 2008 12:54 pm
Location: Greentown, Indiana USA

Re: shutdown properly via bash

Postby Otyugh on Mon Feb 04, 2013 3:27 pm

The same way, I do not see any log message saying somethinh like "stoping the running programs in less than 2 seconds" and stuffs.
I really don't know if the commands you gave to me is doing this and just doing it silently, or if they are all the same "brutal shut down" as if i forced to quit every program. :(
Otyugh
Level 3
Level 3
 
Posts: 125
Joined: Wed Jan 02, 2013 9:52 pm

Re: shutdown properly via bash

Postby Jamesc359 on Tue Feb 05, 2013 4:35 am

shutdown -h now is a perfectly safe and valid method to shutdown a system. There's nothing brutal about it. :)
“Gosh, you've... really got some nice toys here.”
User avatar
Jamesc359
Level 3
Level 3
 
Posts: 133
Joined: Sun May 06, 2012 1:42 pm

Re: shutdown properly via bash

Postby Otyugh on Tue Feb 05, 2013 2:09 pm

My very big point about it, it's that it have to be done as root. Secondly it does not stop to shutdown if any "gedit text wasn't saved yet", it just quit everything. Isn't that brutal ?
I mean, the difference between "i ask you to close" and "I just kill you, because i'm the system, kid".
Otyugh
Level 3
Level 3
 
Posts: 125
Joined: Wed Jan 02, 2013 9:52 pm

Re: shutdown properly via bash

Postby bjornmu on Tue Feb 05, 2013 2:43 pm

There is no way for the system to know which running user processes need to be told to "close" in a controlled manner, and how to do so. Nor can it know in which order to shut them down or how long to wait. All it can do is to send the processes a SIGTERM signal but I don't know if it actually does? Then it's each program's responsibility to do some sensible actions but it's limited what they can do.
User avatar
bjornmu
Level 3
Level 3
 
Posts: 160
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Re: shutdown properly via bash

Postby SiKing on Tue Feb 05, 2013 3:37 pm

bjornmu, I suspect you are expecting too much here.

As was already mentioned, shutdown is considered perfectly "safe". If you read 'man shutdown' you will notice the following:
shutdown arranges for the system to be brought down in a safe way.
...
Once TIME has elapsed, shutdown sends a request to the init(8) daemon to bring the system down into the appropriate runlevel.

You can further read about 'man 8 init' and 'man 7 runlevel' to find out all the gory details. These systems bring down any running system processes in the correct order. Any user processes are sent a signal to shutdown, however applications often ignore this. You can submit defect against each application if you'd like. However, the general assumption is that the user will take care to properly save all their work, since the system has no way of knowing if the user actually wants to save any changes they made. This can lead to a debate of epic proportions...
SiKing
Level 5
Level 5
 
Posts: 576
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas

Re: shutdown properly via bash

Postby bjornmu on Tue Feb 05, 2013 4:02 pm

I'm not expecting much, my point was that the OP may be expecting too much.
User avatar
bjornmu
Level 3
Level 3
 
Posts: 160
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Re: shutdown properly via bash

Postby SiKing on Tue Feb 05, 2013 4:09 pm

bjornmu wrote:I'm not expecting much, my point was that the OP may be expecting too much.

:oops: sorry, copy-paste mistake.
SiKing
Level 5
Level 5
 
Posts: 576
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas

Re: shutdown properly via bash

Postby DrHu on Tue Feb 05, 2013 4:20 pm

The system way is to force off all programs and then power off, so that is the barbarian way
--what this is really is an admin control of the overall system, and is fairly obviously the normally expected behavior, no different than a windows or Apple OS shutdown
    If it was a server system, rather than a desktop OS, then the shutdown operation would not be available to a normal user, what the windows OS names as a limited account..
    --a non-admin or root user..
    The normal user or in the case of Ubuntu/Mint an admin (sudo) group user can do pretty much what they want on the system, and on the command line (terminal) can use the shutdown command
    --a new user, could be excluded from that option, via the /etc/sudoers file if the admin of the desktop wanted to do so, but that probably doesn't really make much sense with a desktop, unless you intended to operate in a kiosk-style mode: more admin controls, less user interactions
A user should normally expect in any multiuser system to log-off, and if they were not an administrator of the system to either not be able to shutdown (via the desktop) or be allowed to do do..
User avatar
DrHu
Level 17
Level 17
 
Posts: 7022
Joined: Wed Jun 17, 2009 8:20 pm

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests