'How to run golang script in PM2?
How do you auto start golang scripts in PM2 on Ubuntu 20.04? this is how I run golang scripts:
./rimgo
I tried pm2 start "./rimgo" --name rimgo but it didn't work. What is the correct command?
Solution 1:[1]
I already run a Golang script. Check this steps:
go build main.goFor to build the script. This must generate amainbinary file.- Grant execution permission for this file with
sudo chmod +x main - Try to execute from command line with
./main - Update the pm2 to latest & type
pm2 start ./main --name FooBar
Solution 2:[2]
you can follow this steps :
- Create you binary using
go build main.go - give execution permission to the binary using
sudo chmod +x main. - create a
package.jsonfile:
{
"apps" : [{
"name" : "main",
"script" : "./main"
}]
}
and finally:
execute :
pm2 start package.json
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alambertt |
| Solution 2 | rassakra |
