Question

What's the purpose of these directives inside redis unit file? Are they needed?

Posted September 28, 2018 2k views
UbuntuRedisUbuntu 16.04

I am asking because in this redis tutorial link the author does not mention these.

[install]
ExecStartPre=-/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d
ExecStartPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-up.d
ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d

PrivateTmp=yes
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/var/run/redis
CapabilityBoundingSet=~CAP_SYS_PTRACE

# redis-server writes its own config file when in cluster mode so we allow
# writing there (NB. ProtectSystem=true over ProtectSystem=full)
ProtectSystem=true
ReadWriteDirectories=-/etc/redis

Also:
In unit description, can we write whatever word we want or must be some directive.

[Unit]
Description=Advanced key-value store

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Your systemd service seems more comprehensive compared to the one you’ve linked. It’s a good thing. Generally, the more elaborate your service file the more stable the service is going to be. Not always but generally speaking.

So to answer your question, they’re not absolutely necessary but you’re better off with them than without. You’re also free to describe your Unit however you want. It’s free form and isn’t a directive.

  • unixynet, thanks for the answer.

    I wanted you to ask also about:
    In my systemd file I have 3 ExecStop commands

    ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d
    ExecStop=/bin/kill -s TERM $MAINPID
    ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d
    

    But, in the tutorial that I have linked there is 1 ExecStop command and it is not the same. ExecStop=/usr/local/bin/redis-cli shutdown

    Do those 3 ExecStop commands interfere and cause some problem in the future or not, or should I replace with the new one. Or just simply add a fourth commands that it is suggested in the tutorial?

Yes, they are not necessary.

Submit an Answer