Cubie Truck 測試 – Arch Linux 開機執行的檔案

在 Fedora / CentOS Linux 可以在 /etc/rc.d/rc.local,在 Debian / Ubuntu Linux 可以在 /etc/rc.local 中設定開機要執行的一些功能,如:防火牆的設定之類的功能,不過在 Arch Linux 中似乎沒有這一個檔案的存在,但可以用替代的方式,達到這種功能。
參考網頁:
ArchLinux Systemd 增加rc-local自运行 – 羽毛の家
arch linux – systemd does not run /etc/rc.local? – Super User
Install Arch Linux on Cubietruck (Cubieboard 3) | Tom’s blog

方法一:
# vim /usr/lib/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target[@more@]開機時啟動 rc.local 此項功能
# systemctl enable rc-local.service
ln -s ‘/usr/lib/systemd/system/rc-local.service’ ‘/etc/systemd/system/multi-user.target.wants/rc-local.service’

建立 /etc/rc.local
關閉 Cubie Truck 上的 LED 燈號
# vim /etc/rc.local
#!/bin/sh
echo 0 > /sys/class/leds/blue:ph21:led1/brightness
echo 0 > /sys/class/leds/orange:ph20:led2/brightness
echo 0 > /sys/class/leds/white:ph11:led3/brightness
echo 0 > /sys/class/leds/green:ph07:led4/brightness

更改檔案執行權限
# chmod +x /etc/rc.local

方法二:
# vim /usr/bin/cubietruck_leds_off.sh
#!/bin/sh
echo 0 > /sys/class/leds/blue:ph21:led1/brightness
echo 0 > /sys/class/leds/orange:ph20:led2/brightness
echo 0 > /sys/class/leds/white:ph11:led3/brightness
echo 0 > /sys/class/leds/green:ph07:led4/brightness

更改檔案執行權限
# chmod +x /usr/bin/cubietruck_leds_off.sh

# vim /etc/systemd/system/cubietruck_leds_off.service
[Unit]
Description=Disable the LEDs of Cubietruck
[Service]
ExecStart=/usr/bin/cubietruck_leds_off.sh
[Install]
WantedBy=multi-user.target

啟動 cubietruck_leds_off 功能
# systemctl start cubietruck_leds_off

設定開機時啟動
# systemctl enable cubietruck_leds_off
ln -s ‘/etc/systemd/system/cubietruck_leds_off.service’ ‘/etc/systemd/system/multi-user.target.wants/cubietruck_leds_off.service’