Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for systemd's systemctl reboot for passwordless reboots #861

Open
matkeith opened this issue Jul 11, 2024 · 5 comments · Fixed by #866
Open

Add support for systemd's systemctl reboot for passwordless reboots #861

matkeith opened this issue Jul 11, 2024 · 5 comments · Fixed by #866
Assignees
Labels
C-feature request New feature request

Comments

@matkeith
Copy link

matkeith commented Jul 11, 2024

I want to suggest some general feature

Topgrade should allow for reboot without requiring a sudo password by using command "systemctl reboot" if the system is running systemd.

More information

If the linux system uses systemd you do not need to reboot using sudo, which requires typing in a password. Instead use the command "systemctl reboot" which will just reboot the system without further user action

https://www.freedesktop.org/software/systemd/man/latest/sd_booted.html
"Internally, this function checks whether the directory /run/systemd/system/ exists. A simple check like this can also be implemented trivially in shell or any other language."

Seems like you can check for this folder in rust and then execute the alternate command "systemctl reboot" instead in the below function

pub fn reboot() -> Result<()> { print!("Rebooting..."); Command::new("sudo").arg("reboot").status_checked() }

I do not know how to test this from a side branch, as I am using bazzite, an immutable desktop. I'm willing to give it a try though if there are instructions somewhere.

@matkeith matkeith added the C-feature request New feature request label Jul 11, 2024
@matkeith matkeith changed the title Add support for systemd's systemctl reboot Add support for systemd's systemctl reboot for passwordless reboots Jul 11, 2024
@SteveLauC
Copy link
Member

SteveLauC commented Jul 15, 2024

Thanks for the report!

Does the reboot command on your Linux box need sudo, from this answer, reboot since Ubuntu 16 does not need sudo, and I started using Fedora since 36, I don't remember sudo is ever needed. Are they due to the switch to the systemd init program?

Though the reboot on my macOS machine does need sudo.

@matkeith
Copy link
Author

@SteveLauC yeah it looks like typing "reboot" without sudo works as well for me on bazzite as well

@SteveLauC
Copy link
Member

I found that this root-less reboot only works if you have local access to your machine, i.e., not ssh, when you do it via ssh:

$ reboot
Call to Reboot failed: Interactive authentication required.

See also: Getting errors whenever I try to reboot or shutdown through terminal

@matkeith
Copy link
Author

Bummer. I found some additional info from ubuntu's forum as well
https://askubuntu.com/questions/1005884/sudo-reboot-vs-reboot-what-is-the-difference

specifically these criteria:

On Ubuntu 14.10 and older, sudo is required.

The introduction of Systemd in 15.04 changed the way Ubuntu handles shutdown and reboot:

When a single user is logged in, sudo isn't necessary. When more than one user is logged in then sudo is required.

Applications can inhibit shutdown and reboot. You override these inhibitions with sudo.

A single user logged in via ssh still requires sudo.

so it seems there are more nuances involved than simply using ssh. reboot would fail on a multiuser system or if an application were to prevent it.

matkeith@mattlaptop:~$ ls -al $(which reboot)
lrwxrwxrwx. 19 root root 16 Jul  5 15:30 /usr/sbin/reboot -> ../bin/systemctl

reboot is just pointed at systemctl reboot anyhow. I don't see a way around this intelligently. oh well =/

@SteveLauC
Copy link
Member

So, it seems that:

  • If we are running Topgrade through SSH, then sudo is needed
  • Otherwise, check if there are more than one user is logged in, if so, sudo is also needed.

Let me implement this.

@SteveLauC SteveLauC reopened this Oct 3, 2024
@SteveLauC SteveLauC self-assigned this Oct 3, 2024
@SteveLauC SteveLauC mentioned this issue Oct 6, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature request New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants