File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes Startup Scripts in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Startup Scripts in Linux" Watch "Startup Scripts in Linux" New topic

Startup Scripts in Linux

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10031


How to set up some start up scripts in Linux. I want to start some of my applications during OS start up. How to do this?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

There are many mechanisms for accomplishing what you want. The easiest thing to do would be to check the FAQ for the flavor you have to see what the preferred method is for that distribution.

[How To Ask Questions On JavaRanch]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

In most cases, what you'll want is an "init script". Init scripts are started and stopped by the runlevel manager, and typically a Linux server will start up to either runlevel 3 (non-GUI, networked) or runlevel 5 (GUI). There's some interesting magic that gets applied to ensure that resource are running (or not) at a given runlevel and in the proper sequence so that pre-requisite resources are there (or not) when needed. It's not perfect, so Sun recently (Solaris 10) added an more sophisticated runlevel manager (not available to Linux, alas). And there's supposed to be improvements in the works for Linux as well, but they're slow in coming.

A typical runlevel script is headed up with some "magic comments" that the system can use to manage the script with. Red Hat/Fedora have one set, SuSe have another (with some overlap), and I forget the details from the Debian/Knoppix/Ubuntu platform. The master copies of the init scripts are stored in /etc/init.d, with aliases made to them to provide the actual runlevel control (this is typically done via the "chkconfig" utility). init scripts are expected to setup an environment (possibly starting a daemon) and returning. Don't make a long-running script, or it will hang the runlevel switching process, including the other apps.

The best thing to do is look at the scripts in your system's /etc/init.d directory. Some are pretty simple. Some are pretty nasty. But they'll help you get what you want.

Java apps are especially problematic, since the executable program's name is typically "java", rather than a unique appname, but there are tricks that can be done to make them reasonably co-operative.

An IDE is no substitute for an Intelligent Developer.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Jothi Shankar Kumar wrote:Guys,

How to set up some start up scripts in Linux. I want to start some of my applications during OS start up. How to do this?

Shall your scripts start some graphic application, or will they stay in the background?

Do they have to be started with admin privileges?

Do they need to run before a user is loged in, or may they start when a user starts a session?
It is sorta covered in the JavaRanch Style Guide.
subject: Startup Scripts in Linux
jQuery in Action, 3rd edition