如何compile daemon出來請參考:http://tomcat.apache.org/tomcat-7.0-doc/setup.html#Unix_daemon
只要做完第一個步驟,將compile出來的jsvc執行檔複製到$CATALINA_HOME/bin底下即可,此時在bin目錄下除了jsvc之外,還有一個重要的daemon.sh。
編輯daemon.sh增加兩行comment,如下方所示紅色部分:
daemon.sh
#!/bin/sh
#
# chkconfig: 35 90 10
# description: Start/Stop the Tomcat daemon.
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
35代表level 3和5會啟動這個service,90代表啟動順序,10代表關閉順序。
#
# chkconfig: 35 90 10
# description: Start/Stop the Tomcat daemon.
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
接下來切換到root身分,到/etc/init.d底下執行:
- ln -s $CATALINA_HOME/bin/daemon.sh tomcat
- chkconfig -add tomcat
這樣就已經完成service安裝,可以執行以下指令試驗看看開關Tomcat:
- /sbin/service tomcat start
- /sbin/service tomcat stop
預設service會用tomcat這個user啟動,如果沒有這個user可以先建一個,或是在$CATALINA_HOME/bin/setenv.sh裡面加入TOMCAT_USER=user name就可以了。