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

LIMIT_OFILE=102400
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-$1.pid" --exec /usr/bin/env -- $options; then
log_end_msg 0
else
log_end_msg 1
fi

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
Advertisements

From → java, linux

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: