Skip to content

Starting Java Application in init.d without Long Classpath in Command Line

January 10, 2010

The key is to use interesting /usr/bin/env command with launches Java process with given environment variables (e.g. CLASSPATH) and key return Java’s PID :)

. /lib/lsb/init-functions

ulimit -n $LIMIT_OFILE

options="CLASSPATH=$CP /usr/lib/jvm/java-6-sun/bin/java $JAVA_OPTS $MAIN_CLASS $OPTS"

if start-stop-daemon -v -b -m --oknodo -c $USER --start --quiet -d $bin_dir --pidfile "$pid_dir/myapp-$" --exec /usr/bin/env -- $options; then
log_end_msg 0
log_end_msg 1

so you can type

ps auxw | grep java

and enjoy short process names. long live linux!

Very Important Update: start-stop-daemon starts processes in none interactive mode and hence does not care about the limits you set in /etc/security/limits.conf . Unfortunately start-stop-daemon itself also does not provide any mechanism to see ulimits and hence one has to see its own limits via ulimits command before running above command inside the script.

While the application is running, its limits values are visible in the /proc file system.

sudo cat /proc/[PID]/limits
sudo ls -1 /proc/[PID]/fd/  | wc -l

From → java, linux

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: