Search code examples
ubuntustartuppm2auto

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

  • you can follow this steps :

    1. Create you binary using go build main.go
    2. give execution permission to the binary using sudo chmod +x main.
    3. create a package.json file:
    {
        "apps" : [{
          "name"        : "main",
          "script"      : "./main"
        }]
    }
    

    and finally:

    execute :

    pm2 start package.json