You are not logged in.

#1 2023-05-23 17:31:00

donaastor
Member
Registered: 2022-03-14
Posts: 68

[SOLVED]How to run a custom root process at each boot or user's login?

I want my system to run a custom process with root privileges whenever the system boots or some user logs in a tty (that's what's called start a session, right?), but I don't have any idea how this would be done.

Specifically, I want to run specific programs in specific chroot-ed environments, but I don't want to set them up every time I start a program or even type my password. I want to keep my keyboard shortcuts for running them. So, my idea was to start a script (bash script) which will listen to a pipe or something and whenever a specific character, say '3', gets read from the pipe, the script starts a new instance of the program number 3, as regular user, after it prepares the chroot environment for it using its root privileges. Then, my keyboard shortcuts would only write a single character to the pipe.

So, how to run an elevated bash script at boot time?

Last edited by donaastor (2023-05-23 18:34:56)

Offline

#2 2023-05-23 18:05:39

ua4000
Member
Registered: 2015-10-14
Posts: 420

Re: [SOLVED]How to run a custom root process at each boot or user's login?

have a look at https://wiki.archlinux.org/title/System … unit_files, to run a script as root or another user, or https://wiki.archlinux.org/title/Systemd/User to run it under your own user.

But your request sounds strange, you should specify your request more in detail, which script or program do you want to start, under which condition.

Also I don't understand your idea with keyboard, pipe and specific character.

Offline

#3 2023-05-23 18:29:20

donaastor
Member
Registered: 2022-03-14
Posts: 68

Re: [SOLVED]How to run a custom root process at each boot or user's login?

ua4000 wrote:

...

Thank you! You actually answered my question completely. It's strange that searches on internet didn't suggest me the systemd... I am sorry that I explained my intentions poorly. They are kind of a digression from the topic... I put it there just so that people could suggest some alternative methods of achieving what I need, maybe even without running a root script. That's because I still believed it might not have been possible. You reminded me that it is.

For the sake of completeness, my idea was an abstract construct of a solution to my main task: how to run specific programs under their respective chroot environment WITHOUT elevating myself to root every time. Since it was still abstract, I meant to specify the exact contents of my scripts after I learn what kind of boot-time executions are possible. That's why I didn't provide the script in the question. The idea for the contents of the script is: 1. create a pipe (the type of file) in a tmpfs, for example: `/tmp/chroot_requests` 2. read on it in a loop: char by char or line by line 3. after each reading, find the read string in a predefined table (table of key-value pairs) and read the associated program 4. run the script for that specific program (which should take care of preparing a chrooted environment: prepare the folder, mount things, then chroot in there calling the command `sudo -u user program`...) EDIT: I forgot about the keyboard. I have set keyboard shortcuts for starting various programs, for example: Ctrl+Alt+V is for starting the browser. After this change in my system, this shortcut will write the character 'V' or the whole string "browser" to the file `/tmp/chroot_requests`, then my script should catch it and process it as I have defined and finally start my browser in a chrooted environment. That all happens without me ever setting up the environment or typing my root password.

That was my idea in more detail. I didn't want to implement it before I knew it is even possible to run it as it is meant to be run.

Last edited by donaastor (2023-05-23 18:32:27)

Offline

Board footer

Powered by FluxBB