Hello! For a very long time I kept having random hardfreezing, sometimes while I sleep, sometimes while I'm working, sometimes at login, sometimes it's up for days. I used different linux distros, debian and arch, I replaced every part of the computer until now I am down to one and the cause is clear. It's a broken old video card and XSERVER crashes.
Someone told me I could run Node-RED under a different user, on boot, so if my user session crashes, Node-RED would keep working.
What do you think about this? I am a bit overwhelmed by stress those days and there are clients counting on my service.
If you are using a Debian based OS such as Ubuntu then the recommended Debian/Ubuntu/Pi install script installs systemd scripts for running at boot. You don't need to run it as a different user, just not running in the xserver session.
Depending on what you are using this server and node-red for, if you need reasonable security, you should most certainly NOT run Node-RED as root. Doing so is not only less secure but is likely to cause other operational issues.
Instead, create a user and group specifically for running Node-RED and adjust the startup script to use that user. Also make sure that the userDir folder is owned by the node-red user/group. Obviously, you need to make sure that the node-red user and/or group has access to whatever resources you want accessible from Node-RED (e.g. serial port, etc). You can then also make sure that the node-red user has no login rights so that the account can't be misused that way.
I was getting Error: ENOENT: no such file or directory errors but I fixed it by running my script from inside the ~/.node-red folder, which I didn't at first.
I don't think "WorkingDirectory" matters but I was trying to fix the error which didn't work by adding it.
@TotallyInformation Thank you for the detailed information, that is what I was recommended to do, you also added some more things to be careful about. Right now I tried doing what @Colin said and just run it as a service, I'll see at the next hard freeze (xserver crash) if node-red keeps working and post an update.
If you look in my GitHub, you will find a repo called alternate installer which has a complete systemd service definition example script. That has some possibly nice extras such as environment variables from a file and some sensible service dependencies.