Tomcat 做成服务
vim /usr/lib/systemd/system/tomcat.service
输入以下内容,并保存
[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
终端执行:
systemctl enable tomcat.service
vim setenv.sh
输入以下内容
# add java home
export JAVA_HOME=/root/jdk1.8.0_77
测试
service tomcat start
redis 制作启动脚本
加入以下内容
#!/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
加入启动并设置权限
chkconfig redis on
chmod a+x /etc/init.d/redis
测试
/etc/init.d/redis start
activemq 制作服务
增加activemq.service
vim /usr/lib/systemd/system/activemq.service
插入以下内容
[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
测试系统自启动
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
设置自启动
需要修改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可能没有执行权限需要赋一下权限
chmod a+x /etc/rc.local
其它Java控制台程序
可以使用Maven的appassembler-maven-plugin的插件,制作成后台程序,之后就可以和Mycat一样了
原文链接:https://www.f2er.com/centos/379496.html