On an RHEL7.X box, I have created a custom service for systemd at /etc/systemd/system/myService@.service
[Unit]
Description="myService Instance : %i"
#Wants=network-online.target
[Service]
User=%i
Group=%i
<remainder of myService@.service file>
Its working where I can see the CGroup/Systemd-slice list of processes after startup
[myInstance@myHostname config]$ systemctl status myService@myInstance
● myService@myInstance.service - "myService Instance : myInstance"
Loaded: loaded (/etc/systemd/system/myService@.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-04-10 19:11:43 BST; 1h 24min ago
Main PID: 15042 (myMainProcess)
Status: "Restarted all services successfully"
CGroup: /system.slice/system-myService.slice/myService@myInstance.service
├─15042 /myPathTo/myInstance/bin/myMainProcess -c 20319 -m 20320
├─16918 /myPathTo/myInstance/bin/myOtherProc1
└─17440 /myPathTo/myInstance/bin/myOtherProc2
But occasionally I need to login manually as USER=myInstance to manually action a few things including starting additional services, but when I start a new process in this SUDO session, I understandably have a different CGROUP context
sudo su - myInstance
bash-4.2$ % myNewManualProcess3 &
[1] 7665
bash-4.2$ ps -o cgroup -p 7665
CGROUP
11:devices:/user.slice,1:name=systemd:/user.slice/user-0.slice/session-22808.scope
In ideal world, I'd like all commands from that SUDO login-session to be in the Systemd-based CGROUP:
/system.slice/system-myService.slice/myService@myInstance.service
But I would settle for the ability to start a new process with the correct CGROUP context.
Either way at the end of the day, I am hoping to see something like this. Not just for visual purposes, but systemd monitoring/mgmt, especially on "systemctl stop myService@myInstance"
[myInstance@myHostname config]$ systemctl status myService@myInstance
● myService@myInstance.service - "myService Instance : myInstance"
Loaded: loaded (/etc/systemd/system/myService@.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-04-10 19:11:43 BST; 1h 24min ago
Main PID: 15042 (myMainProcess)
Status: "Restarted all services successfully"
CGroup: /system.slice/system-myService.slice/myService@myInstance.service
├─15042 /myPathTo/myInstance/bin/myMainProcess -c 20319 -m 20320
├─16918 /myPathTo/myInstance/bin/myOtherProc1
└─17440 /myPathTo/myInstance/bin/myOtherProc2
└─7665 /myPathTo/myInstance/bin/myNewManualProcess3
I can imagine all sorts of security arguments against trying this, but can we assume for now proper network/SUDO security is in place against unauthorized users and skip that type of answer. If there is a stablity argument against doing this, that would be intereseting to hear.
I would also like to avoid an alternative solution where we add a "launcher" service or shell in the original systemd startup context and then trying to attach to it, like with a "screen" session. I am really just trying to find a solution with CGROUP context switching.
Thanks In Advance!