Goal: Configure to load tomcat on startup on MAC Sierre
Write launchd_tomcat_wrapper.sh
#!/bin/bash
function shutdown()
{
date
echo "Shutting down Tomcat"
$CATALINA_HOME/bin/catalina.sh stop
}
date
echo "Starting Tomcat"
export CATALINA_PID=/tmp/$$
# Uncomment to increase Tomcat's maximum heap allocation
# export JAVA_OPTS=-Xmx512M $JAVA_OPTS
. $CATALINA_HOME/bin/catalina.sh start
# Allow any signal which would kill a process to stop Tomcat
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
echo "Waiting for `cat $CATALINA_PID`"
wait `cat $CATALINA_PID`
Write org.apache.tomcat.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>CATALINA_HOME</key>
<string>/Applications/tomcat</string>
<key>JAVA_HOME</key>
<string>/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home</string>
</dict>
<key>Label</key>
<string>org.apache.tomcat</string>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/Users/uytran/Applications/tomcat/launchd_tomcat_wrapper.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/uytran/Applications/tomcat/logs/launchd.stderr</string>
<key>StandardOutPath</key>
<string>/Users/uytran/Applications/tomcat/logs/launchd.stdout</string>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
Move org.apache.tomcat.plist to /Library/LaunchDaemons
Note: Change mode 775 for /Users/uytran/Applications/tomcat and /Applications/tomcat
Load service manually: sudo launchctl load -w org.apache.tomcat.plist
Unload service manually: sudo launchctl unload -w org.apache.tomcat.plist
Check log launchctl : /var/log/system.log
Write launchd_tomcat_wrapper.sh
#!/bin/bash
function shutdown()
{
date
echo "Shutting down Tomcat"
$CATALINA_HOME/bin/catalina.sh stop
}
date
echo "Starting Tomcat"
export CATALINA_PID=/tmp/$$
# Uncomment to increase Tomcat's maximum heap allocation
# export JAVA_OPTS=-Xmx512M $JAVA_OPTS
. $CATALINA_HOME/bin/catalina.sh start
# Allow any signal which would kill a process to stop Tomcat
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
echo "Waiting for `cat $CATALINA_PID`"
wait `cat $CATALINA_PID`
Write org.apache.tomcat.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>CATALINA_HOME</key>
<string>/Applications/tomcat</string>
<key>JAVA_HOME</key>
<string>/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home</string>
</dict>
<key>Label</key>
<string>org.apache.tomcat</string>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/Users/uytran/Applications/tomcat/launchd_tomcat_wrapper.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/uytran/Applications/tomcat/logs/launchd.stderr</string>
<key>StandardOutPath</key>
<string>/Users/uytran/Applications/tomcat/logs/launchd.stdout</string>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
Move org.apache.tomcat.plist to /Library/LaunchDaemons
Note: Change mode 775 for /Users/uytran/Applications/tomcat and /Applications/tomcat
Load service manually: sudo launchctl load -w org.apache.tomcat.plist
Unload service manually: sudo launchctl unload -w org.apache.tomcat.plist
Check log launchctl : /var/log/system.log
Nhận xét
Đăng nhận xét