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
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
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`
sadly that only amazon linux v2 support systemd. Amazon linux v1.0 does not https://aws.amazon.com/amazon-linux-2/
Amazon Linux is ultimately based on an old version of CentOS/RHEL and doesn't support systemd.
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
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.
If you would like to use,
sudo systemctl enable httpd
, just use sudo chkconfig httpd on
Here's the reference, AWSEC2
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
: