ubuntu從16.04開始不再使用initd管理系統,改用systemd。
然而systemd對于使用者的要求很高,需要記憶很多指令不說,每個指令的單詞長度也是不能忍的。
然而,沒辦法,誰叫他的圖形界面确實支援的軟體多呢,吐完後還是接着幹活吧。
為了像以前一樣,在/etc/rc.local中設定開機啟動程式,需要以下幾步:
1、使用現有的啟動項
systemd預設讀取/etc/systemd/system下的配置檔案。
該目錄下的檔案會連結/lib/systemd/system/下的檔案。
一般系統安裝完/lib/systemd/system/下會有rc-local.service檔案,即我們需要的配置檔案。
連結過來:
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
cd /etc/systemd/system/
vim rc-local.service
rc-local.service内容:
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
2、建立/etc/rc.local檔案
3、賦可執行權限
4、編輯rc.local,添加需要開機啟動的任務
#!/bin/bash
/home/chin/startup.sh
執行reboot重新開機系統驗證OK。
最後,說一下/etc/systemd/system/下的配置檔案(XXXX.service),
其中有三個配置項,[Unit] / [Service] / [Install]
1) [Unit] 區塊:啟動順序與依賴關系。
2) [Service] 區塊:啟動行為,如何啟動,啟動類型。
3) [Install] 區塊,定義如何安裝這個配置檔案,即怎樣做到開機啟動。