LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-24-2007, 02:37 PM   #1
guitar_199
LQ Newbie
 
Registered: Jul 2006
Location: Deer Park, Texas
Distribution: Slackware 11.0
Posts: 16

Rep: Reputation: 0
Starting a Java program on system startup


I have written a small Java utility that my employer would like to run...but it has to be started at boot time and it has to stay running.

I have tried starting it both via inittab (which I have to admit is a little weird, we called a script that starts it) and by starting it in rc.local. The best we have seen is that, when the system boots, it does start up. But, when the login to the user's environment, it is gone.

It's just a simple little Window frame with three buttons, each button issues a different shell command string. If I start it manually it runs fine, hangs around on screen as long as I want, and when I click the button it does what I want. I just can't get it to start at system startup time.

Any hints would most certainly be appreciated.

Bob
 
Old 09-24-2007, 02:52 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Your graphic application is running on top of the X11 server.
The X server being restarted between user sessions, your program just can't survive.
You'd rather have it being launched each time users start their graphic environment, not once when the machine starts.
 
Old 09-24-2007, 03:11 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
When you say you want it run at start up, do you mean each time you log in? If you wish it to be running when you are logged in, and you wish to see it, and it has a graphical window (X), it can only last as long as your X session. AFAIK, programs with windows cannot persist accros a login/logout session change, although I could be wrong. If you just want the program running whenever you log in, check out your desktop environment for session management facilities or some autorun function, e.g. in KDE the ~/.kde/Autostart directory.

If it can be run without a GUI, you should be able to run it from rc.local or inittab. rc.local is probably the correct place - be wary of putting things in inittab unless you absolutely have to. You get the respawn-on-crash mechanism there, but if you mess up your inittab, you can make a big mess which is a pain to sort out.

If the program will not run without a GUI, and if you do not need to see or interact with the program's GUI, consider running it using a "fake" X server, such as Xvfb. This can be run in the background and will not be affected by users logging in and logging out. You will not however be able to see or interact with the program on your main display.
 
Old 09-24-2007, 04:15 PM   #4
guitar_199
LQ Newbie
 
Registered: Jul 2006
Location: Deer Park, Texas
Distribution: Slackware 11.0
Posts: 16

Original Poster
Rep: Reputation: 0
The original program that I am replacing is started out of inittab and gets respawned. So essentially I suppose that it might actually die between sessions but be respawned again for the new session. The Java command does not accept a -display parameter to get the display window specified, so I did all of that in a script and called the script in inittab. This isn't very elegant and isn't particularly working well either. What I discovered a little later that, with it set up in this manner (and yes it is set to respawn), when I log on, the window for the Java prog is not there. WHen I exit out of the ssh window that I came in on..... about 10 of them pop up. So respawn is obviously respawning more than the once I need... I am obviously doing this in a manner that isn't reflecting that the JVM is up and running the program properly.

What I did in the shell is this
(ps.... I know this looks really bad in terms of form, but for now I am stuck. We cant
change everything and it really will run this way... I hope that you can try to see through that....)

#/bin/sh
export DISPLAY=:0.0
/usr/src/java/j2sdk1.4.2/bin/java -classpath /usr/src/java/j2sdk1.4.2/bin ThreeButtonControl


this is in a script called init.java

when the system is first loaded, it runs it.
After I do the X login, it disappears.

I come in through an ssh, get in to /etc, call init.java and it pops up just fine and stays there. I cancel it. I log out.... and KABAM. About ten of them appear.....all at once... and..if I hit a button they work.

Did I mention that I love my job?
 
Old 09-24-2007, 04:21 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
If you only want this program to run when you are logged into the system, do not run it from inittab, it is totally the wrong approach. inittab is not for user programs - only for daemons. The proper place is in your desktop environment startup files.

What desktop environment do you use, KDE, Gnome, XFCE, other?
 
Old 09-24-2007, 05:04 PM   #6
guitar_199
LQ Newbie
 
Registered: Jul 2006
Location: Deer Park, Texas
Distribution: Slackware 11.0
Posts: 16

Original Poster
Rep: Reputation: 0
Well....it isnt really a user...per se
Their design, as it sits, is to boot the RHEL4 box up as a dumb xterminal waiting on the main simulation machine(SGI). When the SGI detects the RH box, it starts up a login process of it's own, but sets the DISPLAY to the RHEL linux box. SO you get a display on the Linux system, you log in on the linux system, but you are actually logging in to the SGI. Essentially the Linux/RHEL4 box is just a big X terminal. And again, the program we are replacing works fine out of inittab. They have reasons for wanting to replace it and the program I have running is what they want. Again, I know that, if I start it locally, it will run. But no one is running on the local box. No one is logged in.... the way they have it set up, no one ever logs in on the RH/Linux box.

That said, I really appreciate the sentiment but this is a working system, been deployed for two years, we just want to take out one old process and put in one new one in it's place.
 
Old 09-25-2007, 04:23 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
As already stated several times. Using startup scripts for what you want to achieve is the wrong approach, and using inittab is even worse. Your application isn't a daemon nor a one shot startup script.

As your goal is simply to have that application window to appear each time the X server is (re)started, just add your command to whatever Xsession launch script your system is using.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting MySQL automatically on Slackware 10 on system startup abtimoteo Slackware 2 09-24-2007 01:40 AM
starting httpd during system startup - problems - HELP! noobinacan Linux - Software 2 02-06-2007 07:24 PM
running java program at startup in background Maverick1182 Linux - Newbie 4 09-19-2006 06:09 PM
Starting program on startup with gdm and fluxbox? 95se Linux - Software 4 03-22-2004 12:47 PM
Starting a program at blackbox startup, to open on a different workspace. luc-allouette Linux - Software 2 09-01-2003 07:50 PM


All times are GMT -5. The time now is 08:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration