我正在使用以下 systemd 单元/dev/vdb1
进行安装:/media/esdata
该单位位于/etc/systemd/system/media-esdata.mount
:
[Unit]
Description=Mount cinder volume
Before=docker.service
[Mount]
What=/dev/vdb1
Where=/media/esdata
Options=defaults,noatime,noexec
但这不会在重启时启动。我似乎也无法启用这个单元:
$ sudo systemctl enable media-esdata.mount
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
我该怎么做才能随时/media/esdata
有空?
答案1
您可以在media-esdata.mount中添加[Install]字段,systemctl enable
将为您创建链接:
[Unit]
Description=Mount cinder volume
Before=docker.service
[Mount]
What=/dev/vdb1
Where=/media/esdata
Options=defaults,noatime,noexec
[Install]
WantedBy=docker.service
启用安装单元时,您应该看到以下消息:
$ sudo systemctl enable media-esdata.mount
Created symlink /etc/systemd/system/docer.service.wants/media-esdata.mount → /etc/systemd/system/media-esdata.mount.
答案2
您需要“启用”此设备,这意味着它会在启动时启动。您可以通过 cloud-config 或手动执行此操作sudo systemctl enable media-esdata.mount
答案3
我的解决方法是systemctl enable docker.service
创建一个/etc/systemd/system/docker.service.wants
并将符号链接media-esdata.mount
到该文件夹。Systemd 愿意docker.service
在启动时启动,并使用该文件夹强制安装驱动器。
现在我已经运行了docker,而不需要通过SSH进入盒子并运行docker
(默认情况下,只有在docker.socket
触发依赖项时才启动)。另外,我在任何容器可以访问文件系统之前安装了驱动器。虽然不完全直接,但它工作可靠,而且似乎并没有偏离常规。