I see this reference to open the app directly autostart app in LXDE but is there a way to also start my nodejs script?
1 Answer 1
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.
-
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?Derrick– Derrick2015年08月03日 03:31:40 +00:00Commented 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.goldilocks– goldilocks2015年08月03日 10:55:42 +00:00Commented 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?Derrick– Derrick2015年08月03日 15:44:13 +00:00Commented Aug 3, 2015 at 15:44
-
I've edited in an example. That needs to be executable (
chmod 755 whatever.sh
).goldilocks– goldilocks2015年08月03日 15:59:52 +00:00Commented Aug 3, 2015 at 15:59