This article discusses how to resolve the situation where an AWS EC2 server frequently shuts down, necessitating the setup of automatic restart on Ubuntu 20.04. It offers a straightforward method that can be applied immediately without the need for complex .sh files.
Creating the server_start.service File
Create a server_start.service file in the /etc/systemd/ directory and write it as follows:
[Unit] Description=server start After=mysql.service [Service] ExecStart=/bin/bash -c "exec java -jar /home/ubuntu/my-0.0.1-SNAPSHOT.jar" [Install] WantedBy=multi-user.target
The ExecStart=/bin/bash -c "exec java -jar /home/ubuntu/my-0.0.1-SNAPSHOT.jar" section is crucial for immediately executing the command when the service starts.
Checking Service Operation
You can verify if the created service is functioning correctly with the following commands:
sudo systemctl daemon-reload sudo systemctl start server_start.service sudo systemctl status server_start.service
Confirmation of Proper Operation After Reboot
To confirm that the service operates correctly even after a reboot, simply execute sudo reboot
, and after the reboot, check if the .jar process is running.
0 개의 댓글:
Post a Comment