[systemd-devel] systemd service causing bash to miss signals?
Brian Reichert
reichert at numachi.com
Mon Sep 19 17:18:12 UTC 2022
I apologize for the vague subject.
The background: I've inherited some legacy software to manage.
This is on SLES12 SP5, running:
systemd-228-157.40.1.x86_64
One element is a systemd-managed service, written in Perl, that in
turn, is using bash to generate random numbers (don't ask me why
this tactic was adopted).
Here's an isolation of that logic:
pheonix:~ # cat /root/random_str.pl
#!/usr/bin/perl
print "$0 start ".time."\n";
my $randStr = `cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 64|head -1`;
print "$0 end ".time."\n";
You can run this from the command-line, to see how quickly it
nominally operates.
What I can reproduce in my environment, very reliably, is that when
this is invoked as a service:
- the 'head' command exits very quickly (to be expected)
- the shell does not exit (maybe missed a SIGCHILD?)
- 'fold' chews a CPU core
- A kernel trace shows that 'fold' is spinning on SIGPIPEs, as it's
STDOUT is no longer connected to another process.
My service unit:
pheonix:~ # cat /etc/systemd/system/random_str.service
[Unit]
Description=gernate random number
After=network.target local-fs.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/random_str.pl
ExecStop=/usr/bin/true
#TimeoutSec=infinity
TimeoutSec=900
[Install]
WantedBy=multi-user.target
Easy to repro; this hangs forever, instead of exiting quickly.
pheonix:~ # systemctl daemon-reload
pheonix:~ # systemctl start random_str
Let me know if there are any other details of my environment that
would be helpful here.
--
Brian Reichert <reichert at numachi.com>
BSD admin/developer at large
More information about the systemd-devel
mailing list