CentOS中在/etc/rc.local添加開機自啟動項啟動失敗


應項目要求需要在開機的時候啟動自己的Agent程序,想當然的直接就往/etc/rc.local當中添加啟動命令,結果重啟之后發現什么都沒有發生....一開始還以為是Python路徑的問題,結果改成絕對路徑之后還是一樣,一番搜索之后發現原來是權限問題,執行chmod a+x /etc/rc.d/rc.local解決問題。

其實/etc/rc.local的說明當中已經說的很清楚了, /etc/rc.local只是為了兼容而設置的,若要執行需要為/etc/rc.d/rc.local添加執行權限,看來還是不能慌呀,項目再忙也不能亂了手腳,本來這種稍微看下文檔說明就解決了的問題,結果還是瞎折騰了一下,磨刀不誤砍柴工,古人誠不欺我。

  1. /etc/rc.local實為/etc/rc.d/rc.local的軟連接
[root@10-10-50-109 ~]# ls -l /etc/rc.local 
lrwxrwxrwx 1 root root 13 May 26 09:38 /etc/rc.local -> rc.d/rc.local
  1. /etc/rc.d/rc.local默認權限為不可執行
[root@10-10-50-109 ~]# ls -l /etc/rc.d/rc.local 
-rw-r--r-- 1 root root 473 Apr 13 03:57 /etc/rc.d/rc.local
[root@10-10-50-109 ~]# 
  1. /etc/rc.local當中的說明
[root@10-10-50-109 ~]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
[root@10-10-50-109 ~]# 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM