How to auto start web services when starting an Amazon EC2 instance?
Rather than starting over with a new AMI, you could just issue the following commands on an Amazon Linux EC2 instance...
sudo chkconfig mysqld onsudo chkconfig httpd on
You can check the settings before & after enabling these services to start on boot using the following commands...
sudo chkconfig --list mysqldsudo chkconfig --list httpd
See all services using just...
sudo chkconfig --list
NOTE: If you are having any trouble with chkconfig being in root's path, you can try specifying the full path like this...
sudo /sbin/chkconfig mysqld onsudo /sbin/chkconfig httpd on
It is different between Amazon Linux 1 and Amazon Linux 2.
Amazon Linux 1
In AmazonLinux1, use chkconfig
command.
$ sudo chkconfig mysqld on$ sudo chkconfig httpd on
Amazon Linux2
In AmazonLinux2, systemd was introduced. So, chkconfig
is legacy command. You should use systemctl
. It is a control command for systemd.
$ sudo systemctl enable mysqld$ sudo systemctl enable httpd
You can confirm it is enabled or not using by is-enabled
command.
$ sudo systemctl is-enabled mysqldenabled
chkconfig
command request will be forwarded to systemctl
.
$ chkconfig mysqld onNote: Forwarding request to 'systemctl enable mysqld.service'.
If you using Amazon Linux 2 AMI you need to follow these steps:
- In AMI2 they are using
systemctl
for managing services check if it is installed on your machine2.systemctl list-units --type=service
by this command check if tomcat.service is listed sudo systemctl enable tomcat.service
To eanable tomcat start on boot upsystemctl is-enabled tomcat.service
To check if tomcat enabled to start on boot up linux system
After that you can reboot your linux system and tomcat will be started.
For more about systemctl
Click Here