The officially official Devuan Forum!

You are not logged in.

#1 2017-11-18 16:17:43

lunario
Member
Registered: 2017-11-18
Posts: 2

Conversion of simple systemd script to non-systemd

Hi,

running devuan ascii with i3 window manager.
I would like to  convert a not too complex i3 script, meant for systemd, to work with devuan so that I can use it to control pm-suspend or an alternative suspend/hibernate/shutdown tool with it.

Could somebody tell me how to transform it?
The code is:


#!/bin/sh
lock() {
    i3lock
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        lock && systemctl suspend
        ;;
    hibernate)
        lock && systemctl hibernate
        ;;
    reboot)
        systemctl reboot
        ;;
    shutdown)
        systemctl poweroff
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0

Offline

#2 2017-11-19 10:42:20

Geoff 42
Member
Registered: 2016-12-15
Posts: 74

Re: Conversion of simple systemd script to non-systemd

I don't know!

However, I was just reading the message on DNG from Steve Litt about process supervisors :-

https://lists.dyne.org/lurker/message/2 … d3.en.html

I wonder whether this might be a way forwards.

Geoff

Offline

#3 2017-11-19 15:37:22

fsmithred
Administrator
Registered: 2016-11-25
Posts: 471

Re: Conversion of simple systemd script to non-systemd

It looks like you could just replace the systemd commands with non-systemd commands. I don't know i3. How does it handle running those commands as root? Or does user have privilege for the shutdown and reboot commands? For hibernate and suspend, you can use 'pm-hibernate' and 'pm-suspend'.

Whenever I use a window manager without a diplay manager, I give my user sudo nopasswd permission for those commands.

It's also possible to let dbus manage the session, and then you can use dbus commands for shutdown, etc. I think that's been discussed somewhere on this forum. If you need that and can't find it, just say so.

This looks like the easy solution. No idea here if it works. (Note: Tags to put this in a code box are right above the message text box when you're composing.)

#!/bin/sh
lock() {
    i3lock
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        lock && pm-suspend
        ;;
    hibernate)
        lock && pm-hibernate
        ;;
    reboot)
        reboot
        ;;
    shutdown)
        poweroff
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0

Offline

Board footer