10

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
11

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`
5

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? – overexchange Feb 5 '20 at 3:22
4

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. – Michael Hampton Dec 21 '17 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 '17 at 18:44
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. – Michael Hampton Jul 14 '20 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. – Michael Hampton Jul 15 '20 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. – Manish Jul 15 '20 at 17:25
0

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. – Michael Hampton Nov 17 '20 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.