shutdown properly via bash

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Otyugh

shutdown properly via bash

Post by Otyugh »

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".
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
SiKing
Level 5
Level 5
Posts: 571
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas
Contact:

Re: shutdown properly via bash

Post by SiKing »

Code: Select all

sudo init 0
Otyugh

Re: shutdown properly via bash

Post by Otyugh »

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.
kwisher

Re: shutdown properly via bash

Post by kwisher »

How about "sudo poweroff" ?
Otyugh

Re: shutdown properly via bash

Post by Otyugh »

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. :(
Jamesc359

Re: shutdown properly via bash

Post by Jamesc359 »

shutdown -h now is a perfectly safe and valid method to shutdown a system. There's nothing brutal about it. :)
Otyugh

Re: shutdown properly via bash

Post by Otyugh »

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".
User avatar
bjornmu
Level 3
Level 3
Posts: 189
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Re: shutdown properly via bash

Post by bjornmu »

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.
SiKing
Level 5
Level 5
Posts: 571
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas
Contact:

Re: shutdown properly via bash

Post by SiKing »

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...
User avatar
bjornmu
Level 3
Level 3
Posts: 189
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Re: shutdown properly via bash

Post by bjornmu »

I'm not expecting much, my point was that the OP may be expecting too much.
SiKing
Level 5
Level 5
Posts: 571
Joined: Mon Sep 29, 2008 10:57 pm
Location: Las Vegas
Contact:

Re: shutdown properly via bash

Post by SiKing »

bjornmu wrote:I'm not expecting much, my point was that the OP may be expecting too much.
:oops: sorry, copy-paste mistake.
DrHu

Re: shutdown properly via bash

Post by DrHu »

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..
Locked

Return to “Scripts & Bash”