Page 1 of 1

Cron stops on swapping HDMI or keyboard

Posted: Mon Sep 23, 2019 8:38 am
by davef
I run a cron job every minute. As I have two Model 3B+ and only one HDMI monitor I have noticed that when I swap the monitor and/or USB keyboard between units that the Pi running Jessie sometimes stops running. Maybe, 1 in 10 swap-overs.

Code: Select all

sudo service --status-all
shows a [+] against cron but it just doesn't run until I reboot.

Sound familiar?

Thanks,
Dave

Re: Cron stops on swapping HDMI or keyboard

Posted: Mon Sep 23, 2019 9:15 am
by RaTTuS
no what does
sudo status cron

say
also does
sudo dmesg
say anything useful
or even

sudo cat /var/log/syslog

Re: Cron stops on swapping HDMI or keyboard

Posted: Tue Sep 24, 2019 12:48 am
by davef
Thank you for the suggestions ... will have to wait until the weekend as the devices are at a remote location.

I recall looking into syslog and still see that cron apparently runs every minute, but the bash script that cron calls does not get executed. Perhaps should mention that cron is a one line BUT uses a call to /usr/bin/flock to stop possible multiple instances of the bash script that runs every minute.

Everything runs fine until I show up on site and start playing with the system. As well as swapping hardware, as mentioned, there are many

Code: Select all

sudo service cron stop
and

Code: Select all

sudo service cron start
calls during code modification.

Re: Cron stops on swapping HDMI or keyboard

Posted: Tue Sep 24, 2019 6:12 pm
by DougieLawson
You may want to replace cron with systemd-cron.

Re: Cron stops on swapping HDMI or keyboard

Posted: Wed Sep 25, 2019 12:50 am
by davef
As I have never heard of systemd-cron Google led me to this HowTo:

https://www.putorius.net/using-systemd-timers.html

What I couldn't determine was why using systemd-timers might be better in my situation. Is it more robust? Also, I would need to work out how to stop multiple instances of this timer running.

Just read that one of the benefits is that only one instance can run at a time.

I will investigate further.

Tnx,
Dave

Re: Cron stops on swapping HDMI or keyboard

Posted: Fri Sep 27, 2019 7:13 am
by davef
RaTTus,

I am guessing you mean

Code: Select all

sudo service cron status
With the system running normally this is what I get:

Code: Select all

● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled)
   Active: active (running) since Sun 2019-09-22 15:18:27 NZST; 5 days ago
     Docs: man:cron(8)
 Main PID: 1244 (cron)
   CGroup: /system.slice/cron.service
           ├─ 1244 /usr/sbin/cron -f
           ├─32436 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant_sbms.conf
           └─32537 dhclient -v -pf /run/dhclient.wlan0.pid -lf /var/lib/dhcp/dhclient.wlan0.leases wlan0

Sep 27 18:54:01 raspberrypi sudo[29699]: root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/home/./run_system.sh
Sep 27 18:54:01 raspberrypi sudo[29699]: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 27 18:54:05 raspberrypi sudo[29699]: pam_unix(sudo:session): session closed for user root
Sep 27 18:54:05 raspberrypi CRON[29692]: pam_unix(cron:session): session closed for user root
Sep 27 18:55:01 raspberrypi CRON[29744]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 27 18:55:01 raspberrypi CRON[29748]: (root) CMD (/usr/bin/flock -w 0 /home/run_system.sh -c "sudo /home/./run_system.sh" > /dev/null 2>&1)
Sep 27 18:55:01 raspberrypi sudo[29751]: root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/home/./run_system.sh
Sep 27 18:55:01 raspberrypi sudo[29751]: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 27 18:55:05 raspberrypi sudo[29751]: pam_unix(sudo:session): session closed for user root
Sep 27 18:55:05 raspberrypi CRON[29744]: pam_unix(cron:session): session closed for user root
I will try to get it to fault and post the result.