19

I'm trying to write a systemd service file for redis.

Here's my file:

[Unit]
PartOf=smp-data-services.target
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/opt/eg/share/redis/bin/redis-server
ExecStop=/opt/eg/share/redis/bin/redis-cli
Restart=on-failure
User=eg
Group=eg

[Install]
WantedBy=multi-user.target

No matter what I do, I keep getting:

# systemctl daemon-reload

systemd: redis.service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.

I can start redis on the command line with no issue like this:

/opt/eg/share/redis/bin/redis-server

I've read that redis' daemonized forking process is non-standard, and I should avoid Type=forking or oneshot.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
rajat banerjee
  • 331
  • 1
  • 2
  • 7
  • I had a leftover file for `transmission-daemon` from an earlier configuration in `/etc/systemd/system/transmission-daemon.service.d/override.conf`. Removing the file allowed the service to start. – user598527 Aug 24 '23 at 12:27

3 Answers3

21

In the [service] section, you should clean the ExecStart command:

[Unit]
PartOf=smp-data-services.target
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=
ExecStart=/opt/eg/share/redis/bin/redis-server
ExecStop=/opt/eg/share/redis/bin/redis-cli
Restart=on-failure
User=eg
Group=eg

[Install]
WantedBy=multi-user.target
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Montells
  • 415
  • 4
  • 7
  • 5
    This works but is also so counter-intuitive! – Neurotransmitter May 11 '20 at 10:34
  • 3
    "Cleaning" `ExecStart` must be done even for drop-in files, I just hit it. The solution above work. – Jiri B Mar 17 '21 at 15:51
  • 1
    Why this works? First, multiple `ExecStart=`s can exist. This begs the question as to where this was previously set, as it wasn't in this unit file, but possibly set by default somehow. Next from the docs "If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect." – Elliptical view Mar 27 '22 at 07:51
4

Thanks to rrauenza, he is right. I have a .conf file in /etc/systemd/system/redis.service.d/redis_systemd.conf . Once I removed that, it's almost working!

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
rajat banerjee
  • 331
  • 1
  • 2
  • 7
4

run systemctl edit redis
if Service part has startwith ExecStart= line, remove it.

The ExecStart= line cannot be modified with systemctl edit

eleksbai
  • 41
  • 1
  • Your solution is to use 'systemctl edit' because it doesn't work. – user189395 Apr 16 '23 at 22:16
  • I understood that the `systemctl edit redis` mentioned is to _make sure no `ExecStart=` line is there_ — i.e. check if it is, and if so, remove it. _Then_ proceed to change the main configuration instead. – Gwyneth Llewelyn Jun 16 '23 at 17:36