博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centOS7添加开机启动服务/执行脚本
阅读量:3952 次
发布时间:2019-05-24

本文共 1066 字,大约阅读时间需要 3 分钟。

centOS7添加开机启动服务/执行脚本

开机执行脚本

在centos7中增加脚本有两种常用的方法:

1.修改/etc/rc.d/rc/local文件并修改配置2.脚本放到/etc/rc.d/init.d目录下并进行配置

以下示例以脚本autostart.sh为例:

#!/bin/bash# description:开机自启脚本# 启动tomcat/usr/local/tomcat/bin/startup.sh

一. 修改/etc/rc.d/rc/local文件并修改配置

1、赋予自定义脚本可执行权限(/opt/script/autostart.sh是自定义脚本)

chmod +x /opt/script/autostart.sh

2、打开/etc/rc.d/rc/local文件,在末尾增加如下内容

/opt/script/autostart.sh

3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限

chmod +x /etc/rc.d/rc.local

二. 脚本放到/etc/rc.d/init.d目录下并进行配置

1、将脚本移动到/etc/rc.d/init.d目录下

mv  /opt/script/autostart.sh /etc/rc.d/init.d

2、增加脚本的可执行权限

chmod +x  /etc/rc.d/init.d/autostart.sh

3、添加脚本到开机自动启动项目中

cd /etc/rc.d/init.dchkconfig --add autostart.shchkconfig autostart.sh on
  • 可能会报错:service ×××.sh does not support chkconfig

添加下面两句到 #!/bin/bash 之后。

# chkconfig: 2345 10 90 # description: myservice
  • 注:chkconfig命令对应的目录是/etc/rc.d/init.d文件夹下,需要将自启动脚本拷贝至该文件目录下。

其中2345是默认启动级别,级别有0-6共7个级别。

等级0表示:表示关机

等级1表示:单用户模式

等级2表示:无网络连接的多用户命令行模式

等级3表示:有网络连接的多用户命令行模式

等级4表示:不可用

等级5表示:带图形界面的多用户模式

等级6表示:重新启动

10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低。

转载地址:http://gthwi.baihongyu.com/

你可能感兴趣的文章
Remembering Your User 记住你的用户
查看>>
Authenticating to OAuth2 Services 验证OAuth2服务
查看>>
Creating a Custom Account Type 创建自定义帐户类型
查看>>
Sending Content to Other Apps 将内容发送到其他应用程序
查看>>
Receiving Content from Other Apps 接收来自其他应用程序的内容
查看>>
Adding an Easy Share Action 添加一个简单的共享行动
查看>>
Taking Photos Simply 简单地拍摄照片
查看>>
Recording Videos Simply 简单录制视频
查看>>
Controlling the Camera 控制相机
查看>>
Creating Multiple APKs for Different API Levels 创建多个不同的API级别的APK
查看>>
Creating Multiple APKs for Different Screen Sizes 创建多个APKs为不同的屏幕尺寸
查看>>
Creating Multiple APKs for Different GL Textures 创建多个APK给不同的GL结构
查看>>
Android Package and Manifest File
查看>>
Creating Multiple APKs with 2+ Dimensions 创建两种以上屏幕尺寸多apk支持
查看>>
Abstracting the New APIs 抽象出新的API
查看>>
Proxying to the New APIs 代理新的API
查看>>
Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
查看>>
Using the Version-Aware Component 使用版本识别组件
查看>>
Enhancing Security with Device Management Policies 加强安全与设备管理策略 Developing for Enterprise
查看>>
Advertising without Compromising User Experience 不降低用户体验的广告
查看>>