创建非yum安装的redis和tomcat的开机自启文件

前言

       本地环境:CentOS Linux release 7.4.1708 (Core) 

       配置路径:/etc/init.d/

       系统服务:chkconfig

1.1、redis服务脚本

       在下载redis的gz包里,有utils目录,里面有redis_init_script脚本,类似下载的配置文件;也可以在/etc/init.d/目录里创建以下的脚本

vim /etc/init.d/redis

+++/etc/init.d/redis配置+++++++++++++++

#!/bin/bash
#chkconfig: 2345 10 90
#description: Start and Stop redis

REDISPORT=6379
EXEC=/usr/local/redis-4.0.10/src/redis-server
CLIEXEC=/usr/local/redis-4.0.10/src/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis-4.0.10/redis.conf"

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
        ;;
    stop)
        if [ ! -f $PIDFILE ];then
            echo "$PIDFILE does not exist,process is not running"
        else
            PID=$(cat $PIDFILE)
            echo "Stopping..."
            $CLIEXEC -p $REDISPORT shutdown
            while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac

+++/etc/init.d/redis配置文件+++++++++++++++

注释:

#chkconfig: 2345 10 90

         redis服务必须在运行级2,3,4,5下被启动或关闭,10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低。

 

1.2、在chkconfig添加redis服务管理

chmod +x /etc/init.d/redis

chkconfig --add redis

chkconfig redis on

service redis {start | stop | restart}

 

+++华丽的分隔线+++++++++++++++++++++

2.1创建tomcat服务脚本

vim /etc/init.d/tomcat

+++++/etc/init.d/tomcat配置++++++++

#!/bin/bash
# description: Tomcat7 Start Stop Restart
# processname: tomcat7
# chkconfig: 234 20 80

CATALINA_HOME=/usr/local/tomcat/

case $1 in
        start)
                sh $CATALINA_HOME/bin/startup.sh
                ;;
        stop)
                sh $CATALINA_HOME/bin/shutdown.sh
                ;;
        restart)
                sh $CATALINA_HOME/bin/shutdown.sh
                sh $CATALINA_HOME/bin/startup.sh
                ;;
        *)
                echo 'please use : tomcat {start | stop | restart}'
        ;;
esac

+++++/etc/init.d/tomcat配置++++++++

2.2、在chkconfig添加tomcat服务管理

chmod +x /etc/init.d/tomcat

chkconfig --add tomcat

chkconfig tomcat on

service tomcat {start | stop | restart}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值