LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   running java program at startup in background (https://www.linuxquestions.org/questions/linux-newbie-8/running-java-program-at-startup-in-background-484386/)

Maverick1182 09-17-2006 01:09 PM

running java program at startup in background
 
Hi there, i know how to run modules and bash scripts at startup but can anyone tell me how i can run a java script in the background? i need to be able to run the Mr postman java script without opening a console up everytime and running the following command:

java -jar /usr/local/MrPostman/MrPostman-20060106.jar

I've noticed that it outputs stuff in the window which it is being run, will this be a problem if it is run in the background? Most help guides say the command needs to return to the command prompt. On running this command it does not let you go back to the prompt until you strike ctrl+C


Do I simply need to add an & to the end of this command and then copy it to /etc/conf.d/local.start(is this still correct for gentoo) ?

Vgui 09-19-2006 11:25 AM

Yep, you should be able to throw a & on the end and add it to the startup script. I'd recommend piping the output to a log though (just in case). Also, you might need to source your bash profile first to ensure that JAVA_HOME is set properly. I'd try something like:
Code:

source ~/.bashrc
java -jar /bla/bla/bla.jar &> logfile.txt &


Maverick1182 09-19-2006 02:04 PM

K, will it append to the log every time it runs? or does it over right it? i creates a lot of output when i'm accessing my mails and i dont want the file getting larger and larger.... alough i could probably run a command at shutdown to delete the file. wow. linuxs kick windows bum! lol thanks again :)

Vgui 09-19-2006 02:12 PM

Yep, using a single > will cause a new log file to be created each time. You can use >> to append to an existing file. Heck you could throw it into logrotate and let it be gzipped and cycled like all the /var/log/ stuff. Or, don't even log it, the choice is yours (which is part of why Linux kicks Windows bum, as you say ;))

Maverick1182 09-19-2006 06:09 PM

i tried adding the following lines to the

source ~/.bashrc
java -jar /usr/local/MrPostman/MrPostman-20060106.jar & >> /home/mark/mailoutput.txt &

i gave no joy when it booted so i copied and pasted into a console as i figured it should do the same thing...

unfortunately it still outputs to the screen whilst creating the required file which has nothing in it :(

Am i not piping correctly? Should there be an & at the end of java line? any ideas? Thanks for your help so far though Vgui


All times are GMT -5. The time now is 07:35 AM.