我尝试为 docker 服务创建一个 systemd 脚本:
[Unit]
Description=ScyllaDB 1
After=network-online.target docker.target
Wants=network-online.target systemd-networkd-wait-online.service docker.target
[Service]
Type=notify
Restart=on-failure
RestartSec=10s
User=foo
Group=users
WorkingDirectory=/home/foo/scylladb
ExecStartPre=/usr/bin/docker pull scylladb/scylla
ExecStart=/usr/bin/docker run --volume /home/foo/scylla1:/var/lib/scylla --name scylla1 \
scylladb/scylla --developer-mode 1 --memory 1.5G --smp 3 \
--listen-address 127.0.0.1
# --overprovisioned 1 --seeds 127.0.0.1 --broadcast-address 127.0.1.1
ExecStop=/usr/bin/docker stop scylla1
LimitNOFILE=1048576
ProtectSystem=full
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
我已经执行完毕:
sudo usermod -aG docker foo
mkdir -p /home/foo/scylla1/commitlog /home/foo/scylla1/data
sudo chown foo:users /home/foo/scylla1
sudo systemctl daemon-reload
编辑:当我尝试使用用户手动运行命令时,foo
它工作正常,但在使用时sudo systemctl restart scylladb
显示错误:
May 17 14:58:55 x systemd[1]: Stopped ScyllaDB 1.
May 17 14:58:55 x systemd[1]: Starting ScyllaDB 1...
May 17 14:58:55 x systemd[1]: scylladb.service: Control process exited, code=exited status=210
May 17 14:58:55 x systemd[1]: Failed to start ScyllaDB 1.
May 17 14:58:55 x systemd[1]: scylladb.service: Unit entered failed state.
May 17 14:58:55 x systemd[1]: scylladb.service: Failed with result 'exit-code'.
手动:
[foo@x ~]$ /usr/bin/docker pull scylladb/scylla
Using default tag: latest
latest: Pulling from scylladb/scylla
93857f76ae30: Already exists
fcf3425de92f: Already exists
a9768670d266: Already exists
eaccce6402ed: Already exists
a564f24ba7ea: Already exists
c1c511852d0b: Already exists
f9c8010402b4: Already exists
654f38ed538a: Already exists
64856b4587d3: Already exists
74fbc1822a2d: Already exists
fdeb9fe209e1: Already exists
243856d4fcb5: Already exists
0b59d050d95e: Already exists
e677bcc6c3d3: Already exists
ca2f175eb91a: Already exists
912e754404b4: Already exists
c80ea560f85c: Already exists
9f2fa2f93fae: Already exists
04cfbbeb59e2: Already exists
a9996b00766d: Already exists
1076dbbc8e7b: Already exists
c4eda4b22480: Already exists
Digest: sha256:9c9d23b9ab9bd392cf647d861edc1f48498f6c7ffd142ab9905c23cc3c463345
Status: Image is up to date for scylladb/scylla:latest
[foo@x ~]$ /usr/bin/docker pull scylladb/scylla^C
[foo@x ~]$ /usr/bin/docker run --volume /home/foo/scylla1:/var/lib/scylla --name scylla1 \
> -d scylladb/scylla --developer-mode 1 --memory 1.5G --smp 3 \
> --listen-address 127.0.0.1
4c6e7685e5297028e582e7c19c75424dbf3160a0e46adb69325993d333dbae7e
[foo@x ~]$ /usr/bin/docker stop scylla1
scylla1
造成这种情况的可能原因是什么?
答案1
显然问题是因为工作目录不存在,它应该/home/foo/scylla1
不存在/home/foo/scylladb
,问题的第二部分是1.5G
参数无效,1G
或者2G
工作正常。
这是最终的 systemdscylladb.service
文件:
[Unit]
Description=ScyllaDB 1
After=network-online.target docker.target
Wants=network-online.target systemd-networkd-wait-online.service docker.target
[Service]
Type=simple
Restart=on-failure
RestartSec=10s
User=foo
Group=docker
WorkingDirectory=/home/foo/scylla1
ExecStartPre=/usr/bin/docker rm scylla1
ExecStart=/usr/bin/docker run --volume /home/foo/scylla1:/var/lib/scylla --name scylla1 scylladb/scylla --developer-mode 1 --memory 2G --smp 3 --listen-address 127.0.0.1
# --overprovisioned 1 --seeds 127.0.0.1 --broadcast-address 127.0.1.1
ExecStop=/usr/bin/docker stop scylla1
LimitNOFILE=1048576
ProtectSystem=full
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target