Cron jobs not running after upgrade to Amazon Linux 2

0

I've got crons setup in /etc/cron.d/mycron according to the article at https://repost.aws/knowledge-center/cron-job-elastic-beanstalk These have been running (and still run) on my original EC2 server (retired platform Puma with Ruby 2.6 running on 64bit Amazon Linux/2.12.0). I've created a new identical environment based on Amazon Linux 2 (Ruby 2.7 running on 64bit Amazon Linux 2/3.6.8), however no jobs get run. I have SSH'd on to the new server and can see the files for the cron and the scripts are created fine (e.g /etc/cron.d/charging_all and /usr/local/bin/charging_all.sh) and I can manually run the scripts fine (e.g. [ec2-user@ip-10-0-1-8 current]$ sudo /usr/local/bin/charging_all.sh) so it appears it's nothing to do with security groups or permissions.

So I'm wondering if there is some difference between the old Amazon Linux and the new/current Amazon Linux 2 handles cron jobs? My setup is exactly as per https://repost.aws/knowledge-center/cron-job-elastic-beanstalk but I'm wondering if that is still correct for Amazon Linux 2.

Everything else about the server/website is running just fine. I have checked and rechecked all environment variables are correct.

Any suggestions muchly appreciated.

Thanks Peter

asked 10 months ago2356 views
1 Answer
1
Accepted Answer

Does the new version of Amazon Linux have the cron scheduler installed and running?

[ec2-user@ip-172-31-38-254 ~]$ sudo systemctl status crond
● crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: en>
     Active: active (running) since Fri 2023-06-02 03:40:22 UTC; 2s ago
   Main PID: 25539 (crond)

Rather surprisingly (to me anyway) the cron scheduler is not installed by default in Amazon Linux 2023, although it is a default in Amazon Linux 2.

[ec2-user@ip-172-31-46-115 ~]$ cat /etc/system-release
Amazon Linux release 2 (Karoo)
[ec2-user@ip-172-31-46-115 ~]$ ps -ef | grep cron
root      2339     1  0 03:32 ?        00:00:00 /usr/sbin/crond -n
ec2-user  2590  2548  0 03:34 pts/0    00:00:00 grep --color=auto cron
[ec2-user@ip-172-31-46-115 ~]$ rpm -qf /usr/sbin/crond
cronie-1.4.11-23.amzn2.x86_64
[ec2-user@ip-172-31-46-115 ~]$


[ec2-user@ip-172-31-38-254 ~]$ cat /etc/system-release
Amazon Linux release 2023 (Amazon Linux)
[ec2-user@ip-172-31-38-254 ~]$ ps -ef | grep cron
ec2-user    1762    1672  0 03:34 pts/0    00:00:00 grep --color=auto cron
[ec2-user@ip-172-31-38-254 ~]$ rpm -qa | grep cron
crontabs-1.11-24.20190603git.amzn2023.0.2.noarch
[ec2-user@ip-172-31-38-254 ~]$

If this is the same as you are seeing then you will need install it from the Amazon Linux 2023 repo, and once it's installed you need to start it (it will be enabled for restarting after susequent reboots).

[ec2-user@ip-172-31-38-254 ~]$ sudo yum install cronie -y
Last metadata expiration check: 0:07:19 ago on Fri Jun  2 03:32:34 2023.
Dependencies resolved.
================================================================================
 Package            Arch       Version                    Repository       Size
================================================================================
Installing:
 cronie             x86_64     1.5.7-1.amzn2023.0.2       amazonlinux     115 k
Installing dependencies:
 cronie-anacron     x86_64     1.5.7-1.amzn2023.0.2       amazonlinux      32 k

Transaction Summary
================================================================================
Install  2 Packages
.
.
.
Installed:
  cronie-1.5.7-1.amzn2023.0.2.x86_64 cronie-anacron-1.5.7-1.amzn2023.0.2.x86_64

Complete!
[ec2-user@ip-172-31-38-254 ~]$ sudo systemctl start crond
[ec2-user@ip-172-31-38-254 ~]$ sudo systemctl status crond
● crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: en>
     Active: active (running) since Fri 2023-06-02 03:40:22 UTC; 2s ago
.
.
.
profile picture
EXPERT
Steve_M
answered 10 months ago
  • Thank you for you wonderfully detailed answer, much appreciated. I've checked with sudo systemctl status crond and have confirmed the cron scheduler does seem to be running fine (AL2)

    [ec2-user@ip-10-0-2-17 ~]$ sudo systemctl status crond
    ● crond.service - Command Scheduler
       Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
       Active: active (running) since Fri 2023-06-02 03:48:33 UTC; 17h ago
     Main PID: 2250 (crond)
       CGroup: /system.slice/crond.service
               └─2250 /usr/sbin/crond -n
    
    Jun 02 03:48:33 ip-10-0-2-17.us-west-2.compute.internal systemd[1]: Started Command Scheduler.
    Jun 02 03:48:33 ip-10-0-2-17.us-west-2.compute.internal crond[2250]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 98% if used.)
    Jun 02 03:48:33 ip-10-0-2-17.us-west-2.compute.internal crond[2250]: (CRON) INFO (running with inotify support)

    However, I now notice the jobs have started to run... not exactly sure what changed to make them start.

    I'll be upgrading to Linux 2023 at some point, so will take note to ensure cronie installation and enablement is part of the environment creation.

    I'm going to clone my environment to see if that works and runs the jobs without any further intervention, or if there's something else going on.

    Thanks Peter

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions