Atd exits with failure status

I am trying to use the at command to schedule a future task. (Mainly because I am going through the LFS101 class on linuxfoundation.org and this is one of the lab assignments) The problem I am running into is that even though the job is queued, it actually completes immediately instead of at the scheduled time (in this case “now + 1 minute”). It does show that it is scheduled for the future, but as soon as the command is run, you can see the file being touched in the GUI.

Running systemctl status atd gives the following

david@opensuse155:~> systemctl status atd
\u00d7 atd.service - Deferred execution scheduler
     Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor pre>
     Active: failed (Result: exit-code) since Thu 2024-05-30 21:43:17 CDT; 17>
    Process: 4881 ExecStart=/usr/sbin/atd -f (code=exited, status=1/FAILURE)
   Main PID: 4881 (code=exited, status=1/FAILURE)

I’m at a loss here. I appreciate any help.

@trainerdave Hi, the -f implies foreground which a systemd service won’t like…
https://manpages.opensuse.org/Tumbleweed/at/atd.8.en.html

Strange they are still using that with systemd the default these days…

Thank you! This did fix the atd service errors I was getting. Strangely enough though, at is still exhibiting the same strange behavior. I have tried reinstalling at through zypper but did not notice a difference. atq still shows that my jobs are queuing correctly, but again, they complete immediately instead of at their scheduled time.

I am able to run the exact same command “at now + 1 minute -f ” in Fedora and it runs at the scheduled time. I am sure I must have something misconfigured, but I am not sure what as this is a fairly fresh VM I am running.

Thank you again!

@trainerdave Are you sure you don’t need to create a systemd timer that runs every minute that will run your command in the service? This would be the norm these days.

I would not say that I am sure of anything :sweat_smile:

I have tested the at command repeatedly with different options and times. Sometimes it runs immediately. Sometimes it does not run at all. But it never runs when scheduled. I am tempted to say this should be a bug report, but from what you said and what the man page for atd said, it sounds like it has been deprecated and mostly replaced with cron and systemd timer.

I have noticed that when I run atd now it is loaded but inactive. I suspect this is related to the issue, but I definitely don’t know enough to be certain, or how to begin troubleshooting that.

david@opensuse155:~> systemctl status atd.service
\u25cb atd.service - Deferred execution scheduler
     Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Sat 2024-06-01 01:06:28 CDT; 5s ago
    Process: 7639 ExecStart=/usr/sbin/atd (code=exited, status=0/SUCCESS)
   Main PID: 7639 (code=exited, status=0/SUCCESS)

Sorry? Default systemd service type is Simple which expects foreground. Did you even try to look at the service definition?

Well, atd.service type is Simple which means service is considered terminated when the main process exists. You made atd fork and for systemd it means that service is terminated. Newer systemd version should show that there are still some processes in this service cgroup (assuming there is one).

Read logs, find out why it fails. Enable debug if normal logs do not show anything useful. This is standard troubleshooting.

I installed at and atd.service starts just fine and executes jobs.

Watch the journal:

erlangen:~ # systemctl status atd.service 
● atd.service - Deferred execution scheduler
     Loaded: loaded (/usr/lib/systemd/system/atd.service; disabled; preset: disabled)
    Drop-In: /etc/systemd/system/service.d
             └─toplevel-override.conf
     Active: active (running) since Sat 2024-06-01 09:07:27 CEST; 5s ago
   Main PID: 6952 (atd)
      Tasks: 1 (limit: 4915)
        CPU: 2ms
     CGroup: /system.slice/atd.service
             └─6952 /usr/sbin/atd -f

Jun 01 09:07:27 erlangen systemd[1]: Started Deferred execution scheduler.
erlangen:~ # journalctl -b -u atd.service 
Jun 01 09:07:27 erlangen systemd[1]: Started Deferred execution scheduler.
erlangen:~ # 

BTW: As I prefer systemd timers I never used it. Thus:

erlangen:~ # zypper remove at
Reading installed packages...
Resolving package dependencies...

The following 2 packages are going to be REMOVED:
  at lsb

2 packages to remove.
After the operation, 127.5 KiB will be freed.

Backend:  classic_rpmtrans
Continue? [y/n/v/...? shows all options] (y): 
(1/2) Removing: lsb-4.0.fake-3.8.x86_64 ..............................................................................................................................................................................................[done]
(2/2) Removing: at-3.2.5-2.6.x86_64 ..................................................................................................................................................................................................[done]
Running post-transaction scripts .....................................................................................................................................................................................................[done]
There are running programs which still use files and libraries deleted or updated by recent upgrades. They should be restarted to benefit from the latest updates. Run 'zypper ps -s' to list these programs.
 
erlangen:~ # 

@arvidjaar I’m well aware of that, the user has a task to do, all I was doing was providing some information… sure the systemd service can be installed, but that is not AFAIK what the user was trying to achieve.

I finally had success! Thank you @karlmistelberger for explaining journalctl to me. I was finally able to see what was happening.

Jun 01 11:23:19 opensuse155 systemd[1]: Started Deferred execution scheduler.
Jun 01 11:23:19 opensuse155 atd[10746]: Another atd already running with pid 2322
Jun 01 11:23:19 opensuse155 systemd[1]: atd.service: Main process exited, code=exited>
Jun 01 11:23:19 opensuse155 systemd[1]: atd.service: Failed with result 'exit-code'.
Jun 01 11:25:30 opensuse155 systemd[1]: Started Deferred execution scheduler.
Jun 01 11:25:30 opensuse155 atd[10833]: sysconfig requested batch_interval to be set >
Jun 01 11:25:30 opensuse155 atd[10833]: sysconfig requested load_avg to be set to 0.8>
Jun 01 11:25:30 opensuse155 atd[10833]: Another atd already running with pid 2322
Jun 01 11:25:30 opensuse155 systemd[1]: atd.service: Main process exited, code=exited>
Jun 01 11:25:30 opensuse155 systemd[1]: atd.service: Failed with result 'exit-code'.

Even though the shell was not showing me any errors, it was apparently competing with another already-running process that was not running correctly. After hunting down all the associated PIDs and killing them, I was finally able to start the atd.service and it shows running. I successfully scheduled two tasks and ran them just now.

It’s amazing that this persisted even despite two uninstall/reinstallations. The issue is now solved though. Thank you everyone for contributing.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.