最近在虛擬機裡做 DRBD 實驗,用 chkconfig 管理服務時遇到一個惱人的錯誤。查詢狀態一切正常,可要開機自啟卻直接失敗:
root@node2:/root# chkconfig --list | grep drbd drbd 0:off 1:off 2:off 3:off 4:off 5:off 6:off root@node2:/root# chkconfig drbd on /sbin/insserv: No such file or directory
這是 Ubuntu 12.04 上相當典型的缺陷:chkconfig 只是一層外殼,真正的底層工作交給 insserv 完成,而它卻去了一個不存在的位置找程式。
root@node2:/root# whereis insserv insserv: /etc/insserv /etc/insserv.conf /usr/lib/insserv /usr/share/insserv /usr/share/man/man8/insserv.8.gz
把 whereis 列出來的位置逐一翻過一遍,會發現真正的執行檔躺在 /usr/lib/ 底下:
root@node2:/root# ls -l /usr/lib/insserv/ total 56 -rwxr-xr-x 1 root root 56368 Apr 9 19:07 insserv
直覺做法是補一個連結過去,結果換了另一個錯誤:
root@node2:/root# ln -s /usr/lib/insserv /sbin/insserv root@node2:/root# chkconfig drbd on /sbin/insserv: Permission denied
看權限明明就有執行位:
root@node2:/root# ls -l /sbin/insserv lrwxrwxrwx 1 root root 16 Jun 21 04:27 /sbin/insserv -> /usr/lib/insserv root@node2:/root# ls -l /usr/lib/insserv total 56 -rwxr-xr-x 1 root root 56368 Apr 9 19:07 insserv
折騰半天才恍然大悟:/usr/lib/insserv 其實是一個目錄,連結指到目錄上自然無法執行。
root@node2:~# cd /usr/lib/insserv/ root@node2:/usr/lib/insserv# pwd /usr/lib/insserv root@node2:/usr/lib/insserv# ls insserv
root@node2:/usr/lib/insserv# rm -rf /sbin/insserv root@node2:/usr/lib/insserv# ln -s /usr/lib/insserv/insserv /sbin/insserv root@node2:/usr/lib/insserv# chkconfig drbd on The script you are attempting to invoke has been converted to an Upstart job, but lsb-header is not supported for Upstart jobs. insserv: warning: script 'friendly-recovery' missing LSB tags and overrides insserv: Default-Start undefined, assuming empty start runlevel(s) for script `friendly-recovery' insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `friendly-recovery'
這時還會冒出一堆 LSB 標籤與 Upstart 相關的警告,那些屬於其他腳本本身沒有寫好標頭,跟 DRBD 無關,先放著即可。回頭驗證結果:
root@node2:/usr/lib/insserv# chkconfig --list | grep drbd drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
服務已經成功設為開機啟動。Ubuntu 這類小毛病還不少,長期使用 RedHat 系列的人第一次碰到確實容易一頭霧水,關鍵在於看清楚連結指向的是檔案還是目錄。