Autostart node-applications in user-webspace on reboot (pm2, forever, etc.)

OS type and version Ubuntu Linux 20.04.6
Webmin version 2.021
Usermin version 1.861
Virtualmin version 7.5
Theme version 20.21
Package updates All installed packages are up to date

I wonder if anybody came to this issue too?

I have create some custom-commands which make the user able via usermin to install nvm, choose a node-server version, or fully remove nodejs from their webspace.

Next topic would be to make the user able to execute an yarn start or npm start command to run their servers, AND - most important… to keep them up and awake.

Did anybody solved it, to make the VirtualServer user able to start stop and keep-running their node-services via Usermin or VirtualServer-Admin-User?

Or does those nodejs users always need ssh-access to make this work?

1 Like

There’s a module called virtualmin-init which allows users to manage their own actions to be run on boot. Package is webmin-virtualmin-init on Ubuntu/Debian and wbm-virtualmin-init on RHEL-based distros.

I’m not sure how well-maintained it is, it’s not super commonly used (but maybe should be, since it’s so common to run user-managed app servers these days).

1 Like

And, let us know if you run into any problems with it. We probably should consider this core functionality these days (again, app servers super common now), but I don’t think a lot of people know about it, so it hasn’t gotten much usage.

That is the first part of the problem - knowing about something is the first step because then it gets used then only then can issues with it be identified to indicate a need for maintenance.
-makes me wonder how many other packages are available but lost to public use.

I think about to create a simple virtualmin module especially to handle nodejs stuff.

It should do what I currently do with custom-commands:

Make the user able to:

  1. activate / install nodejs support
  2. show available versions of node
  3. choose version of used node version
  4. de-install node

and additional to that
5. init a pm2 or forever process for any app i like to run

I little hurdle:
It would be nice to also have a nice implementation to simply do a proxy-redirect for a given Port in NGINX and Apache.
But for the first steps it would be ok to me to manage this manually in the nginx-conf files.

Ok, I figured out the whole process that is need to fully setup an nodeJS app, like described in my previous post.
It’s from activating node for a VirtualServer over running yarn commands up to make the process reboot-safe and removeable.

Currently it’s fully handled only by Custom Commands, and one manual setting in Nginx-Conf for Reverse-Proxy.
It’s ok, but bad UX. So I would love to create (with helping hands) an own “Nginx-Node Module” out of it to make this more straight-forward to use.

Expert knowledge needed:

Only last thing I need some support and knowledge from the experts is following:

For my testing purposes I hard-coded a Proxy-Reverse entry to, as nextJS generally use Port 3000 on startup.
It’s no big thing to change the port during nextJS startup to anything else, but the question is, how to prevent a port collision with other users?

As other users at the same server couldn’t know which ports are already in use, there should be a way to handle it fail-save.

@Joe Any Idea to solve this issue?

First ideas:

  1. create a private IP per node-APP ( maybe til
  2. save values for already taken ports and assign new ports internally

“nextjs” why restrict to this framework?
Nearly all my users have no interest in nextjs as they prefer express or other frameworks

  • nearly all, but not all, use NodeJS and a few are even considering a move to me2 alternatives or even better server-side such as “Go”

The port issue is even more important as it affects everyone non one uses 3000 and when left to the client you will always get collisions - they could even choose 1000 or 2000 and if you try to enforce it ($%ÂŁ&!) well do you need the added hassle?

At the moment I take over the whole process so I am also interested in an easy solution that can be passed on to the individual user.

nextJS is only the application I used it for. You can use whatever nodejs application you like.

I think a automated, but managed assignment of ports is needed to prevent port collisions. And the virtualmin plugin should handle this at it’s own … for all users.

So Ideas how to do this are welcome :slight_smile:

Virtualmin does protect ports and can keep up with which users are allowed to use which ports; I don’t know if that’s easily user-visible, though. @Jamie is the port protection stuff available to end users? Can it be made available to end users? (I mean, I know scripts that need a proxied port get one assigned and are prevented from squatting on other user ports, but I don’t see an obvious way to get a port that isn’t associated with an Install Script which is very limiting.)

Also, I’ll mention that though Virtualmin has awareness of ports, it’s probably better to proxy to UNIX named sockets instead of ports. Named sockets can be owned by the user, and thus they don’t need any hacky protections…another user can’t possibly squat on a file owned by another user. Most app servers work fine on named sockets, and with only minor configuration changes. (We also should have better GUI support for proxying to UNIX sockets, @Jamie. Maybe it’s already possible, since it’s the same directives, you just use a path like unix:/path/to/socket instead of http://localhost:3000 or whatever. Maybe we just need more explicit docs about it.)

Virtualmin can also install node.js, setup proxying for it and start it at boot already, using the Install Scripts page. You could presumably do this to get a vanilla node.js install, and then configure it to run your app. This will also take care of port protection…

1 Like

@Joe Can you tell where to find the input-form in virtualmin-gui after installing this plugin?

What plugin?

virtualmin-init, you note above: Autostart node-applications in user-webspace on reboot (pm2, forever, etc.) - #2 by Joe