When working with systemd services of Type=forking, developers often encounter this warning message:
systemd[1]: aaa.service: Supervising process 18285 which is not our child. We'll most likely not notice when it exits.
This occurs when the parent process (your startup script) terminates before systemd can properly track the forked child process (your daemon). Let's break down why this happens in your specific case.
Your current workflow looks like this:
systemd → run_aaa.sh → (forks) aaa daemon
│
└── exits immediately
The critical timing issue occurs because:
- systemd launches run_aaa.sh and expects it to fork
- run_aaa.sh spawns the aaa daemon in background
- run_aaa.sh exits before systemd can establish proper process tracking
The correct behavior for a forking service should be:
[Service]
Type=forking
PIDFile=/path/to/pidfile
ExecStart=/path/to/script
Where the startup script must:
#!/bin/bash
# 1. Do pre-launch setup
# 2. Fork the daemon process
# 3. Write PID to PIDFile
# 4. Wait briefly for child to start
# 5. Exit only after systemd collects the PID
Option 1: Modify your run_aaa.sh script
Here's how to properly implement the forking behavior:
#!/bin/bash
# Your existing setup code
export ENV_VARS=values
./maintenance_scripts.sh
# Launch the daemon properly
/path/to/aaa --options &
daemon_pid=$!
# Write PID file
echo $daemon_pid > /usr/local/aaa_path/aaa/aaa.pid
# Brief delay to let systemd collect the PID
sleep 1
exit 0
Option 2: Consider using Type=simple with proper PID tracking
If your daemon doesn't actually need traditional forking behavior:
[Service]
Type=simple
PIDFile=/usr/local/aaa_path/aaa/aaa.pid
ExecStart=/usr/local/aaa_path/aaa/run_aaa_modified.sh
With modified script:
#!/bin/bash
# Setup code here
# Launch in foreground but write PID
/path/to/aaa --options &
echo $! > /usr/local/aaa_path/aaa/aaa.pid
wait
After making changes:
systemctl daemon-reload
systemctl restart aaa.service
systemctl status aaa.service
The warning should disappear if implemented correctly. Monitor with:
journalctl -u aaa.service -f
For more complex scenarios, consider these additions to your service file:
[Service]
# Add these under [Service] section
Restart=on-failure
RestartSec=5s
TimeoutStartSec=30
TimeoutStopSec=30
This provides better control over service lifecycle management.
When working with systemd services configured as Type=forking
, you might encounter this warning:
systemd[1]: aaa.service: Supervising process 18285 which is not our child. We'll most likely not notice when it exits.
This occurs when systemd can't properly track the forked process hierarchy. Let's examine why this happens in your specific case.
Your service configuration has several key elements:
[Service]
Type=forking
PIDFile=/usr/local/aaa_path/aaa/aaa.pid
ExecStart=/usr/local/aaa_path/aaa/run_aaa.sh
The issue arises because:
- Your
run_aaa.sh
script starts the daemon process and exits - The daemon process becomes detached from systemd's process tree
- Systemd finds the PID in your specified PID file but can't establish proper parent-child relationship
Option 1: Modify Your Startup Script
Adjust your run_aaa.sh
to maintain proper process hierarchy:
#!/bin/bash
# Prepare environment
export VAR1=value1
export VAR2=value2
# Run maintenance scripts
/maintenance/script1.sh
/maintenance/script2.sh
# Start main process without backgrounding
exec /usr/local/aaa_path/aaa/aaa --option1 --option2
Key changes:
- Remove the
&
(background) operator - Use
exec
to replace the shell process with your daemon - Change service type to
simple
Option 2: Proper Forking Implementation
If you must keep the forking behavior, ensure proper implementation:
#!/bin/bash
# Prepare environment
source /etc/aaa/env.conf
# Run maintenance
/maintenance/setup.sh
# Start daemon
/usr/local/aaa_path/aaa/aaa --daemonize --pid-file /var/run/aaa.pid
# Verify PID file creation
sleep 1
if [ ! -f /var/run/aaa.pid ]; then
exit 1
fi
exit 0
Service file adjustments:
[Service]
Type=forking
PIDFile=/var/run/aaa.pid
ExecStart=/usr/local/aaa_path/aaa/run_aaa.sh
ExecStartPost=/bin/sleep 0.1
Using Type=simple with Background Process
If your daemon properly daemonizes itself:
[Service]
Type=simple
ExecStart=/usr/local/aaa_path/aaa/run_aaa.sh
With modified script:
#!/bin/bash
# Environment setup
. /etc/default/aaa
# Start daemon that stays attached
/usr/local/aaa_path/aaa/aaa --foreground
To investigate process relationships:
# View process tree
pstree -p -s <pid>
# Check process ancestry
cat /proc/<pid>/status | grep PPid
# Verify systemd tracking
systemctl show aaa.service -p MainPID
- Prefer
Type=simple
when possible - Ensure proper daemonization if using
Type=forking
- Verify PID file creation timing
- Consider using
ExecStartPost
with small delays if needed - Test service recovery with
systemctl kill -s KILL aaa.service