[SOLVED] Server not restarting after shutdown -r now command
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Try "shutdown -r 0" instead. 2 less characters to type.
However, "shutdown -r now" also should work.
Note that if there is something preventing stop of services shutdown can fail (regardless of Linux distro). If you're having to power cycle every time you might want to open a console to do your shutdown and see where it hangs and/or what messages it is showing. Also you might want to see what is in your system log (/var/log/system or using systemctl) before the power cycle.
Thanks for pointing out the article. I should probably start doing what it suggests.
However, it is just a "suggestion". The article notes the existing (non-sytemctl) commands still work.
Quote:
The commands listed in Table 10.8, “Comparison of Power Management Commands with systemctl” are still available in the system for compatibility reasons, but it is advised that you use systemctl when possible.
I tested both "shutdown -r 0" and "shutdown -r now" on RHEL7 before my initial reply to OP. That is why I opined he may be having other issues preventing the shutdown from completing.
Distribution: Red Hat Enterprise Linux (University has a site license) - I otherwise use Ubuntu
Posts: 4
Original Poster
Rep:
Yeah I've tried all variations of shutdown, reboot, poweroff. There are no PolicyKit rules set that restriction shutdowns, I have verified that shutdown -r now works as expected at the server.
So it only fails when connected via ssh. I have a few more ideas to try tomorrow, but I had to quit for today.
it fails to boot and I have to manually power cycle it.
So on reread I noticed you're saying it "fails to boot". Does that mean it is in fact shutting down but not coming up after the shutdown? This sounds more like an issue with your BIOS settings than the shutdown itself.
Distribution: Red Hat Enterprise Linux (University has a site license) - I otherwise use Ubuntu
Posts: 4
Original Poster
Rep:
SUCCESS! I finally found a work-around that will surely yield an explanation for this problem.
If I log in using ssh as root then all is well: 'shutdown -h now' works as expected. It is only when the command. is executed using sudo or in a root shell started with sudo that there is a problem.
Must be an issue with a process dying during the shutdown process when initiated using sudo to elevate privileges. Very strange, as there was no indication that permissions were involved.
If I log in using ssh as root then all is well: 'shutdown -h now' works as expected. It is only when the command. is executed using sudo or in a root shell started with sudo that there is a problem.
Must be an issue with a process dying during the shutdown process when initiated using sudo to elevate privileges. Very strange, as there was no indication that permissions were involved.
Here you say "-h" but your original question was about "-r". "-h" is not a reboot but rather a halt so you would of course have to power up after a halt.
It seems unlikely sudo is the culprit. In my tests I ran via sudo for both "shutdown -r 0" and "shutdodwn -r now" and didn't see the issue you had. Also those tests were run via PuTTY (ssh) sessions into the system as myself then doing the "sudo su -" to become root.
Is it possible you did "sudo su" instead of "sudo su -" to become root. The former wouldn't invoke root's environment files (bashrc, profile, etc...). There's a lot in PATH for root that non-root users typically wouldn't have.
Last edited by MensaWater; 04-11-2018 at 09:25 AM.
If
su -
or
sudo su -
works but not su or sudo then there might be a check for the real uid in shutdown/reboot. Then it should say so ("need to really be root"), or there is a bug.
Furthermore, there might be a bug in systemd, wrongly relying on the privileges of systemd-login.
One of the reasons I dislike systemd: they are excellent programmers who dare to integrate some powerful mechanisms, but they do not have the full picture i.e. have not understood the principles that make Unix so secure and flexible.
If
su -
or
sudo su -
works but not su or sudo then there might be a check for the real uid in shutdown/reboot. Then it should say so ("need to really be root"), or there is a bug.
The OP never wrote about one working and the other not. However, I did and I disagree with what you say about a bug.
I explained that the environment for the root user is NOT invoked if you don't add the "-" to the su and that there are things in the root user's environment that typically are not in regular user environments. If you do it without the "-" then you're telling root to keep (inherit) the environment of the reguluar user that ran the su. This is true whether you do it with su and password or sudo su.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.