カテゴリー【Debian】
Debian 10 Busterに/etc/rc.localを導入する
POSTED BY
2020-10-26
2020-10-26

マシン起動時に実行したいスクリプト/etc/rc.localはBusterではデフォルト無効になっている。
/lib/systemd/systel/rc-local.service
があるはずで、無ければ同ファイルを作成する。以下のようになっているはずである。
source | rc-local.service | GitHub Source |
# SPDX-License-Identifier: LGPL-2.1+ # # 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 2.1 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 Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no
実行ファイル/etc/rc.localの作成
rc.local自体は無いのでイチから作成する。実行したいスクリプトを書く。
/etc/rc.local
source | rc.local | GitHub Source |
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. su -l hogeuser -c whoami su -l hogeuser -c "echo Hello World rc.local" exit 0
su -lコマンドで任意の一般ユーザに成り代わり、-cコマンドでそれに続くコマンドを実行する。
上記例ではhogeuserとしてwhoami, echo Hello Worldと出力させている。
複数コマンドを一度に実行させたい場合は-cの先のコマンドをシェルスクリプトファイル等にする。
例)su -l hogeuser -c "/home/hogeuser/startup.sh"
など。
サービスとして登録する前に、まず単体で実行確認を行う。実行属性を必ずつけること。
chmod a+x /etc/rc.local sh -x /etc/rc.local + su -l hogeuser -c whoami hogeuser + su -l hogeuser -c echo Hello World rc.local Hello World rc.local + exit 0
問題なさそうであるので、サービス登録・自動起動設定を行う。
systemctl status rc-local systemctl start rc-local systemctl stop rc-local systemctl enable rc-local
マシンを再起動してみて、/var/log/syslogを確認してみる。
Oct 26 10:50:31 test-server systemd[1]: Starting /etc/rc.local Compatibility... Oct 26 10:50:31 test-server rc.local[640]: hogeuser Oct 26 10:50:31 test-server rc.local[640]: Hello World rc.local Oct 26 10:50:31 test-server systemd[1]: Started /etc/rc.local Compatibility.
ちゃんとrc.localスクリプトが起動していることが確認できた。
Android
iPhone/iPad
MacOS
Windows
Debian
FreeBSD
RaspberryPI
C/C++
PHP
Java
JavaScript
Node.js
Swift
Python
Amazon/AWS
Google
LINE
IBM Watson
Microsoft Azure
Xcode
VMware
MySQL
PostgreSQL
Redis
Groonga
Git/GitHub
Apache
nginx
Postfix
SendGrid
Hackintosh
Hardware
Fate/Grand Order
※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
※本記事内容の無断転載を禁じます。
【キーワード検索】
【最近の記事】【全部の記事】
GitLabの2段階認証ログインが端末初期化等で不可能になった場合の対処法【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【16】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【15】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【14】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【13】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【12】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【11】
【FGO】Fate/Grand Orderを今から始めて無料でどこまで行けるか【10】
レンタルサーバーCORESERVERでCRONを定期実行する
レンタルサーバーCORESERVERのPythonでGoogle Analytics Reporting APIを使う
【人気の記事】【全部の記事】
進研ゼミチャレンジタッチをAndroid端末化する【Hackintosh】組立PCにWindowsとmacOSを同居させる場合の注意点
【Javascript】JSON配列内にある特定要素の取得法【Node.js】
【Raspberry Piメモ・4】オンボード無線LANでRaspberry Piをアクセスポイントにする
【ひかり電話+VoIPアダプタ】LANしか通ってない環境でアナログ電話とFAXを使う
【Swift UI】マイク使用許可を得て音声をテキストに変換する(音声認識)
PHPでメールの中身をフルに分解して出力する(日本語&添付ファイル対応)
【Raspberry Piメモ・3】オンボード無線LANでWi-fi Direct対応機器に接続する
LinuxからWindowsの共有フォルダをマウントする
【Xcode】ビルドから実機でCould not launch等エラーでアプリが起動できない場合の対処