SystemD memcached 服务 —(代码=已退出,状态=1/失败)

SystemD memcached 服务 —(代码=已退出,状态=1/失败)

因此我必须在 Rocky Linux 8 memcached 中使用 /var/run/memcached 中的 SOCKET 进行部署

为了避免服务失败,我运行了以下命令:

  • systemctl edit memcached.service

粘贴于:

[Unit]
Description=Memcached
Before=httpd.service
After=network.target
[Service]
Type=simple
User=memcached
Group=memcached
# Run ExecStartPre with root-permissions
ExecStartPre=-/usr/bin/mkdir /var/run/memcached
ExecStartPre=-/usr/bin/chown -R memcached:memcached /var/run/memcached/
[Install]
WantedBy=multi-user.target

[root@cp monit.d]# service memcached status
Redirecting to /bin/systemctl status memcached.service
● memcached.service - Memcached
   Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/memcached.service.d
           └─override.conf
   Active: active (running) since Thu 2022-10-13 15:23:50 CEST; 3s ago
  Process: 1336192 ExecStartPre=/usr/bin/chown -R memcached:memcached /var/run/memcached/ (code=exited, status=0/SUCCESS)
  Process: 1336188 ExecStartPre=/usr/bin/mkdir /var/run/memcached (code=exited, status=1/FAILURE)
 Main PID: 1336194 (memcached)
    Tasks: 10 (limit: 101049)
   Memory: 3.6M
   CGroup: /system.slice/memcached.service
           └─1336194 /usr/bin/memcached -p 11211 -u memcached -m 256 -c 1024 -s /var/run/memcached/memcached.sock -a 0770

Oct 13 15:23:50 cp.uhlhosting.ch systemd[1]: Starting Memcached...
Oct 13 15:23:50 cp.uhlhosting.ch systemd[1]: Started Memcached.

有什么方法可以避免这种失败?

ExecStartPre=/usr/bin/mkdir /var/run/memcached (code=exited, status=1/FAILURE)

谢谢你!

答案1

你现在正在做的事情——/var/run/memcached通过创建ExecStartPre——是可以的,但处理这个问题的规范方法是通过systemd-tmpfiles服务。您可以/etc/tmpfiles.d/memcache.conf使用以下内容创建:

D /run/memcached 0700 memcached memcached

每次系统启动时,都会创建目录/run/memcached(通常/var/run只是 的符号链接/run)。这意味着您无需在服务单元中创建目录。

另请参阅tmpfiles.d手册页/etc/tmpfiles.d以及或 中的现有配置文件/usr/lib/tmpfiles.d

相关内容