Score:0

SystemD memcached service - (code=exited, status=1/FAILURE)

vn flag

So I had to deploy in Rocky Linux 8 memcached with SOCKET in /var/run/memcached

In order to avoid the service to fail, I have run the following:

  • systemctl edit memcached.service

Pasted in:

[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.

What would be a way to avoid this FAILURE?

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

Thank you!

Score:1
pt flag

What you're doing right now -- creating /var/run/memcached via ExecStartPre -- is fine, but the canonical way of handling this is via the systemd-tmpfiles service. You create /etc/tmpfiles.d/memcache.conf with the content:

D /run/memcached 0700 memcached memcached

This will create the directory /run/memcached (typically, /var/run is just a symlink to /run) whenever the system boots. This means you don't need to handle creating the directory in your service unit.

See also the tmpfiles.d man page and existing configuration files in either /etc/tmpfiles.d or in /usr/lib/tmpfiles.d.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.