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`
Answer from supaflysnooka on serverfault.comAmazon 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/
Command not found: systemctl on Amazon Linux 2018.03 - Stack Overflow
Adding a systemd service file
How do I configure my Amazon Linux service to auto-restart if it fails? - Unix & Linux Stack Exchange
centos - No package systemd available on Amazon linux EC2 - Unix & Linux Stack Exchange
Any canonical examples for creating custom services? Googling shows this.
- First check what Amazon linux version you have runnng on using the
command
cat /etc/os-release- If it is Amazon Linux Version 2, then it does support systemd and comes installed by default.
- If it is Amazon linux version 1, then it doesn't support cause Amazon Linux is ultimately based on an old version of CentOS/RHEL.
if it is version 1 (amazon linux), you just need to switch to any other linux distribution that supports systemd. You can't yum install systemd like a package

sudo service nginx status
just use the service command
In earlier versions of RHEL use the service command as explained in the documentation here.
# service service_name start
Therefore, in your case:
# service iptables start
You can replace start with restart, stop, status.
List all services with:
# service --status-all
Amazon Linux 2
If your version of Amazon Linux is >=2.0, it has systemd by default. In this case, you should simply be able to use the same unit file you have been using on CentOS, with the restart directives.
Amazon Linux AMI
If you are you are running Amazon Linux AMI, you will need to either use a separate supervisor to monitor your process (as poige mentioned), or utilize /etc/inittab.
For example, in order to have sysvinit automatically restart your process, add the following to /etc/inittab:
# Start and respawn process
mydaemon:2345:respawn:/path/to/executable argument1 argument2
This tells sysvinit to start the process on runlevels 2, 3, 4, and 5 and restart it when it terminates.
Also, if you wish to add some commands around the executable to be run on startup, the executable path can instead refer to a script that runs the program in the foreground.
I'm using Amazon Linux.
ok, type in man init
If it's any fresh you'll see it's systemd in fact. So thus your q-n transforms into something answered already.
In case you consider systemd over-engineered (as many of us in fact do) you can give a try to venerable daemon-tools or smth alike (runit, supervisord). Be prepared it might be not in standard repos Amazon Linux comes with though.
systemd is not supported in Services. The only correct is sysvinit:
services:
sysvinit:
my_worker:
enabled: "true"
ensureRunning: "true"
But I don't think it will even work, as this is for Amazon Linux 1, not for Amazon Linux 2.
In Amazon Linux 2 you shouldn't be even using much of .ebextensions. AWS docs specifically write:
On Amazon Linux 2 platforms, instead of providing files and commands in .ebextensions configuration files, we highly recommend that you use Buildfile. Procfile, and platform hooks whenever possible to configure and run custom code on your environment instances during instance provisioning.
Thus, you should consider using Procfile which does basically what you want to achieve:
Use a Procfile for long-running application processes that shouldn't exit. Elastic Beanstalk expects processes run from the Procfile to run continuously. Elastic Beanstalk monitors these processes and restarts any process that terminates. For short-running processes, use a Buildfile.
Alternative
Since you already have created a unit file /etc/systemd/system/my_worker.service for systemd, you can enable and start it yourself.
For this container_commands in .ebextensions can be used. For example:
container_commands:
10_enable_worker:
command: systemctl enable worker.service
20_start_worker:
command: systemctl start worker.service
It's not officially documented, but you can use a systemd service in Amazon Linux 2.
A block like the following should work:
services:
systemd:
__SERVICE_NAME__:
enabled: true
ensureRunning: true
Support for a "systemd" service is provided by internal package /usr/lib/python3.7/site-packages/cfnbootstrap/construction.py which lists recognized service types: sysvinit, windows, and systemd
class CloudFormationCarpenter(object):
_serviceTools = {"sysvinit": SysVInitTool, "windows": WindowsServiceTool, "systemd": SystemDTool}
Note that a systemd service must support chkconfig and in particular your launch script at /etc/init.d/__SERVICE_NAME__ must include a "chkconfig" and "description" line similar to:
# chkconfig: 2345 70 60
# description: Continuously logs Nginx status.
If you don't support chkconfig correctly then chkconfig --list __SERVICE_NAME__ will print an error, and attempting to deploy to Elastic Beanstalk will log a more detailed error in /var/log/cfn-init.log when it tries to start the service.