Skip to main content
Topic: How should I write a service for Valkey? (Read 93 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

How should I write a service for Valkey?

I am trying to write a dinit service for paperless, and realized that valkey service is also necessary.


The Arch Valkey package seems to include the following systemd service

Code: [Select]
[Unit]
Description=Advanced key-value store
After=network.target

[Service]
Type=notify
User=valkey
Group=valkey
ExecStart=/usr/bin/valkey-server /etc/valkey/valkey.conf --supervised systemd
TimeoutStartSec=60
TimeoutStopSec=60
CapabilityBoundingSet=
PrivateTmp=true
PrivateDevices=true
ProtectSystem=full
ProtectHome=true
NoNewPrivileges=true
RuntimeDirectory=valkey
RuntimeDirectoryMode=755
LimitNOFILE=10032

[Install]
WantedBy=multi-user.target
Alias=redis.service

I tried to convert this to a dinit service.

Code: [Select]
run-as = valkey
socket-uid = valkey
socket-gid = valkey
type = process
command = /usr/bin/valkey-server /etc/valkey/valkey.conf
logfile = /var/log/dinit/valkey.log
working-dir = /run/valkey
start-timeout = 60
stop-timeout = 60
depends-on = network.target
after = network.target

The issue is that I am not sure if I am replicating all the options specified in the original systemd script. I get a warning message saying that memory overcommit must be enabled. Could anyone help me determine if I did this incorrectly?

Code: [Select]
5841:M 06 Sep 2025 17:11:37.138 # WARNING Memory overcommit must be enabled! Without it, a background save
or replication may fail under low memory condition. Being disabled, it can also cause failures without low
memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommi
t_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for th
is to take effect.
5841:M 06 Sep 2025 17:11:37.138 * oO0OoO0OoO0Oo Valkey is starting oO0OoO0OoO0Oo
5841:M 06 Sep 2025 17:11:37.138 * Valkey version=8.1.3, bits=64, commit=d063dff5, modified=1, pid=5841, jus
t started
5841:M 06 Sep 2025 17:11:37.138 * Configuration loaded
5841:M 06 Sep 2025 17:11:37.138 # You requested maxclients of 10000 requiring at least 10032 max file descr
iptors.
5841:M 06 Sep 2025 17:11:37.138 # Server can't set maximum open files to 10032 because of OS error: Operati
on not permitted.
5841:M 06 Sep 2025 17:11:37.138 # Current maximum open files is 4096. maxclients has been reduced to 4064 t
o compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
5841:M 06 Sep 2025 17:11:37.138 * monotonic clock: POSIX clock_gettime
5841:M 06 Sep 2025 17:11:37.139 * Running mode=standalone, port=6379.
5841:M 06 Sep 2025 17:11:37.139 * Server initialized
5841:M 06 Sep 2025 17:11:37.139 * Loading RDB produced by Valkey version 8.1.3
5841:M 06 Sep 2025 17:11:37.139 * RDB age 16 seconds
5841:M 06 Sep 2025 17:11:37.139 * RDB memory usage when created 0.58 Mb
5841:M 06 Sep 2025 17:11:37.139 * Done loading RDB, keys loaded: 0, keys expired: 0.
5841:M 06 Sep 2025 17:11:37.139 * DB loaded from disk: 0.000 seconds
5841:M 06 Sep 2025 17:11:37.139 * Ready to accept connections tcp

 

Re: How should I write a service for Valkey?

Reply #1
Your dinit service definition is mostly fine.
  • To avoid the warning about "Your requested maxclients...", add a rlimit-nofile directive to the dinit service (equivalent to systemd's LimitNOFILE). Read man 5 dinit-service for more details.
  • working-dir is not needed, systemd's RuntimeDirectory is actually translated by either relying on the service creating /run/valkey itself, or by creating a valkey-pre scripted service that calls mkdir.

Other than that, you've translated every option in the systemd service file with a direct equivalent whenever possible.

The CapabilityBoundingSet and PrivateWhatever/ProtectWhatever options could be translated with some effort by wrapping Valkey in a script that uses a sandboxing suite, but that's not really necessary, plus dedicated UIDs (run-as directives) provide a really good deal of isolation already.

The warning about memory overcommit, as the message explains, is avoided by running sysctl and making it permanent by adding that line to /etc/sysctl.conf. That's done outside the init system.



Some nitpicks:
  • Unlike systemd Requires + After, depends-ms and after don't need to be used together. Just pick one (AFAIK, most stock Artix services choose after)
  • Since you're not using a socket-listen directive, socket-uid and socket-gid aren't doing anything. And unless Valkey is one of the very few programs that support systemd-style socket activation without systemd, socket-listen won't do anything useful either.