From 71016a4d35590c4d010ab7f862df42bcddc2c7d5 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 24 Sep 2021 23:26:26 +0300 Subject: [PATCH] 208.2. Creating Unix Service - My impl (through service and with Env variable) (#32) --- README.md | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fdccd9c..e404ed7 100644 --- a/README.md +++ b/README.md @@ -130,10 +130,41 @@ Create EC2 instance with custom security rules - `sudo service supportapi status` 9. View logs - `cd /var/log` -> `ls` - - `cat supportapi.log` + - `cat /var/log/supportapi.log` - **or** - `sudo vim supportapi.log` -> :qa for quit - **or** - - `sudo tail -f supportapi.log` + - `sudo tail -f /var/log/supportapi.log` +10. Setting Permanent Global Environment Variables for All Users + - `sudo nano /etc/environment` + - `SPRING_PROFILES_ACTIVE=aws-local` + +#### 208.2 Creating Unix Service - Correct Way + +- cd /etc/systemd/system +- Create a file named your-service.service and include the following: +```shell script +[Unit] +Description=Support Portal API + +[Service] +User=supportuser +WorkingDirectory=/var/lib/supporthome +ExecStart=/var/lib/supporthome/support-portal.jar +Restart=always +Environment="SPRING_PROFILES_ACTIVE=aws-local" + +[Install] +WantedBy=multi-user.target +``` +- Reload the service files to include the new service. + - `sudo systemctl daemon-reload` +- Start your service + - `sudo systemctl start supportapi.service` +- To check the status of your service + - `sudo systemctl status supportapi.service` +- To enable your service on every reboot + - `sudo systemctl enable supportapi.service` +