添加开启自动启动 Apache nginx redis 脚本

linux 专栏收录该内容
5 篇文章 0 订阅
apache开机自动启动
拷贝安装目录下的启动脚本
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
 
编辑启动脚本 添加启动顺序
vim /etc/init.d/httpd
# chkconfig: 35 70 30
# description: Apache
 
加入启动项
chkconfig --level 35 httpd on
 
验证
chkconfig --list|grep http
 
 
 
nginx

把以下脚本保存为nginx文件放入/etc/init.d/nginx

然后可以通过
/etc/init.d/nginx start 命令启动nginx
/etc/init.d/nginx stop 命令停止nginx
/etc/init.d/nginx restart 命令重启nginx

开机自动启动nginx,

如果需要开机启动服务,保存好 /etc/init.d/nginx文件后,

执行以下命令:

chkconfig --add nginx

chkconfig --level  2345 nginx  on

 

vim /etc/init.d/nginx

---------------------分割线下是脚本内容,红色字体需要你修改-------------------------------------------
#! /bin/sh

# chkconfig: 35 70 30

# description: nginx

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

 
 
redis 
 
 

vim /etc/init.d/redis

 

#! /bin/sh

 

 

# chkconfig: 2345 10 90
# description: Start and Stop redis

 

PATH=/usr/local/bin:/sbin:/usr/bin:/binREDISPORT=6379EXEC=/usr/local/redis/bin/redis-serverREDIS_CLI=/usr/local/redis/bin/redis-cliPIDFILE=/var/run/redis.pidCONF= "
 
/usr/local/redis
/etc/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 -a $AUTH  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
 
验证
chkconfig --list|grep redis
 
 
 开机执行程序
/etc/rc.d/目录下的初始化程序很多,rc.local是在完成所有初始化之后执行的,所以在这里做手脚很合适。
  1. cd /etc/rc.d/  
  2. vi rc.local 
 
加入要执行的程序
su -  www -c "setsid /home/ www/svnrsync/sync.sh"
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值