When dealing with APT-related cron jobs failing on Ubuntu 14.04, you might encounter several distinct error messages:
/etc/cron.weekly/apt-xapian-index:
FATAL -> Failed to fork.
run-parts: /etc/cron.weekly/apt-xapian-index exited with return code 100
And simultaneously see:
/etc/cron.daily/apt:
FATAL -> Failed to fork.
Or sometimes the database-related error:
/etc/cron.daily/apt:
DB Update failed, database locked
Several factors could contribute to these failures:
- Resource constraints: Even with 600MB free RAM, process limits might be hit
- Lock file issues: Stale lock files preventing execution
- Permission problems: Improper file ownership or permissions
- Process limits: System-wide or user-specific process limits
First, check system resource limits:
ulimit -a
cat /proc/sys/kernel/pid_max
Verify APT lock status:
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/lib/dpkg/lock
Try manually removing stale locks:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock
For persistent fork issues, modify process limits by editing /etc/security/limits.conf
:
# Add these lines at the end of the file
* soft nproc 2048
* hard nproc 16384
* soft nofile 2048
* hard nofile 65536
If manual execution hangs, try running with strace:
sudo strace -f /etc/cron.daily/apt
Check for zombie processes that might be consuming resources:
ps aux | grep 'Z'
Create a wrapper script to handle locks more gracefully:
#!/bin/bash
# /usr/local/bin/apt-cron-wrapper
LOCK_FILE="/var/lib/apt/lists/lock"
MAX_WAIT=300
WAIT_INTERVAL=10
attempt=0
while [ $attempt -lt $(($MAX_WAIT/$WAIT_INTERVAL)) ]; do
if ! [ -f $LOCK_FILE ]; then
exec /etc/cron.daily/apt
exit $?
fi
sleep $WAIT_INTERVAL
attempt=$((attempt+1))
done
echo "Timeout waiting for APT lock"
exit 100
For systems where these errors persist, consider disabling the problematic cron jobs and running updates manually:
sudo chmod -x /etc/cron.daily/apt
sudo chmod -x /etc/cron.weekly/apt-xapian-index
Then create a custom update script with better error handling.
When your cron jobs try to run APT maintenance tasks, you're hitting two distinct but potentially related errors:
/etc/cron.weekly/apt-xapian-index:
FATAL -> Failed to fork.
run-parts: /etc/cron.weekly/apt-xapian-index exited with return code 100
/etc/cron.daily/apt:
FATAL -> Failed to fork.
/etc/cron.daily/apt:
DB Update failed, database locked
The "Failed to fork" error typically occurs when the system cannot create new processes. Despite having 600MB free RAM (which should be sufficient), several factors could be at play:
- Resource limits set via ulimit
- Process table exhaustion (check with
cat /proc/sys/kernel/pid_max
) - System-wide process limit
- Memory fragmentation issues
The locked database suggests another APT process might be running. Check with:
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/lib/dpkg/lock
If you find locked files, carefully consider whether to remove them, as this could corrupt package management:
# Only proceed if you're certain no other APT processes are running
sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock
To check system resource limits:
# Check user limits
ulimit -a
# Check system-wide process limit
cat /proc/sys/kernel/threads-max
cat /proc/sys/kernel/pid_max
For a deeper dive into available memory (not just free RAM):
free -m
cat /proc/meminfo
If you've confirmed resource limits are the issue:
# Temporarily increase max user processes
ulimit -u 4096
# For permanent solution (add to /etc/security/limits.conf):
* soft nproc 4096
* hard nproc 8192
For the database lock, try resetting the APT cache:
sudo apt-get clean
sudo apt-get update
Try running the cron job manually with strace:
sudo strace -f /etc/cron.daily/apt
This might reveal which system call is failing during the fork attempt. Look for clone() or fork() calls that return -1.
For temporary workaround, you could modify the cron job to include resource limits:
#!/bin/bash
ulimit -u 4096
/usr/lib/apt/apt.systemd.daily update
Remember to make it executable:
sudo chmod +x /etc/cron.daily/apt