Centos7解决rc.local自启动失败问题

  1. 前言:是这种问题再往下看吧 

   我的目的是在服务器启动后 通过  rc.local  去进行开机自启动 我们所写脚本 .sh  但是开机启动时候没有反应   那就是有可能你的  rc.local  开机后并没有 启动成功有报错   

systemctl start rc-local.service   命令可以输入启动试一下   会返回

Job for rc-local.service failed because the control process exited with error code. See "systemctl status rc-local.service" and "journalctl -xe" for details.

大概这种的报错信息   但是  。。。。。。。。。。  别紧张  解决方式很简单   

 status rc-local.service" and "journalctl -xe" for details. 报错信息里面告诉我们了可以使用     journalctl -xe  来查看日志

先给大家看一下我  journalctl -xe  后的报错信息

[root@localhost ~]# journalctl -xe
10月 29 15:20:01 localhost.localdomain CROND[4113]: (root) CMD (/usr/lib64/sa/sa1 1 1)
10月 29 15:21:09 localhost.localdomain polkitd[889]: Registered Authentication Agent for unix-process:5585:13777 (system bus name :1.100 [/us
10月 29 15:21:09 localhost.localdomain systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
-- Subject: Unit rc-local.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rc-local.service has begun starting up.
10月 29 15:21:09 localhost.localdomain rc.local[5591]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:09 localhost.localdomain rc.local[5591]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:09 localhost.localdomain rc.local[5591]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:09 localhost.localdomain rc.local[5591]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:09 localhost.localdomain systemd[1]: rc-local.service: control process exited, code=exited status=126
10月 29 15:21:09 localhost.localdomain systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
-- Subject: Unit rc-local.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rc-local.service has failed.
-- 
-- The result is failed.
10月 29 15:21:09 localhost.localdomain systemd[1]: Unit rc-local.service entered failed state.
10月 29 15:21:09 localhost.localdomain systemd[1]: rc-local.service failed.
10月 29 15:21:09 localhost.localdomain polkitd[889]: Unregistered Authentication Agent for unix-process:5585:13777 (system bus name :1.100, o
10月 29 15:21:17 localhost.localdomain polkitd[889]: Registered Authentication Agent for unix-process:5779:14571 (system bus name :1.101 [/us
10月 29 15:21:17 localhost.localdomain systemd[1]: Reloading.
10月 29 15:21:17 localhost.localdomain polkitd[889]: Unregistered Authentication Agent for unix-process:5779:14571 (system bus name :1.101, o
10月 29 15:21:22 localhost.localdomain polkitd[889]: Registered Authentication Agent for unix-process:5927:15120 (system bus name :1.102 [/us
10月 29 15:21:22 localhost.localdomain systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
-- Subject: Unit rc-local.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rc-local.service has begun starting up.
10月 29 15:21:22 localhost.localdomain rc.local[5934]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:22 localhost.localdomain rc.local[5934]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:22 localhost.localdomain rc.local[5934]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:22 localhost.localdomain rc.local[5934]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:22 localhost.localdomain rc.local[5934]: /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件
10月 29 15:21:22 localhost.localdomain systemd[1]: rc-local.service: control process exited, code=exited status=126
10月 29 15:21:22 localhost.localdomain systemd[1]: Failed to start /etc/rc.d/rc.local Compatibility.
-- Subject: Unit rc-local.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rc-local.service has failed.
-- 
-- The result is failed.
10月 29 15:21:22 localhost.localdomain systemd[1]: Unit rc-local.service entered failed state.
10月 29 15:21:22 localhost.localdomain systemd[1]: rc-local.service failed.
10月 29 15:21:22 localhost.localdomain polkitd[889]: Unregistered Authentication Agent for unix-process:5927:15120 (system bus name :1.102, o

问题就出现在这  : /etc/rc.d/rc.local: /usr/local/hengsen/java.sh: /bin/bash^M: 坏的解释器: 没有那个文件

/usr/local/hengsen/java.sh 脚本的解释器行存在问题!

那就解决这个问题    /bin/bash^M      脚本在执行的时候 ^M可能不被系统所识别或解释不到  所产生的问题  

解决方式:  安装  dos2unix 

sudo yum install dos2unix

然后使用命令 处理一下就好了

[root@localhost ~]# dos2unix /etc/rc.d/rc.local
dos2unix: converting file /etc/rc.d/rc.local to Unix format ...

dos2unix: converting file /etc/rc.d/rc.local to Unix format ...有这种就成功了  
dos2unix 命令后面跟 你报错的.sh脚本   处理后

使用  systemctl start rc-local.service  命令你就会看到没有   Job for rc-local.service  报错 并且脚本正在执行!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值