Linux 自启动脚本

2022/4/25 7:14:50

本文主要是介绍Linux 自启动脚本,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

/etc/rc.d 文件会在 Linux 系统各项服务都启动完毕之后再被运行

  1. 新建xxx.sh脚本文件。
  2. chmod +x xxx.sh,赋予可执行权限,此时文件会变色。

 

#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
echo "启动es"
ES_PID=`ps -ef | grep elasticsearch | grep -v grep | awk '{print $2}'`
if [  ! -z "$ES_PID" ] ; then
     echo "es is runing...pid:$ES_PID"
else
    echo "start es"
    cd '/data/tools/elasticsearch-7.3.0/bin'
    ph=`pwd`
    echo "$ph"
    su - elasticsearch -c 'sh /data/tools/elasticsearch-7.3.0/bin/elasticsearch -d;exit'    
fi

echo "启动nacos"
NACOS_PID=`ps -ef | grep nacos | grep -v grep | awk '{print $2}'`
if [  ! -z "$NACOS_PID" ] ; then
    echo "nacos is runing...pid:$NACOS_PID"
else
    echo "start nacos"
    cd /data/nacos/bin
    nohup sh startup.sh -m standalone &
fi

echo "启动redis"
REDIS_PID=`ps -ef | grep redis | grep -v grep | awk '{print $2}'`
if [  ! -z "$REDIS_PID" ] ; then
    echo "redis is runing...pid:$REDIS_PID"
else
    echo "start REDIS"
    cd /data/tools/redis-4.0.2/src
    redis-server ../redis.conf
fi

echo "启动nginx"
NGINX_PID=`ps -ef | grep nginx | grep -v grep | awk '{print $2}'`
if [  ! -z "$NGINX_PID" ] ; then
    echo "nginx is runing...pid:$NGINX_PID"
else
    echo "NGINX REDIS"
    /usr/local/nginx/sbin/nginx
fi

echo "启动MySQL"
MYSQL_IS_START=`netstat -lntup |grep 3306|wc -l`
if [ $MYSQL_IS_START -eq 1 ] ; then
    echo "mysql is runing..."
else
    echo "start mysql"
    service mysqld start
fi

 



这篇关于Linux 自启动脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程