12

I started using Amazon Linux AMIs. It seems to have the /etc/systemd/system/ folder, but I am not able to use systemctl to start stop a service I added to the /etc/systemd/system/ folder.

$ systemctl
bash: systemctl: command not found

7 Answers 7

15

Amazon Linux v 2.0 does support systemd and comes installed by default:

cat /etc/os-release
NAME="Amazon Linux"
VERSION="2.0 (2017.12)"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2.0"
PRETTY_NAME="Amazon Linux 2.0 (2017.12) LTS Release Candidate"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2.0"
HOME_URL="https://amazonlinux.com/"

rpm -qa | grep -i systemd
systemd-libs-219-42.amzn2.4.x86_64
systemd-219-42.amzn2.4.x86_64
systemd-sysv-219-42.amzn2.4.x86_64`
9

sadly that only amazon linux v2 support systemd. Amazon linux v1.0 does not https://aws.amazon.com/amazon-linux-2/

1
  • Does amazon Linux v2 also support SYSVinit? Feb 5, 2020 at 3:22
6

Amazon Linux is ultimately based on an old version of CentOS/RHEL and doesn't support systemd.

https://forums.aws.amazon.com/message.jspa?messageID=731256

2
  • That thread is funny. AFAIK the only people who "want" Amazon Linux are internal to Amazon. And maybe not even there. Dec 21, 2017 at 18:01
  • 1
    @MichaelHampton but now there's Amazon Linux 2, which will be awesome!!!1! I noticed that there have been very few updates to Amazon Linux 1 recently.
    – Tim
    Dec 21, 2017 at 18:44
1

So even though "Amazon Linux 2" should have this command by default, the docker image for it – amazonlinux:2 – does not. To install it there use this directive:

FROM amazonlinux:2
RUN yum install -y /usr/bin/systemctl
1
  • This is not surprising. Docker images are not expected to contain systemd or any other init system, only your application. Nov 17, 2020 at 22:34
0

If you need a horrible hack to fill a gap in your scripts, a simple function may work for you. It only covers essentials and will break very easily.

With this you can perform stop, start, restart, status and is-active requests, such as systemctl start docker. Obviously the outputs won't match systemctl, although is-active provides the same text output on my system.

  #!/bin/bash

  function systemctl() {
    if [ "$1" == 'is-active' ]; then
      if [ -z "$(service $2 status | grep "is stopped")" ]; then
        echo "$2 is active"
      else
        echo "$2 is inactive"
      fi
    else
      service $2 $1
    fi
  }

You can extend it by putting the whole function definition into an if block to test for the OS type or existence of systemctl if necessary.

0

If you would like to use, sudo systemctl enable httpd , just use sudo chkconfig httpd on

Here's the reference, AWSEC2

1
  • Amazon Linux 1 is obsolete, and so is that tutorial. Jul 14, 2020 at 12:50
0

Upon exploring, I found that Amazon Linux AMI release 2018.03 versions of Amazon Linux does not support systemctl. But this does not mean that init.d services cannot be configured to autostart upon boot.

chkconfig can be used for implement the use case.

To configure my init.d service whose name was ingester :

sudo chkconfig ingester on

To list all the services:

sudo chkconfig --list

Here is man page of chkconfig :

2
  • Amazon Linux 1 is obsolete. Jul 15, 2020 at 17:20
  • 1
    I agree that it is obsolete, but when I had to configure my app on a server which is using the obsolete version, I was not able to do it through systemctl. So I shared the answer with others. Jul 15, 2020 at 17:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .