0

I see this reference to open the app directly autostart app in LXDE but is there a way to also start my nodejs script?

asked Aug 2, 2015 at 16:03

1 Answer 1

0

I think you are looking for the --command option to lxterminal. From man lxterminal:

-e STRING --command=STRING

Execute the argument to this option inside the terminal.

So for example in your autostart file:

@lxterminal -e "node /full/path/to/your/script"

My node invocation may be a bit off there, but whatever you normally use should work. If there are spaces in the command, enclose it in quotes as above.

If the script daemonized itself or otherwise goes to the background, it will be detached from the terminal which spawned it and that terminal will then exit. Your process may still be running (look with ps -C [name-of-process]), but if you want to keep the terminal up, try using a shell wrapper:

#!/bin/sh
node /blah/blah
exec bash

This would replace the -e "command". To explain: When the first command finishes (or forks to the background), the next command will execute. This will mean the terminal appears normal, with a bash shell prompt (the default invocation is really the equivalent of lxterminal -e $SHELL, where $SHELL is bash). If your backgrounded script produces output, it should still appear since the output device/tty is still the same. If that's the case though you probably want to look into a way to keeping the node process in the foreground.

answered Aug 2, 2015 at 16:10
4
  • Thanks, it worked but somehow the terminal auto closed itself after executig my script, apparently my script should always left it on listening to the port...is there a reason for this? Commented Aug 3, 2015 at 3:31
  • I doubt it would be killing your script for some reason. If the script ended, it ended of its own accord. However, if it backgrounded itself I guess that might happen. If that's the case you could use a shell script wrapper that executes the node script, then exec bash to replace itself with a normal bash shell. Commented Aug 3, 2015 at 10:55
  • Thanks goldilocks, however I'm new to shell script stuff. Is there a reference for creating a shell script? Commented Aug 3, 2015 at 15:44
  • I've edited in an example. That needs to be executable (chmod 755 whatever.sh). Commented Aug 3, 2015 at 15:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.