With the following example, you should be able to see, that lxc list
will escape to the user.slice
.
Write the following bash script to /root/lister.sh
and make it executable.
#!/bin/bash
while true; do
/snap/bin/lxc list
sleep 1
done
Write the following service file to /etc/systemd/system/lister.service
[Unit]
Description=lister
After=network.target
[Service]
Type=simple
ExecStart=/root/lister.sh
StandardOutput=null
StandardError=null
[Install]
WantedBy=multi-user.target
Run systemctl daemon-reload && systemctl start lister.service
to start the service.
Repeatedly check the output from systemctl --user status
and systemctl status lister.service
to catch a running lxc list
process.
You will notice that lxc list
will never appear in the process tree of lister.service
(like I would expect), but always in user@0.service
.
Here is my output from systemctl --user status
:
● system-1-dc
State: running
Jobs: 0 queued
Failed: 0 units
Since: Fri 2022-12-02 09:21:54 CET; 6min ago
CGroup: /user.slice/user-0.slice/user@0.service
├─app.slice
│ ├─dbus.service
│ │ └─1319131 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
│ └─snap.lxd.lxc.75f6210c-a78a-47de-af5b-3235a2e67b51.scope
│ └─1325357 /snap/snapd/17883/usr/lib/snapd/snap-confine --base core20 snap.lxd.lxc /usr/lib/snapd/snap-exec lxd.lxc list
└─init.scope
├─1318832 /lib/systemd/systemd --user
└─1318833 (sd-pam)
Here is my output from systemctl status lister.service
:
● lister.service - lister
Loaded: loaded (/etc/systemd/system/lister.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2022-12-02 09:28:05 CET; 7s ago
Main PID: 1324702 (lister.sh)
Tasks: 1 (limit: 9404)
Memory: 404.0K
CPU: 407ms
CGroup: /system.slice/lister.service
└─1324702 /bin/bash /root/lister.sh