The front engineer tried to automatically start go's API server with systemd quickly

I was told that it would be better to make it a service with systemd, so I tried it for the time being.

① Go build with the project file (sample in this case) ② Create app.service in etc / systemd / system ③ Describe the following in app.service

[Unit]
Description=Automatic start server demon

[Service]
ExecStart=/home/sample/sample
WorkingDirectory=/home/ec2-user/sample
Restart=always
Type=simple
User=ec2-user

[Install]
WantedBy=multi-user.target

[Explanation] Specify the executable file with ExecStart When go build, the same binary as the file name will be generated, so specify it

Specify the directory to be executed in Working Directory

By setting Restart = always always, it will restart automatically even if it fails.

Type = simple Specify the timing to determine that execution is complete

simple = When the command is executed Type = forking = When the executed command is finished When the Type = oneshot = command completes

User User to execute

Create a link in the .wants directory of this unit when WantedBy = multi-user.target is enabled I wasn't sure about this.

4 Run `` `sudo systemctl daemon -reload``` Updated the contents of app.service

⑤ Execute `` `sudo systemctl enable /home/ec2-user/etc/systemd/system/app.service``` Enable automatic service startup

⑥ Execute sudo systemctl start app.service

This will start automatically

Recommended Posts

The front engineer tried to automatically start go's API server with systemd quickly
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to get the authentication code of Qiita API with Python.
I tried to automatically extract the movements of PES players with software
What to do if the server doesn't start with python manage.py runserver
I tried to touch the COTOHA API
I tried to get the movie information of TMDb API with Python
Former image processing engineer tried to solve Saizeriya's spot the difference with OpenCV
To automatically send an email with an attachment using the Gmail API in Python
I tried to automatically send the literature of the new coronavirus to LINE with Python
Log in to the remote server with SSH
I tried to detect motion quickly with OpenCV
I tried to touch the API of ebay
I tried to start Jupyter with Amazon lightsail
Create an API server quickly with Python + Falcon
Build API server for checking the operation of front implementation with python3 and Flask
I tried to learn the sin function with chainer
I tried to move Faster R-CNN quickly with pytorch
I tried to read and save automatically with VOICEROID2 2
I tried to solve the soma cube with python
I tried to automatically read and save with VOICEROID2
I tried to uncover our darkness with Chatwork API
I tried to automatically generate a password with Python3
I tried to solve the problem with Python Vol.1
I tried hitting the API with echonest's python client
I tried to rewrite the WEB server of the normal Linux programming 1st edition with C ++ 14
I tried to find the entropy of the image with python
Try hitting the Twitter API quickly and easily with Python
I tried to simulate how the infection spreads with Python
I tried to analyze the whole novel "Weathering with You" ☔️
[First COTOHA API] I tried to summarize the old story
I tried to find the average of the sequence with TensorFlow
I tried to automatically create a report with Markov chain
I tried to notify the train delay information with LINE Notify
The first API to make with python Djnago REST framework
Throw appointments to others with the LINE WORKS calendar API
I tried saving the DRF API request history with django-request
I tried to divide the file into folders with Python
I tried to get various information from the codeforces API
How to start Apache by specifying httpd.conf with systemd (CentOS7, CentOS8)
I tried to output the access log to the server using Node.js