How to run Go forever in producction something like pm2 for nodejs?

(Illud) #1

I want to run my Go program forever like pm2 for nodejs.

(Lutz Horn) #2

A quick web search yields these results as the first four hits:

(Karl Benedict) #3

[OT] Forever? I don’t think you will find that level of guarantee with any solution you find on the internet, forever is a very long time, you know? :slight_smile: [/OT]

(Norbert Melzer) #4

I don’t know what pm2 is, but it boils down to learning about the targets distribution init system or windows services and deploy your program in a way that it’s at least compatible with them, perhaps even provide necessary unit/service files.

(Illud) #5

So i will change my question how to exit linux Terminal without closing Go program?

(Lutz Horn) #6

This not not related to Go … but

(Illud) #7

I’ll check them out, thanks.

(Illud) #8

I´ll check, thanks.

(Norbert Melzer) #9

You use the capabilities of your init system. The most prominent today is probably systemd, but which exactly is used on your system, I don’t know as you haven’t told which Linux you use.

(Illud) #10

Hey i use ubuntu 18 and centos 7

(Norbert Melzer) #11

Both are on systemd iirc, I’m pretty sure about CentOS, though Ubuntu switched the init system a couple of times over the last 10 years, so you have to check there individually.

(Illud) #12

Alright ill check it out thanks men.

(Taalhach) #13

on linux you can use screen but when your system is turned off these screens are gone in other words program stops and other option is creating services by using following code

Description=Service description



every time you do an update to your code just replace build with newer one at this path

and run following command
sudo service NAMEOFSERVICE restart

(Illud) #14

thanks ill check it out.

(Jorge Ramirez) #15

I actually use pm2 to keep my go binary services running, logs and monitoring

(Illud) #16

Like this, (pm2 start main.exe) ?

(Karl Benedict) #17

Are you looking for systemd and/or supervisor? Just guessing here…

(Illud) #18


(Karl Benedict) #19

Well there you have it :slight_smile:

(Illud) #20

Yeah I just did ir jajaj thanks