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

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

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

1 Like

[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]

2 Likes

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.

1 Like

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

This not not related to Go … but

2 Likes

I’ll check them out, thanks.

I´ll check, thanks.

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.

3 Likes

Hey i use ubuntu 18 and centos 7

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.

1 Like

Alright ill check it out thanks men.

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

[Unit]
Description=Service description
Requires=network.target

[Service]
User=root
Restart=on-failure
ExecStart=/usr/bin/NAMEOFFILE

[Install]
WantedBy=multi-user.target

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

and run following command
sudo service NAMEOFSERVICE restart

2 Likes

thanks ill check it out.

1 Like

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

1 Like

Like this, (pm2 start main.exe) ?

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

1 Like

Supervisor

Well there you have it :slight_smile:

1 Like

Yeah I just did ir jajaj thanks