- 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.
- Facebook Application Development with Graph API Cookbook
- C++案例趣學
- Getting Started with React
- Learning Data Mining with Python
- 算法精粹:經典計算機科學問題的Java實現
- 21天學通C++(第6版)
- IBM Cognos TM1 Developer's Certification guide
- Java 9 Programming By Example
- 網絡數據采集技術:Java網絡爬蟲實戰
- Django Design Patterns and Best Practices
- 會當凌絕頂:Java開發修行實錄
- SQL Server 2012 數據庫應用教程(第3版)
- 軟件測試技術
- Kotlin語言實例精解
- WCF全面解析