Tomcat 做成服務(wù)
增加tomcat.service文件
vim /usr/lib/systemd/system/tomcat.service
輸入以下內(nèi)容匀奏,并保存
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/root/tomcat.pid
ExecStart=/root/apache-tomcat-8.0.33/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
終端執(zhí)行:
systemctl enable tomcat.service
在tomcat的bin目錄中增加文件
vim setenv.sh
輸入以下內(nèi)容
# add java home
export JAVA_HOME=/root/jdk1.8.0_77
測試
service tomcat start
redis 制作啟動腳本
在/etc/init.d/增加redis文件
加入以下內(nèi)容
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
### BEGIN INIT INFO
# Provides: redis
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts redis
# Description: starts the redis FastCGI Process Manager daemon
### END INIT INFO
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/root/redis-3.2.5/src/redis-server
#EXEC=/usr/local/bin/redis-server
REDIS_CLI=/root/redis-3.2.5/src/redis-cli
PIDFILE=/run/redis_6379.pid
CONF="/root/redis-3.2.5/redis.conf"
AUTH="1234"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
sleep 2
while [ -x $PIDFILE ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
加入啟動并設(shè)置權(quán)限
chkconfig redis on
chmod a+x /etc/init.d/redis
測試
/etc/init.d/redis start
activemq 制作服務(wù)
增加activemq.service
vim /usr/lib/systemd/system/activemq.service
插入以下內(nèi)容
[Unit]
Description=Apache activemq
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/root/apache-activemq-5.13.2/data/activemq.pid
ExecStart=/root/apache-activemq-5.13.2/bin/activemq start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
測試系統(tǒng)自啟動
systemctl enable activemq.service
測試
service activemq start
Mycat 制作啟動腳本
這個比較簡單酿矢,直接將mycat/bin/mycat 做成鏈接到/etc/init.d/mycat
ln -s /root/mycat/bin/mycat /etc/init.d/mycat
測試
/etc/init.d/mycat start
設(shè)置自啟動
需要修改mycat/conf/wrapper.conf需要將java改成絕對路徑
#wrapper.java.command=java
wrapper.java.command=/root/jdk1.8.0_77/bin/java
再修改/etc/rc.local
在exit之前加入
/etc/init.d/mycat start
注意rc.local可能沒有執(zhí)行權(quán)限需要賦一下權(quán)限
chmod a+x /etc/rc.local
其它Java控制臺程序
可以使用Maven的appassembler-maven-plugin的插件,制作成后臺程序写烤,之后就可以和Mycat一樣了