以前書いた記事[Ubuntu] Raspberry pi に Ramdiskを設定したら nginx とか MySQL が起動しなくなったので、rc-local で対処する。 をラズパイ4でも試してみたというだけの話。 今はMySQLはDockerコンテナで動かしているので、今回の対象は /var/log/nginx のみ。
試した環境
Raspberry Pi 4
Ubuntu 20.10 64bit
$ uname -a
Linux pi4 5.8.0-1017-raspi #20-Ubuntu SMP PREEMPT Mon Mar 1 14:19:20 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
対策
systemdに用意されている /etc/rc.local Compatibility を使う。
最初に/etc/rc.local を準備しておく。
$ sudo vi /etc/rc.local #!/bin/bash mkdir -p /var/log/nginx chown root.www-data /var/log/nginx exit 0 $ sudo chmod +x /etc/rc.local
systemd の rc.local Compatibility を有効にする。
/lib/systemd/system/rc-local.serviceの一番下に[Install]セクションを追記する。
$ sudo vi /lib/systemd/system/rc-local.service
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
kkitta@pi4:~$ cat /lib/systemd/system/rc-local.service
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
[Install]
WantedBy=multi-user.target
サービスを有効にする。
$ sudo systemctl enable rc-local Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.
参考:/lib/systemd/system/rc-local.service に [Install] セクションを書いておかないと、下記のエラーが出る。
$ sudo systemctl enable rc-local The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: • A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. • A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. • A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, …). • In case of template units, the unit is meant to be enabled with some instance name specified.
わし
いつも「あれ?Webサーバ落ちてる?」ってなってからこの状況に気づく。
コメント