Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

0 votes
0 answers
22 views
Restart systemd service *without* restarting dependents
I have four `systemd` services: `{a,b,c,d}.service`. `d.service` is the "main" service, and it is the one that parses the configuration file for all four. Typically, the four are started together. To make it easier to apply configuration changes, I have marked `{a,b,c}.service` as `PartOf=d.service`...
I have four systemd services: {a,b,c,d}.service. d.service is the "main" service, and it is the one that parses the configuration file for all four. Typically, the four are started together. To make it easier to apply configuration changes, I have marked {a,b,c}.service as PartOf=d.service in their unit files. That way, when I restart d.service, the configuration changes are applied across all four services. However, there are circumstances (debugging, for example) where I want to **only** restart d.service without affecting {a,b,c}.service. Is there a way for me to do this, either through options for the systemctl restart command or through unit file configurations? I could also, I suppose, make a wrapper service - e.service - that contains {a,b,c,d}.service and then restart that when I want to apply config changes. I wanted to see if there was a way to do this without adding a fifth service, though. This is perhaps a misuse of systemd, and I'll gladly take recommendations for ways that I can structure this configuration better.
chrysolepis (1 rep)
Aug 6, 2025, 01:00 PM • Last activity: Aug 6, 2025, 02:55 PM
3 votes
1 answers
39 views
How to start multiple systemd services within a target sequentially
I have a large set of systemd services that are part of a single target running on an embedded system with a relatively slow file system. When starting the target, our most significant startup delay is due to loading the application from the filesystem into memory. When the target is started, System...
I have a large set of systemd services that are part of a single target running on an embedded system with a relatively slow file system. When starting the target, our most significant startup delay is due to loading the application from the filesystem into memory. When the target is started, SystemD starts all services simultaneously, and we occasionally miss the service's TimeoutSec delay for some applications. We could increase the TimeoutSec to increase the delay, but I'm interested in whether we can improve the overall system startup by having SystemD start only 1 service at a time and not thrashing the i/o. We could use the service unit wants/after/requires etc. to enforce a specific startup ordering, but the ordering doesn't matter. Is there a way, without requiring specific ordering, to tell SystemD to start the services within a target 1 at a time?
T. Waters (31 rep)
Aug 1, 2025, 04:39 PM • Last activity: Aug 1, 2025, 07:17 PM
0 votes
0 answers
23 views
Maintainer scripts to remove excessive dependency symlinks for services
I have a package to maintain, which has a `WantedBy` dependency. It must also save it's state after being updated (enabled/disabled, active/inactive after package was updated). Suddenly I needed to change `WantedBy` dependency from one service to another (`WantedBy A.service` to `WantedBy B.service`...
I have a package to maintain, which has a WantedBy dependency. It must also save it's state after being updated (enabled/disabled, active/inactive after package was updated). Suddenly I needed to change WantedBy dependency from one service to another (WantedBy A.service to WantedBy B.service) and I felt puzzled when I tried to find debhelper options for that. I did not find any way to delete previous dependency on update autoamtically without meddling with postinst script. Is there a proper way to do so via debhelper auto-generated scripts? ATM I'm using dh_installsystemd like that to save service state:
override_dh_installsystemd:
	dh_installsystemd --no-enable --restart-after-upgrade --no-start
It updates service and saves it's state and overall works fine except for removing excessive service dependencies. If there is no way to do that via dh, is there any other good standard way? It seems strange that it was not implemented by default. Why isn't it done on deb-systemd-helper enable my_package.service?
modd1e (13 rep)
Jul 29, 2025, 07:21 AM • Last activity: Jul 29, 2025, 12:24 PM
2 votes
2 answers
4058 views
How to prevent SElinux from blocking custom systemd service at boot?
SElinux is preventing a custom service of mine from getting picked up by systemd at boot. > MESSAGE=SELinux is preventing systemd from read access on the file custom.service #### before rebooting ``` [root@box opt]# systemctl daemon-reload [root@box opt]# systemctl enable --now custom [root@box opt]...
SElinux is preventing a custom service of mine from getting picked up by systemd at boot. > MESSAGE=SELinux is preventing systemd from read access on the file custom.service #### before rebooting
[root@box opt]# systemctl daemon-reload
[root@box opt]# systemctl enable --now custom
[root@box opt]# systemctl status custom.service
● custom.service - foo
   Loaded: loaded (/opt/foo/bar/systemd/custom.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-10-07 12:18:27 EDT; 1min 28s ago
...
...
#### after reboot
[root@box opt]# systemctl status custom.service
Unit custom.service could not be found.
So I disabled selinux and rebooted but it didn’t seem to help anything. I then changed the selinux user, role, and type of the service file and tried a reboot again.
[root@box opt]# chcon -R -u unconfined_u -r object_r -t systemd_unit_file_t foo/bar/systemd/
Still nothing... Then I noticed that the symlink I placed in /etc/systemd/system was showing a ? for the secontext. The same thing happens if I cp the service file into the /etc/systemd/system directory too.
[root@box opt]# ls -Z /etc/systemd/system/custom.service
? /etc/systemd/system/custom.service
Anyone know what needs to be done here to fix this? **TLDR** - SElinux is preventing systemd from reading an enabled custom systemd unit even though selinux is disabled.
Cory W. (21 rep)
Oct 7, 2022, 05:27 PM • Last activity: Jul 28, 2025, 01:20 PM
1 votes
1 answers
36 views
systemd: how to make unit to only react on other unit start or maunal start
I need to write a systemd unit that: - starts if another specified unit was started; - starts if started manually; - **do not** start at boot if specified unit didn't start at boot; - **do not** stop if specified unit was stopped (so `Requires` or `Requisite` will not do the job fully) and **do not*...
I need to write a systemd unit that: - starts if another specified unit was started; - starts if started manually; - **do not** start at boot if specified unit didn't start at boot; - **do not** stop if specified unit was stopped (so Requires or Requisite will not do the job fully) and **do not** stop specified unit if stopped itself. Is there any way to make such unit? Preferably without any additional auxillary units.
modd1e (13 rep)
Jul 18, 2025, 02:03 PM • Last activity: Jul 18, 2025, 03:01 PM
2 votes
1 answers
5447 views
systemd: my service stopped working with code=killed
My service has suddenly stopped working, `systemctl status` reports: Main PID: 5459 (code=killed, signal=TERM) Also, I checked through `journald` for my service (`journalctl -u myservice.service`) and the last entry is: systemd[1]: Stopped MyService Service. Does this mean it was manually stopped wi...
My service has suddenly stopped working, systemctl status reports: Main PID: 5459 (code=killed, signal=TERM) Also, I checked through journald for my service (journalctl -u myservice.service) and the last entry is: systemd: Stopped MyService Service. Does this mean it was manually stopped with systemctl stop or it might as well mean it has crashed? Is there a way to tell?
Mark (1943 rep)
Jun 7, 2022, 09:23 PM • Last activity: Jul 2, 2025, 07:08 PM
1 votes
1 answers
5228 views
systemd: Failed to start Application launched by gnome-session-binary
If you check the error log it comes to that `.scope` unit is not found - `No such process`. I got similar error 4 times. I would like to understand what is going on during the boot process. Why these errors appear? How to debug it to find even more details? The full log ------------ First three erro...
If you check the error log it comes to that .scope unit is not found - No such process. I got similar error 4 times. I would like to understand what is going on during the boot process. Why these errors appear? How to debug it to find even more details? The full log ------------ First three errors appear in this part
...
Jan 05 13:42:51 magnetron systemd: Starting GNOME Session Manager (session: gnome)...
░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ A start job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 393.
Jan 05 13:42:51 magnetron gnome-keyring-daemon: The PKCS#11 component was already initialized
Jan 05 13:42:51 magnetron gnome-keyring-d: The PKCS#11 component was already initialized
Jan 05 13:42:51 magnetron gnome-keyring-daemon: The Secret Service was already initialized
Jan 05 13:42:51 magnetron gnome-keyring-secrets.desktop: discover_other_daemon: 1GNOME_KEYRING_CONTROL=/run/user/1000/keyring
Jan 05 13:42:51 magnetron gnome-keyring-secrets.desktop: SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
Jan 05 13:42:51 magnetron gnome-keyring-pkcs11.desktop: discover_other_daemon: 1GNOME_KEYRING_CONTROL=/run/user/1000/keyring
Jan 05 13:42:51 magnetron gnome-keyring-pkcs11.desktop: SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
Jan 05 13:42:51 magnetron gnome-keyring-ssh.desktop: discover_other_daemon: 1GNOME_KEYRING_CONTROL=/run/user/1000/keyring
Jan 05 13:42:51 magnetron gnome-keyring-ssh.desktop: SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
Jan 05 13:42:51 magnetron gnome-keyring-d: The Secret Service was already initialized
Jan 05 13:42:51 magnetron gnome-keyring-daemon: discover_other_daemon: 1
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dpkcs11-2742.scope: Couldn't move process 2742 to requested cgroup '/user.slice/user-1000.slice/user@1000.service/app.slice/app-gnome-gnome\x2
dkeyring\x2dpkcs11-2742.scope': No such process
Jan 05 13:42:51 magnetron gnome-keyring-daemon: discover_other_daemon: 1
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dpkcs11-2742.scope: Failed to add PIDs to scope's control group: No such process
Jan 05 13:42:51 magnetron gnome-keyring-daemon: discover_other_daemon: 1
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dpkcs11-2742.scope: Failed with result 'resources'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'resources'.
Jan 05 13:42:51 magnetron systemd: Failed to start Application launched by gnome-session-binary.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ A start job for unit UNIT has finished with a failure.
░░ 
░░ The job identifier is 450 and the job result is failed.
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dsecrets-2743.scope: Couldn't move process 2743 to requested cgroup '/user.slice/user-1000.slice/user@1000.service/app.slice/app-gnome-gnome\x2dkeyring\x2dsecrets-2743.scope': No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dsecrets-2743.scope: Failed to add PIDs to scope's control group: No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dsecrets-2743.scope: Failed with result 'resources'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'resources'.
Jan 05 13:42:51 magnetron systemd: Failed to start Application launched by gnome-session-binary.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ A start job for unit UNIT has finished with a failure.
░░ 
░░ The job identifier is 454 and the job result is failed.
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dssh-2740.scope: Couldn't move process 2740 to requested cgroup '/user.slice/user-1000.slice/user@1000.service/app.slice/app-gnome-gnome\x2dkeyring\x2dssh-2740.scope': No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dssh-2740.scope: Failed to add PIDs to scope's control group: No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-gnome\x2dkeyring\x2dssh-2740.scope: Failed with result 'resources'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'resources'.
Jan 05 13:42:51 magnetron systemd: Failed to start Application launched by gnome-session-binary.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ A start job for unit UNIT has finished with a failure.
...
The last error is at different place in the log:
Jan 05 13:42:51 magnetron gnome-session: gnome-session-binary: GnomeDesktop-WARNING: Could not create transient scope for PID 2747: GDBus.Error:org.freedesktop.DBus.Error.UnixProcessIdUnknown: Process with ID 2747 does not exist.
Jan 05 13:42:51 magnetron gnome-session-binary: GnomeDesktop-WARNING: Could not create transient scope for PID 2747: GDBus.Error:org.freedesktop.DBus.Error.UnixProcessIdUnknown: Process with ID 2747 does not exist.
Jan 05 13:42:51 magnetron gnome-session: gnome-session-binary: GnomeDesktop-WARNING: Could not create transient scope for PID 2749: GDBus.Error:org.freedesktop.DBus.Error.UnixProcessIdUnknown: Process with ID 2749 does not exist.
Jan 05 13:42:51 magnetron gnome-session-binary: GnomeDesktop-WARNING: Could not create transient scope for PID 2749: GDBus.Error:org.freedesktop.DBus.Error.UnixProcessIdUnknown: Process with ID 2749 does not exist.
Jan 05 13:42:51 magnetron systemd: app-gnome-at\x2dspi\x2ddbus\x2dbus-2752.scope: Couldn't move process 2752 to requested cgroup '/user.slice/user-1000.slice/user@1000.service/app.slice/app-gnome-at\x2dspi\x2ddbus\x2dbus-2752.scope': No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-at\x2dspi\x2ddbus\x2dbus-2752.scope: Failed to add PIDs to scope's control group: No such process
Jan 05 13:42:51 magnetron systemd: app-gnome-at\x2dspi\x2ddbus\x2dbus-2752.scope: Failed with result 'resources'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ The unit UNIT has entered the 'failed' state with result 'resources'.
Jan 05 13:42:51 magnetron systemd: Failed to start Application launched by gnome-session-binary.
░░ Subject: A start job for unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support 
░░ 
░░ A start job for unit UNIT has finished with a failure.
░░
My system is Debian Bookworm: uname -a ``` Linux magnetron 6.0.0-6-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.0.12-1 (2022-12-09) x86_64 GNU/Linux
tukan (6575 rep)
Jan 5, 2023, 01:49 PM • Last activity: Jun 12, 2025, 11:03 AM
0 votes
1 answers
117 views
Systemd fails to restart a Python script with exit(0)
I have a working python script and systemd service script. But somehow it is not working the way I wanted it. The python script prints time every 5s but stops with exit(0) at first second of a minute. This is fine. The systemd seems to be working fine for the first time. Once the python script stops...
I have a working python script and systemd service script. But somehow it is not working the way I wanted it. The python script prints time every 5s but stops with exit(0) at first second of a minute. This is fine. The systemd seems to be working fine for the first time. Once the python script stops, it fails to restart. My python script: test_python_script_auto_run_linux_raspberrypi.py from datetime import datetime import schedule def print_time_now(): time_now = datetime.now() print("%s : This is the time now"%(time_now)) def stop_the_script(): time_now = datetime.now() print("%s : Stopping the script ..."%(time_now)) # Clean exit with no errors exit(0) schedule.every(5).seconds.do(print_time_now) schedule.every().minute.at(":01").do(stop_the_script) while True: schedule.run_pending() sudo nano /etc/systemd/system/testpythonpcriptautorunmm.service [Unit] Description=Testing my python script for auto restart After=multi-user.target [Service] Type=simple Restart=always RestartSec=60 ExecStart=/usr/bin/python3 /home/pi/Documents/RaspberryPi_projects/ExamplEScripts_Practice_MM_20221209/test_python_script_auto_run_linux_raspberrypi.py [Install] WantedBy=multi-user.target Terminal commands: pi@raspberrypi:~ $ sudo systemctl status testpythonpcriptautorunmm.service ● testpythonpcriptautorunmm.service - Testing my python script for auto restart Loaded: loaded (/etc/systemd/system/testpythonpcriptautorunmm.service; enabled; vendor preset: enabled) Active: inactive (dead) since Wed 2024-06-19 12:38:01 EDT; 40s ago Process: 816 ExecStart=/usr/bin/python3 /home/pi/Documents/RaspberryPi_projects/ExamplEScripts_Practice_MM_20221209/test_python_script_auto_run_linux_raspberrypi.py (code=exited, status=0/SU Main PID: 816 (code=exited, status=0/SUCCESS) Jun 19 12:37:12 raspberrypi systemdReferenced image: Started Testing my python script for auto restart. Jun 19 12:38:01 raspberrypi python3: 2024-06-19 12:37:17.883550 : This is the time now Jun 19 12:38:01 raspberrypi python3: 2024-06-19 12:37:57.454879 : This is the time now Jun 19 12:38:01 raspberrypi python3: 2024-06-19 12:38:01.000049 : Stopping the script ... Jun 19 12:38:01 raspberrypi systemdReferenced image: testpythonpcriptautorunmm.service: Succeeded. lines 1-11/11 (END) When I run the python script on same raspberry pi using Thonny IDE: enter image description here What could be the problem? Why does the systemd service fail to restart the script after a successful first run? **Edit:** Updated systemd service: [Unit] Description=Testing my python script for auto restart After=multi-user.target [Service] Type=simple Restart=always #on-failure#always RestartSec=10 WatchdogSec=60 ExecStart=/usr/bin/python3 /home/pi/Documents/RaspberryPi_projects/ExamplEScripts_Practice_MM_20221209/test_python_script_auto_run_linux_raspberrypi.py RemainAfterExit=yes [Install] WantedBy=multi-user.target Terminal response: pi@raspberrypi:~ $ sudo nano /etc/systemd/system/testpythonpcriptautorunmm.service pi@raspberrypi:~ $ sudo systemctl status testpythonpcriptautorunmm.service ● testpythonpcriptautorunmm.service - Testing my python script for auto restart Loaded: loaded (/etc/systemd/system/testpythonpcriptautorunmm.service; enabled; vendor preset: enabled) Active: active (exited) since Wed 2024-06-19 13:07:22 EDT; 4min 6s ago Process: 1621 ExecStart=/usr/bin/python3 /home/pi/Documents/RaspberryPi_projects/ExamplEScripts_Practice_MM_20221209/test_python_script_auto_run_linux_raspberrypi.py (code=exited, status=0/S Main PID: 1621 (code=exited, status=0/SUCCESS) Jun 19 13:07:22 raspberrypi systemdReferenced image: Started Testing my python script for auto restart. Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:27.438964 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:32.439073 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:37.439153 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:42.439228 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:47.439308 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:52.439386 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:07:57.439471 : This is the time now Jun 19 13:08:01 raspberrypi python3: 2024-06-19 13:08:01.000031 : Stopping the script ... pi@raspberrypi:~ $ As per this new update, the script seems to be active after 4 minutes of operation but failed to run the script. Don't know why?
Mainland (115 rep)
Jun 19, 2024, 04:20 PM • Last activity: Jun 5, 2025, 06:32 AM
4 votes
2 answers
2872 views
systemd unit indirect status
I wonder how can I check which unit activates another with status indirect? I run Arch with Gnome and a Debian server. On my Debian machine I can see that output for ```systemctl list-unit-files --type=target --state=enabled``` shows, as expected: ``` default.target enabled multi-user.target enabled...
I wonder how can I check which unit activates another with status indirect? I run Arch with Gnome and a Debian server. On my Debian machine I can see that output for
list-unit-files --type=target --state=enabled
shows, as expected:
default.target    enabled
multi-user.target enabled
But on Arch desktop, surprisingly for me, it doesn't, although both:
-user.target
and
.target
(my default on arch) are active. When I check the status of these units files they are both:
. When I list-dependencies for
.target
it shows
.service
and
-user.target
. In gdm unit file I do not see
=
in
[Install]
section. So what exactly activates
.target
? What is the reason of this "indirect" solution?
Maciek (193 rep)
Apr 11, 2020, 10:43 AM • Last activity: May 12, 2025, 01:10 PM
0 votes
1 answers
1943 views
Enable service for specific user Only (UBUNTU)
1. Currently writing a service unit file in Ubuntu, i want the service to be enabled for one user UserA only. The service will run automatically when UserA login but not for other users. How can I do this? Below is my unit file placed in /etc/system ``` [Unit] Description=Test unit [Service] ExecSta...
1. Currently writing a service unit file in Ubuntu, i want the service to be enabled for one user UserA only. The service will run automatically when UserA login but not for other users. How can I do this? Below is my unit file placed in /etc/system
[Unit]
Description=Test unit

[Service]
ExecStart=/bin/sh -c 'echo test > /home/UserA/sysdworking'

[Install]
WantedBy=multi-user.target
2. Is this a common practice? or all services should be system wide ?
Hawii Hawii (1 rep)
Oct 22, 2020, 06:00 AM • Last activity: Apr 26, 2025, 05:04 AM
0 votes
0 answers
34 views
system service: scheduling a variable timer
I am writing a program that I would like to have the ability to schedule an action. This would work similar to the the `TIME` option in `shutdown`, where the user specifies a time and that information gets stored in a temporary file: `/run/systemd/shutdown/scheduled` Which contains a set of variable...
I am writing a program that I would like to have the ability to schedule an action. This would work similar to the the TIME option in shutdown, where the user specifies a time and that information gets stored in a temporary file: /run/systemd/shutdown/scheduled Which contains a set of variables:
USEC=1742499354904002
WARN_WALL=1
MODE=reboot
UID=0
TTY=pts/0
At first I thought I could do something similar by having a service check for the existence of that file (with ConditionPathExists). If that file exists, read in those variables and start a second service that runs the program and has a temporary timer file, maybe like:
[Timer]
Environment=/run/systemd/customprogram/scheduled
OnCalendar=$(date -d "@${USEC}"  +"%a %Y-%m-%d %H:%M:%S") # converted
But systemd timers do not allow the Environment unit. It seems that shutdown does not use systemd timers but invokes some other method see here . Is there a simplistic, automated way to read a file to schedule a process with a variable time? I was designing this as a service because I would also be like to be able to send a signal to cancel or update the time as this program should only run a single instance at the "next" scheduled time.
andiegoonie (1 rep)
Apr 7, 2025, 08:54 PM
0 votes
1 answers
121 views
User systemd exited and removed semaphores
I use a `systemd` service to start several processes when Ubuntu 20.04 starts up. # MyApp start app service [Unit] Description=MyApp start service Requires=network-online.target After=network-online.target [Service] Type=simple ExecStartPre=/bin/sleep 20 ExecStart=/etc/init.d/MyApp.sh start ExecStop...
I use a systemd service to start several processes when Ubuntu 20.04 starts up. # MyApp start app service [Unit] Description=MyApp start service Requires=network-online.target After=network-online.target [Service] Type=simple ExecStartPre=/bin/sleep 20 ExecStart=/etc/init.d/MyApp.sh start ExecStop=/etc/init.d/MyApp.sh stop LimitMEMLOCK=infinity LimitCORE=infinity RemainAfterExit=yes User=admin [Install] #WantedBy=multi-user.target #WantedBy=graphical.target WantedBy=basic.target All my processes start after the system boots. However, after several minutes, the user-level systemd exits and removes all semaphores that were created by my processes. It seems that I can set RemoveIPC=No configuration in /etc/systemd/logind.conf to prevent user systemd from removing the semaphores. However, why did user systemd exit? Should I use the command sudo loginctl enable-linger admin to prevent it from exiting? Thanks!
sfzhang (103 rep)
Mar 14, 2025, 09:35 AM • Last activity: Apr 2, 2025, 02:31 PM
0 votes
0 answers
67 views
Why does systemd restart my (healthy) service?
I have a systemd service for an application that is the primary workload for the machine it is running on. In my logs, I see that systemd restarts this service and as far as I can tell, the service is perfectly healthy at the time this happens. The VM runs in an AWS auto-scaling group and has a max...
I have a systemd service for an application that is the primary workload for the machine it is running on. In my logs, I see that systemd restarts this service and as far as I can tell, the service is perfectly healthy at the time this happens. The VM runs in an AWS auto-scaling group and has a max lifetime of 25 hours, and yet, for many of the instances, it shuts down this service in the early morning (more or less the same time every day). In the app logs I can see that it receives the SIGINT from systemd and then shuts itself down correctly. Then systemd restarts it immediately afterwards. The journalctl -u service-name shows this when it happens.
normal expected operational logs
...
Mar 26 06:26:12 ip-172-31-107-114 systemd: Stopping service-name.service - service description...
...
logs indicating clean shutdown
...
Mar 26 06:26:26 ip-172-31-107-114 systemd: service-name.service: Deactivated successfully.
Mar 26 06:26:26 ip-172-31-107-114 systemd: Stopped service-name.service - service-description
Mar 26 06:26:26 ip-172-31-107-114 systemd: service-name.service: Consumed 12h 56min 50.136s CPU time, 4.8G memory peak, 0B memory swap peak.
Mar 26 06:26:26 ip-172-31-107-114 systemd: Starting service-name.service - service-description
Mar 26 06:26:27 ip-172-31-107-114 systemd: Started service-name.service - service-description
...
logs indicating healthy start
The unit file looks like this:
[Unit]
Description=service-description
After=cloud-final.service

[Service]
ExecStartPre=+/opt/vendor/setup-systemd-environment-file.sh
EnvironmentFile=-/etc/vendor/file.conf
ExecStart=/opt/vendor/launcher.sh
Restart=always
User=serviceuser
Group=serviceuser

[Install]
WantedBy=cloud-init.target
Pieter Breed (101 rep)
Mar 26, 2025, 08:06 AM
0 votes
1 answers
51 views
Is it safe to clean up (delete) references to missing systemd units?
## List missing services ```bash systemctl --state=not-found --all ``` Output: UNIT LOAD ACTIVE SUB DESCRIPTION ● boot.automount not-found inactive dead boot.automount ● home.mount not-found inactive dead home.mount ● tmp.mount not-found inactive dead tmp.mount ● connman.service not-found inactive d...
## List missing services
systemctl --state=not-found --all
Output: UNIT LOAD ACTIVE SUB DESCRIPTION ● boot.automount not-found inactive dead boot.automount ● home.mount not-found inactive dead home.mount ● tmp.mount not-found inactive dead tmp.mount ● connman.service not-found inactive dead connman.service ● console-screen.service not-found inactive dead console-screen.service ● dpdk.service not-found inactive dead dpdk.service ● fcoe.service not-found inactive dead fcoe.service ● firewalld.service not-found inactive dead firewalld.service ● haveged.service not-found inactive dead haveged.service ● ip6tables.service not-found inactive dead ip6tables.service ● iptables.service not-found inactive dead iptables.service ● iscsi-shutdown.service not-found inactive dead iscsi-shutdown.service ● iscsi.service not-found inactive dead iscsi.service ● iscsid.service not-found inactive dead iscsid.service ● kbd.service not-found inactive dead kbd.service ● rbdmap.service not-found inactive dead rbdmap.service ● systemd-hwdb-update.service not-found inactive dead systemd-hwdb-update.service ● systemd-oomd.service not-found inactive dead systemd-oomd.service ● systemd-update-done.service not-found inactive dead systemd-update-done.service ● systemd-vconsole-setup.service not-found inactive dead systemd-vconsole-setup.service ● xencommons.service not-found inactive dead xencommons.service ● xendomains.service not-found inactive dead xendomains.service ● virtlxcd.socket not-found inactive dead virtlxcd.socket ● virtqemud.socket not-found inactive dead virtqemud.socket ● virtvboxd.socket not-found inactive dead virtvboxd.socket ● virtvzd.socket not-found inactive dead virtvzd.socket ● virtxend.socket not-found inactive dead virtxend.socket ## Find units which reference missing services
grep -rR "" /usr/lib/systemd
grep -rR "" /etc/systemd

# See tables in man page for more directories to search with grep and to learn their purpose
man systemd.unit
Sample for tmp.mount
grep -rR "tmp.mount" /usr/lib/systemd
grep -rR "tmp.mount" /etc/systemd
Output: /usr/lib/systemd/system/basic.target:After=sysinit.target sockets.target paths.target slices.target tmp.mount /usr/lib/systemd/system/basic.target:Wants=tmp.mount ## Clean up references
sudo nano /usr/lib/systemd/system/basic.target
Contents:
[Unit]
Description=Basic System
Documentation=man:systemd.special(7)
Requires=sysinit.target
Wants=sockets.target timers.target paths.target slices.target
After=sysinit.target sockets.target paths.target slices.target tmp.mount

RequiresMountsFor=/var /var/tmp
Wants=tmp.mount
Here we found tmp.mount under After= and Wants= I want to delete these entries so that systemctl --state=not-found --all no longer list it, and so for each missing unit. ## Question Is it safe to delete such entries for every missing unit on system?
metablaster (776 rep)
Mar 15, 2025, 12:16 PM • Last activity: Mar 15, 2025, 12:39 PM
1 votes
0 answers
130 views
How can I use --machine to see another user's units in journalctl?
With systemctl, I can start and stop the user service units of a different user using: ``` sudo systemctl --user --machine=OTHER_USER@ stop their.service ``` How can I achieve this behaviour with journalctl? When I try to pass the `--machine=OTHER_USER@` argument, I get the error: > Failed to open r...
With systemctl, I can start and stop the user service units of a different user using:
sudo systemctl --user --machine=OTHER_USER@ stop their.service
How can I achieve this behaviour with journalctl? When I try to pass the --machine=OTHER_USER@ argument, I get the error: > Failed to open root directory: No machine 'OTHER_USER@' known. My goal here is to see the log messages for a systemd user service unit for a user that I am not currently logged in as.
mallwright (442 rep)
Feb 18, 2025, 10:51 AM
-2 votes
1 answers
256 views
What happens when you run systemctl enable on a unit file that doesn't have an [Install] section?
When you run `systemctl enable` and provide it a service name, what happens if there is no `[Install]` section in the service? ```shell ❯ systemctl enable myapp.service The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultIns...
When you run systemctl enable and provide it a service name, what happens if there is no [Install] section in the service?
❯ systemctl enable myapp.service
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.
 
Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.
This use of systemctl enable returns 0 (success) but if it doesn't do anything it would seem to me like it should be an error?
Evan Carroll (34663 rep)
Feb 12, 2025, 04:34 PM • Last activity: Feb 12, 2025, 04:48 PM
1 votes
1 answers
155 views
Systemd MemoryMax not being applied to service unit
I'm trying to limit the memory usage of a systemd service, but the MemoryMax setting doesn't seem to be applied. Here's my situation: In my service file `/etc/systemd/system/discordsearch.service`, I have set this under `[Service]`: ``` MemoryAccounting=true MemoryMax=2GB ``` However, when I check t...
I'm trying to limit the memory usage of a systemd service, but the MemoryMax setting doesn't seem to be applied. Here's my situation: In my service file /etc/systemd/system/discordsearch.service, I have set this under [Service]:
MemoryAccounting=true
MemoryMax=2GB
However, when I check the service status with systemctl status discordsearch, I see:
Memory: 3.6G
Furthermore, when I run systemctl show discordsearch.service | grep Memory, I get:
MemoryCurrent=1195773952
MemoryAvailable=infinity
MemoryAccounting=yes
MemoryHigh=infinity
MemoryMax=infinity
MemoryLimit=infinity
This shows that MemoryMax is set to infinity, not the 2GB I specified in the service file. I've tried the following: 1. Reloading systemd with sudo systemctl daemon-reload 2. Restarting the service with sudo systemctl restart discordsearch **/etc/systemd/system/discordsearch.service**:
[Unit]
Description=discordsearch

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/djm14qz135r1cfjsid90qryxgsw2i349-glibc-locales-2.37-45/lib/locale/locale-archive"
Environment="PATH=/nix/store/cm1sfanx42miqdzbwd5alxmg9lg96nag-yj-5.1.0/bin:/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/bin:/nix/store/yknc37wfb1hbnmgwmp4bm96rxwzsc692-findutils-4.9.0/bin:/nix/store/bj8a14pqhmvlha8hyv1p8bkd9kmykgjy-gnugrep-3.7/bin:/nix/store/agq64rvl0aj88ckm0kzaqgk2ddq8bvz8-gnused-4.9/bin:/nix/store/f9wkksb3lslf6q90i6c2r3qji7qcp0f2-systemd-253.6/bin:/nix/store/cm1sfanx42miqdzbwd5alxmg9lg96nag-yj-5.1.0/sbin:/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/sbin:/nix/store/yknc37wfb1hbnmgwmp4bm96rxwzsc692-findutils-4.9.0/sbin:/nix/store/bj8a14pqhmvlha8hyv1p8bkd9kmykgjy-gnugrep-3.7/sbin:/nix/store/agq64rvl0aj88ckm0kzaqgk2ddq8bvz8-gnused-4.9/sbin:/nix/store/f9wkksb3lslf6q90i6c2r3qji7qcp0f2-systemd-253.6/sbin"
Environment="TZDIR=/nix/store/x376xyviyrg5rafwk5a261lviv0l9paw-tzdata-2023c/share/zoneinfo"



ExecStart=/nix/store/lj1p39b4sp4k7g6qzdc0m2s6imga9yxy-HaskellNixCabalStarter-0.1.0.0/bin/discord-app
MemoryAccounting=true
MemoryMax=2GB
Restart=always
RestartSec=1
Type=simple
WorkingDirectory=%h/discordsearch
Chris Stryczynski (6603 rep)
Aug 3, 2024, 09:45 AM • Last activity: Feb 8, 2025, 03:59 PM
0 votes
0 answers
63 views
How to reliably bring up systemd.socket?
The interface I am using is called usb0, and I would like to bring it up only on a certain interface. I tried this: ``` ExecStartPre=/usr/lib/systemd/systemd-networkd-wait-online --interface=usb0 ``` But it failed, and would not allow a connection. I then tried this, and got it to work reliably: ```...
The interface I am using is called usb0, and I would like to bring it up only on a certain interface. I tried this:
ExecStartPre=/usr/lib/systemd/systemd-networkd-wait-online --interface=usb0
But it failed, and would not allow a connection. I then tried this, and got it to work reliably:
ExecStartPre=bash -c \
    'while ! (/usr/bin/netcat -v  -w 1 -t -l -p 23 192.168.7.2 2>&1 | grep Connection\ timed\ out) ; do \
         date ; \
         ((i++)); \
         ((i>60)) && echo "telnet.socket wait: Timer expire" && exit 1 ; \
     done;exit 0'
This is what I have that worked (seems like there should be a better way):
[Unit]
Description=Telnet Server Activation Socket
After=systemd-user-sessions.service

[Socket]
ListenStream=192.168.7.2:23
Accept=true
ExecStartPre=bash -c \
    'while ! (/usr/bin/netcat -v  -w 1 -t -l -p 23 192.168.7.2 2>&1 | grep Connection\ timed\ out) ; do \
         date ; \
         ((i++)); \
         ((i>60)) && echo "telnet.socket wait: Timer expire" && exit 1 ; \
     done;exit 0'

[Install]
WantedBy=multi-user.target
So here is another stab at this to eliminate **socat**. Since telnet.socket does not successfully start, it does not need to be enabled. Here is a simpler telnet.socket that also fails when enabled:
[Unit]
Description=Telnet Server Activation Socket

[Socket]
ListenStream=192.168.7.2:23
Accept=true

[Install]
WantedBy=sys-subsystem-net-devices-usb0.device
Now to fix this, I add and enable the following service:
[Unit]
Description=Get telnetd socket up

[Service]
ExecStart=/usr/libexec/telnetd-up/telnetd-up.sh
Type=oneshot
RemainAfterExit=yes
Nice=10

[Install]
WantedBy=sys-subsystem-net-devices-usb0.device
The telnetd-up.sh now merely needs to reliably start up the socket unit:
#!/bin/bash
while : ; do
    systemctl start telnet.socket
    if systemctl status telnet.socket 2>&1 >/dev/null  ; then
        exit 0
    fi
    systemctl stop telnet.socket
    sleep 1
done
NOTE: I realize telnet is not secure. This is an embedded device being booted from an image loaded serially through an external USB interface and this is not intended to be normal usage.
John Klug (1 rep)
Jan 8, 2025, 07:18 PM • Last activity: Jan 9, 2025, 11:55 PM
4 votes
3 answers
5842 views
Use dynamic date in systemd unit
I try use date output as part of log file name in systemd unit. Here example: ``` [Unit] Description=TCS minetest server unit [Service] Type=simple ExecStart=/home/tcs/minetest/bin/minetestserver --worldname world --logfile /home/tcs/logs/debug_$$(date +%%Y_%%m_%%d).txt ExecReload=/bin/kill -HUP $MA...
I try use date output as part of log file name in systemd unit. Here example:
[Unit]
Description=TCS minetest server unit

[Service]
Type=simple
ExecStart=/home/tcs/minetest/bin/minetestserver --worldname world --logfile /home/tcs/logs/debug_$$(date +%%Y_%%m_%%d).txt
ExecReload=/bin/kill -HUP $MAINPID
User=tcs

[Install]
WantedBy=multi-user.target
But I get the log file:
ls /home/tcs/logs/
'debug_$(date'
How I can use current date for log filename?
Dargod (75 rep)
Dec 7, 2019, 02:16 AM • Last activity: Jan 5, 2025, 05:15 PM
0 votes
1 answers
72 views
proper Systemd Unit file syntax to get commands to work
I have this script which works: ``` #! /usr/bin/bash export SEQVAL=$(date +%s) && sed -i "s/^SEQ1=.*$/SEQ1=${SEQVAL}/" /etc/environment systemctl restart ccs-srvapp-telemetry.service ``` For the life of me, I can not get the above to work properly from within a unit file. the latest incarnation I ha...
I have this script which works:
#! /usr/bin/bash

export SEQVAL=$(date +%s) &&  sed -i "s/^SEQ1=.*$/SEQ1=${SEQVAL}/" /etc/environment
systemctl restart ccs-srvapp-telemetry.service
For the life of me, I can not get the above to work properly from within a unit file. the latest incarnation I have is below, but there have been several attempts with various setups all failing on either variable not getting set, or something not escaping correctly in the sed command.
[Unit]
Description=restarts fluent bit with a new SEQ1 to force a logrotate
After=network.target


[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStart=/usr/bin/sh -c 'export SEQVAL=$(date +%s) && sed -i "s/^SEQ1=.*$/SEQ1=${SEQVAL}/" /etc/environment'
ExecStartPost=/bin/systemctl restart ccs-srvapp-telemety.service


[Install]
WantedBy=multi-user.target
Pompey Magnus (103 rep)
Jan 4, 2025, 03:44 PM • Last activity: Jan 4, 2025, 04:58 PM
Showing page 1 of 20 total questions