3 Simple Steps to Run Go Application in Ubuntu
Writing a blog post after a long time. Was occupied with some new venture and role.
Recently in one of the applications we decided to use GO Lang for APIs And thats where we were required to find out a way to create service for the application to run in background.
One way is the usual way of running the application via nohup using the following command.
nohup go run main.go &
But we know this is just a temporary workaround and not the best solution. So we decided to create a service.
Below are the steps to create a service to run the go lang application in background
Go to the application path where the main.go file is location and run the following command
Step 1 – Build the go program
The above command will create a binary file of the same name as the folders name
Step 2 – Create System Service
The above command will create a blank file called appname.service (replace your app name with the filename).
Write the following content in the file and close it.
[Unit] Description=Name of your application [Service] Type=simple Restart=always RestartSec=5s ExecStart=/path/to/binary/file [Install] WantedBy=multi-user.target
Step 3 – Start the service with system service command
service appname start
The above command will start the service named appname
That’s it. 3 easy steps to run our go program in background on our Ubuntu server hosted on AWS.
Feel Free to Ask Questions if any.