Skip to content

Amazon Linux 2023 で cron を利用出来るようにする

Amazon Linux 2023 には cron が含まれておらず、スケジュール実行機能を利用したい場合は systemd を使う必要があります。 この仕様については AWS re:PostAmazon Linux 2023 does not contain /etc/cron.d folder という投稿がされており、以下のように記載されています。

Amazon Linux 2023 does not contain "/etc/cron.d" folder. Our application need to add few services installed in this folder. It was supported in Linux 1 and 2. I am running the below command to create the "cron.d" folder in Amazon Linux 2023. "sudo yum install cronie -y" Is this an acceptable workaround? Will this folder no longer be part of any future releases? Please suggest. Thanks Arahanth

他にも GitHubhttps://github.com/amazonlinux/amazon-linux-2023/issues/300 という同様の投稿がされています。 今後はスケジュール実行機能も systemd へ移行する方が好ましいのかも知れませんが、今回は「古いアプリケーションとの互換性も考えて敢えて Amazon Linux 2023 へ cron をインストールする」手順をメモしておきます。

検証環境

今回は以下の環境で検証しました。

  • Amazon Linux 2023
  • ARM
  • t4g.micro

cronie のインストール

cron を利用するには cronie パッケージをインストールします。 dnf で標準リポジトリからインストール可能です。

1
dnf -y install cronie

インストール直後はサービスが停止しています。

1
2
3
4
# systemctl status crond.service
○ crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled)
     Active: inactive (dead)

起動&自動起動設定をしておきます。

1
systemctl start crond.service && systemctl enable crond.service

これで cron が利用出来るようになりました。