- GeoServer Beginner's Guide(Second Edition)
- Stefano Iacovella
- 582字
- 2021-07-08 09:21:10
Configuring Tomcat as a service on Linux Mint
When installing on Windows, the setup configures Tomcat as a system service. This way, it will start when the computer boots without any user action. Are you wondering why do you have to manually start and stop Tomcat on Linux? You do not. As for Windows, the Linux operating system can be configured for an automatic start of programs.
In this section, you will create a script and learn how it works:
- Download the tomcat file from the Packt site for this book and save it on your machine. You have to move it to the /etc/init.d folder.
- Open it with the vi editor as follows:
~ $ sudo vi /etc/init.d/tomcat
- There are some key settings you need to check in this file. The following lines contain the location of JRE and Tomcat. You can modify them according to your environment:
export JAVA_HOME=/opt/java/jre1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH export CATALINA_HOME=/opt/apache-tomcat-8.5.13
- Now, set the permissions for your script to make it executable using the following:
~ $ sudo chmod a+x /etc/init.d/tomcat
- Let's try to call it and check for any problems:
~ $ sudo service tomcat Usage: /etc/init.d/tomcat {start|stop|restart}
- Try starting Tomcat by:
~ $ sudo service tomcat start
- To check if Tomcat started without errors, you can open the home page with your browser, as you did in a previous example, or you can check for the process to be running. For this second way, you have to use a ps shell command that returns the list of all the processes currently running on your machine. Piping the list to grep and searching for the Java string, you will find the Tomcat instance:
~ $ ps -ef | grep java root 1447 1 4 18:18 ? 00:01:21 /usr/bin/java -
Djava.util.logging.config.file=/opt/apache-tomcat-8.5.5/conf/
logging.properties -Djava.util.logging.manager=org.apache.juli.
ClassLoaderLogManager -Djava.awt.headless=true -Xms1536m
-Xmx1536m -XX:PermSize=256m -XX:MaxPermSize=256m
-Djdk.tls.ephemeralDHKeySize=2048 -classpath /opt/apache-
tomcat-8.5.5/bin/bootstrap.jar:/opt/apache-tomcat-8.5.5/
bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-
tomcat-8.5.5 -Dcatalina.home=/opt/apache-tomcat-8.5.5
-Djava.io.tmpdir=/opt/apache-tomcat-8.5.5/temp
org.apache.catalina.startup.Bootstrap start
- We have successfully created a script to start and stop Tomcat, but this still requires you to run it manually from the command shell. For an automatic startup, the last step is adding it to configured services. We will use a system utility, update-rc, to do this:
~ $ sudo update-rc.d tomcat defaults
- The previous command creates a set of files in some special folders. Each time your operating system changes its run level, for example, when you boot or halt it, the script contained in these folders is executed, so Tomcat will be started or killed. You can take a look at these files:
~ $ ls -l /etc/rc?.d/*tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc0.d/K01tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc1.d/K01tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc2.d/S02tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc3.d/S02tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc4.d/S02tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc5.d/S02tomcat
-> ../init.d/tomcat lrwxrwxrwx 1 root root 16 Oct 6 16:18 /etc/rc6.d/K01tomcat
-> ../init.d/tomcat
We created a shell script to start Apache Tomcat. Now, when you boot your Linux machine, Tomcat will automatically start and all the web application content will be available for user requests. If you prefer to manually start and stop Tomcat, the script could yet be useful for you. Just create it as described and avoid the last step. You will use the script to start or stop Tomcat from the command line, that is, sudo tomcat start or sudo tomcat stop.
- Deploying Node.js
- Java范例大全
- Python 3.7網絡爬蟲快速入門
- 工程軟件開發技術基礎
- Backbone.js Blueprints
- 嚴密系統設計:方法、趨勢與挑戰
- Bootstrap 4:Responsive Web Design
- JavaScript 程序設計案例教程
- C語言程序設計
- jQuery Mobile移動應用開發實戰(第3版)
- Learning Unreal Engine Android Game Development
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- 黑莓(BlackBerry)開發從入門到精通
- Instant GLEW
- 編程的原則:改善代碼質量的101個方法