systemd-inhibit doesnt work with cinnamon gui shutdown button

Forum rules
Before you post please read how to get help
Post Reply
wullewu
Level 1
Level 1
Posts: 3
Joined: Fri Aug 25, 2017 6:34 am

systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by wullewu » Mon Aug 28, 2017 3:58 am

Hi,
I have a backup-script for my Linux Mint machine. I wanted to block shutdown, sleep or logout commands until the script is running.

systemd-inhibit --what=shutdown:sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch tar -czf /media/fabian/hdd_extern/backup_fabian/home_$datum.tar.gz /home/fabian/*

So far so good. It works when i try to shutdown the machine via commandline, but when I press the shutdown button in the cinnamon gui the user logs off an the process gets terminated.

Has anyone an idea how to fix this? Thanks for your answers :-)

g3rb
Level 1
Level 1
Posts: 6
Joined: Fri Apr 07, 2017 5:21 am

Re: systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by g3rb » Tue Mar 06, 2018 10:20 am

Same for me !

User avatar
Termy
Level 5
Level 5
Posts: 762
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: systemd-inhibit doesnt work with cinnamon gui shutdown button

Post by Termy » Wed Mar 07, 2018 11:45 am

Use nohup before your command; it keeps the process alive, if the HUP signal is sent to it. Might help. You can also tell your script what to do if it detects the HUP (or other) signal, using the trap builtin -- see help trap. Example usage of the trap command:

Code: Select all

#!/bin/bash

trap 'printf "\nSignal HUP (1) or INT (2) detected.\n"' HUP INT

for INT in {9..1}; {
        printf "\rSleeping for %d second(s)..." "$INT"
        /bin/sleep 1s
}

printf "\nThe script executed without being hung up.\n"
Send the HUP or INT signal during the 9-second countdown (with kill or ^C) to see it work.
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

Post Reply

Return to “Scripts & Bash”