zl程序教程

您现在的位置是:首页 >  后端

当前栏目

将java程序成为linux的系统服务

2023-09-14 08:56:51 时间
在分布式环境开发中经常会使用socket,或者使用rmi来对外提供服务,常用的办法是将写一个java代码,然后部署到服务器上,但是问题来了。如何将这个服务成为一个可靠的系统服务,不会应为风吹草动就挂了,那就不好了。 所以想到使用apache commons 下面的daemon框架来充当守护进程。首

在分布式环境开发中经常会使用socket,或者使用rmi来对外提供服务,常用的办法是将写一个java代码,然后部署到服务器上,但是问题来了。如何将这个服务成为一个可靠的系统服务,不会应为风吹草动就挂了,那就不好了。

所以想到使用apache commons 下面的daemon框架来充当守护进程。首先需要在系统中安装jsvc工具具体操作方法这里不作详细说明,请查看 http://commons.apache.org/daemon/jsvc.html

最后jsvc安装成功之后需要有执行 jsvc -help 会显示以下内容:


-cp / -classpath directories and zip/jar files set search path for service classes and resouces -home directory set the path of your JDK or JRE installation (or set the JAVA_HOME environment variable) -version show the current Java environment version (to check correctness of -home and -jvm. Implies -nodetach) -showversion show the current Java environment version (to check correctness of -home and -jvm) and continue execution. -nodetach dont detach from parent process and become a daemon -debug


/home/baisui/commons-daemon-1.0.10-native-src/unix/jsvc -pidfile ./pidfile.pid -outfile ./logs/trigger_server_out.log -errfile ./logs/trigger_server_err.log -cp $CLASSPATH com.taobao.terminator.trigger.LaunchServer
stop(){ /home/baisui/commons-daemon-1.0.10-native-src/unix/jsvc -stop -pidfile ./pidfile.pid -cp $CLASSPATH com.taobao.terminator.trigger.LaunchServer echo "trigger_server stopped"
从 Linux 内核线程反观 Java Go 的线程模型 原文参考我的个人公众号文章(欢迎关注!):[点此链接进入](https://mp.weixin.qq.com/s?__biz=MzkxNDMyNjk0Mw== mid=2247484374 idx=1 sn=5e5c8ef7adc0841019cb3302ed5003db chksm=c1715726f606de301494abf87fbdc40303bdb9ac8393333b0778e23