11

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
Saqib Ali
  • 410
  • 2
  • 7
  • 19

7 Answers7

13

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

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

SWdream
  • 161
  • 1
  • 3
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

Sven
  • 97,248
  • 13
  • 177
  • 225
  • 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
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
Innokenty
  • 171
  • 1
  • 3
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.

phil_ayres
  • 181
  • 1
  • 3
  • 11
0

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

Here's the reference, AWSEC2

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 :