Description of problem: [root@localhost ~]# systemctl start redis.service ; echo $? 0 [root@localhost ~]# systemctl status redis.service -n 50 redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled) Active: failed (Result: exit-code) since Wed 2014-12-10 21:28:37 UTC; 7s ago Process: 32584 ExecStop=/usr/bin/redis-shutdown (code=exited, status=1/FAILURE) Process: 32583 ExecStart=/usr/bin/redis-server /etc/redis.conf --daemonize no (code=exited, status=1/FAILURE) Main PID: 32583 (code=exited, status=1/FAILURE) Dec 10 21:28:37 localhost.localdomain systemd[1]: Starting Redis persistent key-value database... Dec 10 21:28:37 localhost.localdomain systemd[1]: Started Redis persistent key-value database. Dec 10 21:28:37 localhost.localdomain redis-server[32583]: [32583] 10 Dec 21:28:37.775 # Fatal error, can't open config file '/etc/redis.conf' Dec 10 21:28:37 localhost.localdomain systemd[1]: redis.service: main process exited, code=exited, status=1/FAILURE Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + REDIS_CLI=/usr/bin/redis-cli Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + SERVICE_NAME= Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + '[' -z '' ']' Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + SERVICE_NAME=redis Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + CONFIG_FILE=/etc/redis.conf Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: ++ awk '/^[[:blank:]]*port/ { print $2 }' /etc/redis.conf Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: awk: fatal: cannot open file `/etc/redis.conf' for reading (Permission denied) Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + PORT= Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + '[' redis = redis ']' Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + PORT=6279 Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: + /usr/bin/redis-cli -p 6279 shutdown Dec 10 21:28:37 localhost.localdomain redis-shutdown[32584]: Could not connect to Redis at 127.0.0.1:6279: Connection refused Dec 10 21:28:37 localhost.localdomain systemd[1]: redis.service: control process exited, code=exited status=1 Dec 10 21:28:37 localhost.localdomain systemd[1]: Unit redis.service entered failed state. If the service fails to start in this manner, the 'start' command should return an error. Version-Release number of selected component (if applicable): redis-2.8.14-2.el7.x86_64 How reproducible: 100% Steps to Reproduce: 1. chown root.root /etc/redis.conf 2. chmod 640 /etc/redis.conf 3. systemctl start redis.service Actual results: returns 0, service fails. Expected results: returns 1, service fails.
Thanks for the report, Bill. Assigning to @hguemar
ack.
I've looked into this one, understand the root cause now and have a fix. The underlying problem is that systemd starts the service successfully (this is a Type=Simple service - the default - not Type=forking, or another service type). So, systemd starts the process and as far as *it* can tell, it does so successfully even though the process fails very soon after starting (its not an immediate failure from systemd's POV). This phenomena is described here: https://serverfault.com/questions/751030/systemd-ignores-return-code-while-starting-service There is also a possible solution recommended there - to use Type=forking and a script (or helper program) that can verify more carefully that the daemon started and ensure the return code is more meaningful. Not described there however, is another solution which I think suits better here, and that is the use of a Type=notify service, since current Redis supports this natively. This is enabled by changing service type to "notify" in the service file, and changing the line "supervised no" to "supervised systemd" in the Redis configuration file). Here's how Bill's failure scenario (unavailable redis.conf) pans out now ... # mv /etc/redis.conf /etc/redis.conf.saved # systemctl start redis Job for redis.service failed because the control process exited with error code. See "systemctl status redis.service" and "journalctl -xe" for details. # echo $? 1 # mv /etc/redis.conf.saved /etc/redis.conf # systemctl start redis # echo $? 0 # I'll continue testing, but assuming all goes well I'll include this change in the next Redis build.
> This is enabled by changing service type to "notify" in the service file, > and changing the line "supervised no" to "supervised systemd" in the Redis configuration file). Please don't rely on configuration file (this will be broken on update, config files are not updated) Instead, use option in unit file Type=Notify ExecStart=/usr/bin/redis-server /etc/redis.conf --daemonize no --supervised systemd From a quick test, seems to work as expected.
Ah yes - thanks Remi - I'll make that change before I push it. cheers.
Addition notice: supervised implies daemonize=no, so perhaps this option could be dropped in src/server.c (checked in 4.0.1) int background = server.daemonize && !server.supervised; if (background) darmonize();
Same code is there in the 3.x series - thanks Remi, I'll make this change as well.
redis-3.2.11-1.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2017-6d0c7eb24e
redis-3.2.11-1.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-a2c6d143e8
redis-3.2.11-1.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-2735f42785
redis-3.2.11-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-165ee8a3f6
redis-3.2.11-1.fc27 has been pushed to the Fedora 27 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-6d0c7eb24e
redis-3.2.11-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-2735f42785
redis-3.2.11-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-165ee8a3f6
redis-3.2.11-1.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-a2c6d143e8
redis-3.2.11-1.fc27 has been pushed to the Fedora 27 stable repository. If problems still persist, please make note of it in this bug report.
redis-3.2.11-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.
redis-4.0.2-2.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-343c274808
redis-4.0.2-2.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-343c274808
redis-4.0.2-2.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.
redis-3.2.12-1.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2018-8de40d24ca
redis-3.2.12-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2018-8de40d24ca
redis-3.2.12-1.el7 has been pushed to the Fedora EPEL 7 stable repository. If problems still persist, please make note of it in this bug report.