mcron stops and then insufficient permissions?

Table of Contents

Problem: my MCRON process stops and I don’t know how to check/restart it

Sometimes, usually after coming back from suspend or starting a new session without rebooting, my “check mail every 5 minutes” mcron has stopped running and I have to execute the script manually. Does anyone know why it might stop, and how I can check if it’s running right now? I attempted to start it as follows, but I get a strange cannot read error. (I tried first without sudo, but got the same result)1

  1. Why might mcron stop, when mcron works fine after an initial booting?
  2. How can I see if mcron is running now?
  3. How can I start mcron again if mcron is NOT running?
sudo mcron -d
mcron: Cannot read files in your ~/.config/cron (or ~/.cron) directory.

More info: seems related. I found that my ssh had stopped, too, so my ssh/custom aliases were broken. Restarting fixed the problem, but what is going on?

Shell session demonstrating the isses

Debugging some more. Here is the session I just had which demonstrates that for some reason mcron says it starts, then stops. I turned up the verbosity but don’t see an explanation.

$> ~/ 17:42$ shepherd
Service root has been started.

Some deprecated features have been used.  Set the environment
variable GUILE_WARN_DEPRECATED to "detailed" and rerun the
program to get more information.  Set it to "no" to suppress
this message.
$> ~/ 10:57$ Service mcron has been started.
shepherd: while opening socket '/run/user/1000/shepherd/socket': bind: Address already in use

Exiting shepherd...
Service mcron has been stopped.

Some deprecated features have been used.  Set the environment
variable GUILE_WARN_DEPRECATED to "detailed" and rerun the
program to get more information.  Set it to "no" to suppress
this message.

$> ~/ 10:58$ export GUILE_WARN_DEPRECATED="detailed"
$> ~/ 10:58$ echo $GUILE_WARN_DEPRECATED
detailed
$> ~/ 10:58$ shepherd
Service root has been started.
bit-count is deprecated.  Use bitvector-count, or a loop over array-ref if array support is needed.
scm_bitvector_length is deprecated.  Use scm_c_bitvector_length instead.
$> ~/ 10:58$ Service mcron has been started.
shepherd: while opening socket '/run/user/1000/shepherd/socket': bind: Address already in use

Exiting shepherd...
Service mcron has been stopped.

Using herd, not shepherd

This looks promising:

$> ~/ 10:59$ herd start mcron
error: connect: /run/user/1000/shepherd/socket: Connection refused
$> ~/ 11:08$ herd stop mcron
error: connect: /run/user/1000/shepherd/socket: Connection refused
$> ~/ 11:08$ sudo -s
Password: 
root@$> herd stop mcron
Service mcron has been stopped.
root@$> herd start mcron
Service mcron has been started. 

Answer: Using Herd, not Shepherd

EDIT: This seems like it should work ā€“ it gives all the right answers ā€“ but I don’t think it is actually causing my local mcron stuff to run.

As sudo Herd is actually the useful command. It appears that Shepherd is responsible for managing all the herds en masse (Daemons), while the herd command interacts with specific ones2. From my original issues:

  1. Why might mcron stop, when mcron works fine after an initial booting?
  2. How can I see if mcron is running now?
  3. How can I start mcron again if mcron is NOT running?

TODO 1. Why might mcron stop, when mcron works fine after an initial booting?

Iā€¦ don’t know this yet ([2022-07-20 Wed]). I’m guessing it has to do with suspending or logging in to a new session.

DONE 2. How can I see if mcron is running now? herd status

The answer is, as root, herd status

root@$> herd status
Started:
 + avahi-daemon
 + console-font-tty1
 + console-font-tty2
 + console-font-tty3
 + console-font-tty4
 + console-font-tty5
 + console-font-tty6
 + cups
 + dbus-system
 + elogind
 + file-system-/boot/efi
 + file-system-/dev/pts
 + file-system-/dev/shm
 + file-system-/gnu/store
 + file-system-/run/systemd
 + file-system-/run/user
 + file-system-/sys/firmware/efi/efivars
 + file-system-/sys/fs/cgroup
 + file-system-/sys/fs/cgroup/blkio
 + file-system-/sys/fs/cgroup/cpu
 + file-system-/sys/fs/cgroup/cpuacct
 + file-system-/sys/fs/cgroup/cpuset
 + file-system-/sys/fs/cgroup/devices
 + file-system-/sys/fs/cgroup/elogind
 + file-system-/sys/fs/cgroup/freezer
 + file-system-/sys/fs/cgroup/memory
 + file-system-/sys/fs/cgroup/perf_event
 + file-system-/sys/fs/cgroup/pids
 + file-system-/sys/kernel/debug
 + file-system-/var/cache/fontconfig
 + file-systems
 + guix-daemon
 + loopback
 + mcron
 + networking
 + nscd
 + ntpd
 + root
 + root-file-system
 + swap-1c4936ce-6b10-4667-9c31-732351fb7294
 + syslogd
 + term-tty1
 + term-tty2
 + term-tty3
 + term-tty4
 + term-tty5
 + term-tty6
 + udev
 + upower-daemon
 + urandom-seed
 + user-file-systems
 + user-processes
 + virtual-terminal
 + wpa-supplicant
 + xorg-server
Stopped:
 - term-console
One-shot:
 * host-name
 * sysctl
 * user-homes

3. How can I start mcron again if mcron is NOT running? herd start mcron

root@$> herd stop mcron
Service mcron has been stopped.
root@$> herd start mcron
Service mcron has been started.

Manually crawling to the file with mcron

having used sudo -s:

mcron -d /home/torysa/.config/cron/mail.guile

Answer take 2: wrong environment paths

After using sudo herd things were failing silently. Using sudo herd start mcron -d myfile.scm It would indeed start the thing, but I noticed that it would fail at every five-minute tick in which it attempted to run. The issue was that the script files I was calling used ~/ several times, and the sudo that was necessary to get herd to start my mcron was evaluating ~/ as something like /root/ and so every place that used ~/ was failing to find the file. By replacing all the ~/ with full paths, I am able to see the mcron always work regardless of what user starts it.

The errors were silent, so I was left trying to figure out why it was running but not doing anything.

Footnotes

1 Posted as a question to Reddit, although my answer came first through searching and experimenting. https://www.reddit.com/r/GUIX/comments/w212jv/mcron_stops_and_then_insufficient_permissions/

2 The documentation on the relationship of these two commands: https://www.gnu.org/software/shepherd/manual/shepherd.html#herd-and-shepherd

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist