【Ubuntu】/etc/rc.localの有効化
備忘ネタ。昔のLinuxでは/etc/rc.localに起動時に実行したいコマンドを記載し実行権限を与えておくだけでよかったが、最近のUbuntuではSystemdを使用するようになり、/etc/rc.localはデフォルトで使用されなくなった。このため、有効化するための方法をメモ。
1. /etc/rc.local ファイルを作成し、実行可能化
起動時に実行したいコマンドを記載し、rootでの実行権限を与える。
$ sudo chmod +x /etc/rc.local
2. /etc/systemd/system/rc-local.service ファイルを作成し、以下の内容を記述
[Unit]
Description=/etc/rc.local Compatibility
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3. rc-local.service を有効化
$ sudo systemctl enable rc-local.service
4. システムを再起動
$ sudo reboot