Start script just before user get login screen

Leap 15.6 and next 16.1

Hello.

The goal is to force a reboot to another system and this 4 times per year.
So during the months of January, April, July, and October, the operator is asked which system he wants to restart.
If on the 30th of the month, no reboot has been carried out by an operator, the system will reboot automatically to another predefined system.
After a reboot has been done no more question to operator until the next month period.

I have created all the scripts.
The final script uses:

  • grub2-once --list
  • grub2-ounce $CHOICE
  • shutdown -r now

First question:
If I use the Kde user autostart function, how can I lock the operator in the window running the script until it answers yes or no, without being able to leave the window?

Second question:
Is it possible to launch my application in a bash konsole by a systemd “TEST_REBOOT” service before the user’s login is shown; and stay until the “TEST_REBOOT” service ended ( by an answer from the operator ).

Any help is welcome

@jcdole just create a systemd timer and service to go off on the time/date etc…

There is also rebootmgr https://github.com/SUSE/rebootmgr

Thank you for helping.

I have made ten’s tries without success.

This is an interactive application, not driven by timer.

A)
If using kde autostart functionality, how to stick the user in the window script until operator’s anwser has been made.

B)
If using a systemd service (in /etc/systemd/system) , I never be able to show my bash script running in a konsole and then cannot answer to the question

What happens before user login on the DE, is out of control of that user.

Then you need to create your own login profile in /etc/profile.d crafted to your requirements…

For example, I use tty1 for login on Hyprland via a drop-in to /etc/profile.d

cat /etc/profile.d/hyprland.sh

if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" == 1 ]; then
  exec start-hyprland > /dev/null 2>&1
fi
1 Like

Thank you for helping

If run under systemd, I suppose that the my main script is started and run by root (-id 0).
If run under kde autostart script before user log in, must find a way run the final command as root without knowing the root password. Must stay in the script window until the operator answer yes/no.
If run under kde autostart script after user log in, must find a way run command as root without knowing the root password. Must stay in the script window until the operator answer yes/no.

@jcdole you can use a sudo drop in to allow a command to run as the designated user…

Anyways, you cannot do this through the user’s kde autostart. That works after user login. There are 3 stages

  • the pre plasma desktop
  • plasma desktop
    The system does not know something like “just before user get login screen”. It does not know which user is going to login until the user does.
  • the post plasma desktop

I am sorry but I do not understand what you mean by “sudo drop in to allow a command to run as the designated user”

On the other hand, all users are concerned.
And none of them know the “root” password.

In short I need something like :

make systemd-logind.service dependent of service 'reboot is finished'

Set an env var 'reboot is pending' (if in good month) from crontab @reboot ( user later by main script )
Check when X server is running via a systemd service
when  X server is running,  start bash script 'ask_for_reboot' in a konsole or xterm
    if env var 'reboot is pending' is not set then 
        reset env var 'reboot is pending'
        start systemd service 'reboot is finished'
    else
        ask operator if he wants to reboot to another system
        if yes
            reboot that clear every things
        else
            reset env var 'reboot is pending'
            start systemd service 'reboot is finished'
        fi
    fi
systemd-logind.service is activate

Is it consistent?

IMNSHO No. But because I see absolutely no sense in this whole effort. Maybe others do.