Shutdown via cli / whats the correct way

I read somewhere that shutdown now should not be used to turn off the device on the command line interface (CLI). Therefore:

What is the correct way to shutdown a SFOS system on a phone, when on the CLI? For example by a bash script et cetera. Thanks.

Do you know where you read it?

1 Like

It was here or in the old TJC portal. A search doesn’t reveal that sentence. Therefore here the question.

There is this unreliable reboot command [closed] - together.jolla.com about differences between shutdown -r and reboot and it also links to some bug in Mer, but that’s been fixed since 2015

‘shutdown -h now’ as devel-su works fine on my Volla @ 4.4.0.64. Tested it just now.

edit: Sony Xperia 10 also shuts down with this command, but then reboots immediately (very old bug, not fixed by Jolla since 3 years or longer)

devel-su poweroff

Tested just now; the above command shuts down both of my devices without any reboot. (Xperia 10 II @ Jolla1).

See here for descriptions of each command; Linux halt, poweroff, and reboot command help

  • halt instructs the hardware to stop all CPU functions.
  • poweroff sends an ACPI signal which instructs the system to power down.
  • reboot instructs the system to reboot.
1 Like

@throwaway69 thank you to find the right pointer! Indeed its that what I had in mind. The standard commands are wrapped with specific ones that are important for this platform (mobile + sfos) as depicted here [ unreliable reboot command [closed] - together.jolla.com ] and here [ Make command line reboot go through dsme when applicable by spiiroin · Pull Request #95 · nemomobile/dsme · GitHub ].

@Seven.of.nine , @Edz your command invocations are catched by the mentioned wrapper. That said, it applies only for interactive execution (bash). For applications, scripts, etc the right way should be explicitly considered and that is my case here. For example a kill switch …

Thanks again and have a nice day.

1 Like

@Edz ‘poweroff’ as devel-su shuts down my X10 fine with no reboot, while ‘shutdown -h now’ works only at the Volla phone. You helped me much!

@leon kill switch is a very good idea!

As SailfishOS is using systemd init system, I guess that best way is to use systemctl poweroff. As the /usr/sbin/poweroff is symlink to /usr/bin/systemctl, it behaves like alias I believe…

2 Likes

BTW, is it possible to shutdown the device via CLI as normal user (or script/bin) by using the dsmetool interface? Any DBUS or polkit possibilities available?

for my battInfo helper app for Xperia 10 V (until sony/jolla will fix battery status) i looking if there is better solution to poweroff phone within app than using privileged perms?
(yes, perhaps making patch for some system qml like StatusArea.qml or some other with timer may be the better solution, but actually i have no time for that now :frowning: )

reason: people asking for this because they may not hear low battery notification or they may sleep or just be away from phone…

desktop file:

Permissions=Privileged

the whorking code:

if (getBatteryPercent() < 1) dsmeDbus.powerOff();
 .....
    DBusInterface {
        id: dsmeDbus
        bus: DBus.SystemBus
        service: "com.nokia.dsme"
        path: "/com/nokia/dsme/request"
        iface: "com.nokia.dsme.request"
        function powerOff() {
            dsmeDbus.call("req_shutdown", [],
                          function(success) {
                              console.log("req_shutdown OK, powering off")
                          },
                          function(error, message) {
                              console.info("Error occured when entering to shutdown: ", error, "message:", message)
                          }
                          )
        }
    }

Just for fun:

shutdown now or init 0 tell systemd to bring the system down in a clean way, i.e. unmount the filesystems and gracefully end all processes in a reasonable order. If that fails due to a problem with systemd itself or since some required action fails, you can still tell the kernel to forcefully power off:

echo 1 > /proc/sys/kernel/sysrq
echo o > /proc/sysrq-trigger

Disclaimer: If that breaks your phone, you may keep the pieces.

on my testing xperia 10plus shutdown now does nothing for defaultuser, after devel-su it perform reboot :wink:

dbus call what i posted were extracted from system qml files
there is also call for lipstick, but it needs to be privileged too

    DBusInterface {
           id: lipstick
           bus: DBus.SystemBus
           service: "org.nemomobile.lipstick"
           path: "/shutdown"
           iface: "org.nemomobile.lipstick"

           function powerOff() {
               lipstick.call("setShutdownMode", ["poweroff"],
                             function(success) {
                                 console.log("setShutdownMode OK, powering off")
                             },
                             function(error, message) {
                                 console.info("Error occured when entering to shutdown: ", error, "message:", message)
                             }
                             )
           }
       }

SFOS is a bit special - “shutdown” is wrapper around dsmetool and its the preferred and official way to bring system down and should not be bypassed. It does some pretasks for correct app signaling, alarms and hw stuff like led trigger etc.