In our team, we have a lot of Java standalone applications which should be run as daemon on Unix/Linux system, and we found JSVC is the best choice for us to wrap Java programs to daemons. This article records the steps on how to install JSVC executable on Linux, which is our stage/prod environment.
Download JSVC source package
First of all, we need to download JSVC source package from this URL:http://commons.apache.org/daemon/download_daemon.cgi, for example, I downloaded commons-daemon-1.0.5-src.tar.gz file. Or, download it via wget:
wget -c http://apache.etoak.com/commons/daemon/source/commons-daemon-1.0.5-src.tar.gz
Build JSVC executable
Unzip the source package and build JSVC executable.
chmod 755 commons-daemon-1.0.5-src.tar.gz tar zxvf commons-daemon-1.0.5-src.tar.gz cd commons-daemon-1.0.5-src/src/native/unix
Before building the JSVC executable, please make sure you have set JAVA_HOME variable correctly. And make sure you have “autoconf” and “make” installed, otherwise, install it by:
yum install autoconf yum install make
After that, we can configure and make the JSVC executable now.
sh support/buildconf.sh ./configure --with-java=/opt/apps/jdk make clean make
Eventually, move the “jsvc” to another folder and add that folder on PATH environment variable.
mv jsvc /opt/apps/commons-daemon vi ~/.bashrc
Add two lines in .bashrc:
PATH=/opt/apps/commons-daemon:$PATH export PATH
And then load the latest setting:
source ~/.bashrc
Now, we can use this command in script which will launch Java application as daemon.
Please make sure to add commons-daemon-x.jar into classpath, otherwise, we would see this error:
Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader Service exit with a return value of 1
For more information on how to use jsvc command, please refer tohttp://commons.apache.org/daemon/jsvc.html
thanks, this was very usefull!
ReplyDeletethanks, helps alot
ReplyDelete404, Thanks, asshole
ReplyDeleteRespect and that i have a dandy present: How Much Is A Complete House Renovation whole home remodel cost
ReplyDelete