How to Fix Failed to Start atd.service in Ubuntu

The atd daemon executes commands scheduled for one-off future execution via the at command. When atd.service fails to start on Ubuntu servers, batch job scheduling halts, and attempts to queue jobs produce errors such as Cannot open lockfile /var/spool/cron/atjobs/.SEQ or systemd startup exit failures.

Inspect Service Failure Details in Journalctl

Identify the precise root cause by examining the systemd diagnostic logs:

  1. Query the current status of the daemon:
    sudo systemctl status atd.service
  2. Check the detailed system log output:
    sudo journalctl -u atd.service -e --no-pager
  3. Common failure causes include missing spool directories, incorrect ownership on /var/spool/cron/atjobs, or stale PID lockfiles.

Restore Correct Ownership and Permissions on At Spool Directories

The atd daemon enforces strict POSIX ownership constraints on its queue directory to prevent local privilege escalation:

  1. Verify the existence and permissions of the spool paths:
    ls -ld /var/spool/cron/atjobs /var/spool/cron/atspool
  2. If the directories are missing, recreate them:
    sudo mkdir -p /var/spool/cron/atjobs /var/spool/cron/atspool
  3. Set the required ownership to daemon:daemon:
    sudo chown -R daemon:daemon /var/spool/cron/atjobs /var/spool/cron/atspool
  4. Apply the strict octal permissions (1770 for atjobs):
    sudo chmod 1770 /var/spool/cron/atjobs
    sudo chmod 700 /var/spool/cron/atspool

Remove Stale Lockfiles and Restart the Daemon

Abrupt system shutdowns or kernel panics can leave orphaned lockfiles in the spool directory:

  1. Remove any stale sequence or lock files:
    sudo rm -f /var/spool/cron/atjobs/.SEQ /run/atd.pid
  2. Reload the systemd configuration manager:
    sudo systemctl daemon-reload
  3. Start and enable the atd service:
    sudo systemctl restart atd.service
    sudo systemctl enable atd.service
  4. Test scheduling functionality by queuing a test command:
    echo "logger 'atd test successful'" | at now + 1 minute
    atq

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.