Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App running in background, reliably and debuggable #138

Open
scripting opened this issue Nov 14, 2019 · 10 comments

Comments

@scripting
Copy link
Owner

@scripting scripting commented Nov 14, 2019

I am working on a Node app that must:

  1. run in the background,

  2. disconnected from the terminal,

  3. survives the terminal window being closed,

  4. yet is easy to quit so I can run a new version.

The product will remain in active development at the same time it is deployed, for the foreseeable future.

It's running on Ubuntu 18.04.3 (LTS) x64 on digitalocean.com.

I am currently using nohup node appname.js & to launch the app, and killAll node, to terminate it, and the apps it launches.

This method seems pretty good. I am able to Control-C after launching the app and it keeps running in the background. It seems to survive closing the terminal and logging on again.

Curious to know what other devs think? What method do you use to launch and kill an app in the background when you're actively developing it?

@easp

This comment has been minimized.

Copy link

@easp easp commented Nov 14, 2019

Sounds like you are running on a unix variant. Which one? They have different canonical ways to manage background daemons/servers.

Also, what, if any, front-end web server are you using?

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Nov 14, 2019

Ooops. I should have said -- Ubuntu.

image

@toontoet

This comment has been minimized.

Copy link

@toontoet toontoet commented Nov 14, 2019

Have a look at what pm2 has to offer. It allows you to manage node processes and more: https://pm2.keymetrics.io/

It also has a nice develop feature so it restarts an app when source code changes. And nice features to deploy code to remote servers.

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Nov 14, 2019

I need something much much lighter weight.

@mterenzio

This comment has been minimized.

Copy link

@mterenzio mterenzio commented Nov 14, 2019

Will forever keep it running in the background?

Then forever list

And forever stop [pid]

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Nov 14, 2019

Matt. this app is forever.

@tedchoward

This comment has been minimized.

Copy link

@tedchoward tedchoward commented Nov 14, 2019

I’ve been using pm2 on my server to run river5 for quite a while. It keeps it going, survives restarts, etc. I haven’t thought a lot about it, I just set it up once a long time ago, and then forgot about it.

@danmactough

This comment has been minimized.

Copy link

@danmactough danmactough commented Nov 15, 2019

I am currently using nohup node appname.js & to launch the app, and killAll node, to terminate it, and the apps it launches.

With your requirements, this is what I would do. (Actually, I run everything inside Docker containers, now. But before I started doing that, this is what I would have done.)

@easp

This comment has been minimized.

Copy link

@easp easp commented Nov 15, 2019

I'd use "systemd" to manage the node process. That way it gets started when/if the machine reboots. It can also automatically restart the process after a crash. Systemd is already installed on ubuntu and is responsible for managing pretty much every persistent process and subsystem, so you won't have to worry about installing extra software.

This article looks like a decent overview of configuring a systemd managed node app. All it takes a 10-15 line config file.

@scripting

This comment has been minimized.

Copy link
Owner Author

@scripting scripting commented Nov 15, 2019

Thanks @easp -- I'll look into it. I see it does allow for the possibility of quitting and relaunching, so it may be usable for a project under development like this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.