Linux 开机执行脚本方法

1. 方式一修改/etc/rc.local

tail -2 /etc/rc.local

touch /root/aa.txt

/bin/bash /root/shell/redis-start.sh >/dev/null 2>/dev/null

2. 方式二chkconfig管理

  1> 第一种脚本

1#!/bin/sh 2#Configurations injected by install_server below.... 3 4EXEC=/usr/local/bin/redis-server 5CLIEXEC=/usr/local/bin/redis-cli 6PIDFILE=/var/run/redis_6379.pid 7CONF="/etc/redis/6379.conf" 8REDISPORT="6379" 9############### 10# SysV Init Information 11# chkconfig: - 58 74 12# description: redis_6379 is the redis daemon. 13### BEGIN INIT INFO 14# Provides: redis_6379 15# Required-Start: $network $local_fs $remote_fs 16# Required-Stop: $network $local_fs $remote_fs 17# Default-Start: 2 3 4 5 18# Default-Stop: 0 1 6 19# Should-Start: $syslog $named 20# Should-Stop: $syslog $named 21# Short-Description: start and stop redis_6379 22# Description: Redis daemon 23### END INIT INFO 24 25 26case "$1" in 27 start) 28 if [ -f $PIDFILE ] 29 then 30 echo "$PIDFILE exists, process is already running or crashed" 31 else 32 echo "Starting Redis server..." 33 $EXEC $CONF 34 fi 35 ;; 36 stop) 37 if [ ! -f $PIDFILE ] 38 then 39 echo "$PIDFILE does not exist, process is not running" 40 else 41 PID=$(cat $PIDFILE) 42 echo "Stopping ..." 43 $CLIEXEC -p $REDISPORT shutdown 44 while [ -x /proc/${PID} ] 45 do 46 echo "Waiting for Redis to shutdown ..." 47 sleep 1 48 done 49 echo "Redis stopped" 50 fi 51 ;; 52 status) 53 PID=$(cat $PIDFILE) 54 if [ ! -x /proc/${PID} ] 55 then 56 echo 'Redis is not running' 57 else 58 echo "Redis is running ($PID)" 59 fi 60 ;; 61 restart) 62 $0 stop 63 $0 start 64 ;; 65 *) 66 echo "Please use start, stop, restart or status as first argument" 67 ;; 68esac

  2 > 第二种方式

[root@redis ~]# cat /etc/init.d/redis-6379

#!/bin/bash

# chkconfig: 3 88 88

/bin/bash /server/scripts/redis-6379-start.sh >/dev/null 2>/dev/null

[root@redis ~]# chmod +x /etc/init.d/redis-6379

#添加到chkconfig,开机自启动

[root@redis ~]# chkconfig --add redis-6379

[root@redis ~]# chkconfig --list redis-6379

redis-6379               0:off    1:off    2:off    3:on    4:off    5:off    6:off

重启系统,查看结果

[root@redis ~]# cat /tmp/redis-6379-start.log
2020-12-19_09:59:10
操作成功

关闭开机启动

[root@redis ~]# chkconfig redis-6379 off
[root@redis ~]# chkconfig --list redis-6379
redis-6379               0:off    1:off    2:off    3:off    4:off    5:off    6:off
从chkconfig管理中删除redis-6379

[root@redis ~]# chkconfig --list redis-6379
redis_6379         0:关    1:关    2:开    3:开    4:开    5:开    6:关

[root@redis ~]# chkconfig --del redis-6379

[root@redis ~]# chkconfig --list redis-6379
服务 redis_6379 支持 chkconfig,但它未在任何运行级别中被引用(请运行“chkconfig --add redis_6379”)

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

swap空间的增减方法

(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Linux 开机执行脚本方法 - HelloWorld