Seems the majority of guides online relate to Amazon Linux using init.d which isn't on Amazon Linux 2. Systemctl is on Amazon Linux 2, which doesn't appear to be capable (from what I've found to date) of automatically restarting a service if it has failed, i.e. httpd. I've been looking at Monit.
... just found a bit of additional info while writing this, and it appears that systemctl can automatically restart services by adding the line;
Restart=always
I tried this and systemctl detected that a file change had happened in one of the services. So I ran the following command as prompted and it didn't work;
systemctl daemon-reload
I ended up having to restart the box, after removing the changes I made, to get the service I altered the file for back up and running.
Seems as though systemctl is capable of doing the automatic restarts. I'm a bit lost at present as the documentation is abysmal as usual when you get to this level of configuration, mix that with the endless nuances with how AWS AMIs don't behave as you would expect them to.
One particular service is failing intermittently (which is no surprise really as it's on the smallest EC2 instance you can imagine, but it works 99% of the time). So I'd prefer it if I was able to configure systemctl, or Monit, to just automatically restart the service for the time being before having to scale up the EC2 instance to a bigger box.
UPDATE To add an example service, httpd, this is the out of the box configuration;
[Unit]
Description=The Apache HTTP Server
Wants=httpd-init.service
After=network.target remote-fs.target nss-lookup.target httpd-init.service
Documentation=man:httpd.service(8)
[Service]
Type=notify
Environment=LANG=C
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
KillMode=mixed
PrivateTmp=true
[Install]
WantedBy=multi-user.target