3

I know there are a lot of answers to this question but none have worked for me and I've been at it for something like six hours... Most of the answers also look like they are years out of date.

I am trying to open an lxterminal when my Raspberry Pi 3B+ opens, have it run a node server.js file, and keep that server running (because the program requires it).

I've tried editing the autostart files at both

/etc/xdg/lxsession/LXDE/autostart and /home/pi/.config/lxsession/LXDE-pi/autostart

Even just trying to run @lxterminal from either of those doesn't work.

I have successfully been able to get the other half of this project running, which is to open localhost in a browser on bootup, by putting a command in autostart at /etc/xdg/lxsession/LXDE/autostart

Basically, my program will crash if I don't keep the terminal open, and I want to run this in headless mode because it's a portable NFC-scanning application that I'm using for a game that is receiving data from one serial port, piping it to the webpage to play audio and parse some text, then sending that text back over socket.io to display on a tiny LCD screen.

Thanks for your help!

Edit: I tried pm2 and it didn’t work, unfortunately. I spent a few hours today trying to debug but in a nutshell the command would run once then fail, and not appear in the pm2 process list (but the port remained blocked). It’s possible there’s something I’m missing.

Joe
  • 135
  • 9
  • 2
    My first thought is ... trying to run a program that must have a terminal open (whatever that really means) in headless mode suggests the program isn't meant to run in headless mode, so you may be pushing a big stone uphill – Jaromanda X Mar 01 '19 at 07:37
  • Thanks for that thought. In this case, it doesn’t matter if I can access it via .ssh, what matters is that I can turn on the pi and have these programs launch without any input from me. I’ve tested it with a monitor and screen and the program works so long as the terminal is open, but that could just mean keeping the node server up after the initial command, regardless of what’s happening in the GUI. PM2 may actually be the solution to this but I tried the initial setup and that didn’t work. – Jess Marcotte Mar 01 '19 at 10:46
  • Syntactically, I also saw the -hold command? But I wasn’t able to find clear documentation about which ways of autostarting a process support it. But the fact that @lxterminal wouldn’t even launch on its own without those parameters makes me think that’s not the issue with what I’ve tried so far. – Jess Marcotte Mar 01 '19 at 10:51
  • I have been struggling with this issue for days. Thanks. – Joe Nov 03 '19 at 22:51

1 Answers1

4

I found the solution after all. I used pm2 after all. The quick start suggested at the start of the pm2 documentation will not work. Follow the detailed instructions instead, which amount to:

  1. Install pm2 for node (npm install -g pm2)
  2. Type “pm2 startup” into the command line
  3. Paste in the resulting command as instructed.
  4. Change directories to where your app exists.
  5. Type “pm2 start filename.js”
  6. Type “pm2 save”
  • This solved my problem. – Joe Nov 03 '19 at 22:52
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Jan 28 '20 at 12:00