davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Cron stops on swapping HDMI or keyboard

Mon Sep 23, 2019 8:38 am

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

User avatar
RaTTuS
Posts: 10601
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Cron stops on swapping HDMI or keyboard

Mon Sep 23, 2019 9:15 am

no what does
sudo status cron

say
also does
sudo dmesg
say anything useful
or even

sudo cat /var/log/syslog
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Cron stops on swapping HDMI or keyboard

Tue Sep 24, 2019 12:48 am

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.

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron stops on swapping HDMI or keyboard

Tue Sep 24, 2019 6:12 pm

You may want to replace cron with systemd-cron.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Cron stops on swapping HDMI or keyboard

Wed Sep 25, 2019 12:50 am

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

davef
Posts: 64
Joined: Wed Feb 20, 2013 8:39 pm
Location: Christchurch, NZ

Re: Cron stops on swapping HDMI or keyboard

Fri Sep 27, 2019 7:13 am

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.

Return to “Troubleshooting”