开发者

java install tomcat as service

开发者 https://www.devze.com 2023-03-10 03:48 出处:网络
I\'m developing a installation wizard to install an application on linux, and as part of installation installs tomcat and set it as service开发者_高级运维 to start automatically when system boots. Can

I'm developing a installation wizard to install an application on linux, and as part of installation installs tomcat and set it as service开发者_高级运维 to start automatically when system boots. Can someone help me to figure it out? (installing tomcat on linux and settingJava it as service ONLY and ONLY through Java code)


Here's an idea but bear in mind you can do most of the following in Java but not all of it in Java:

  • in most Linux distros the services are in /etc/init.d -- though the path can vary and also be /etc/rc.d/init.d -- so you need to check which one applies. Typically you would copy in there a shell script which starts your service.
  • However, the shell script itself is normally distro dependent, but you can prepare multiple shell scripts -- one per distro and figure out which distribution it is by launching the command uname -a and parse the output of that to determine the distro and as such which script to copy to /etc/init.d. You will need to give read/execute permissions on this script but this can be done by launching chmod
  • you then would typically symlink this script to /etc/rc2.d/ or /etc/rc3.d/ -- you can symlink it in both; however, you can't do symlinking in Java -- you will need to employ some native library;
  • or alternatively simply copy your script in those directories as well; though this does mean that now you have 3 points of configuration (/etc/init.d/, /etc/rc2.d and /etc/rc3.d/) which is not ideal
  • or another idea is to launch ln -s /etc/init.d/yourscript /etc/rc2.d/name to make the symlink

This does mean though that your installation will only work on Linux. Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消