When my CentOS 7 system boots, elasticsearch fails to start with the message
Failed at step RUNTIME_DIRECTORY spawning /usr/share/elasticsearch/bin/elasticsearch: File exists
Once the system is up, it starts fine with 'systemctl start elasticsearch'.
After much investigation, I think I found the problem
- /usr/lib/tmpfiles.d/elasticsearch.conf creates the directory /var/run/elasticsearch
- /usr/lib/systemd/system/elasticsearch.service has a RuntimeDirectory saying that it wants the directory /run/elasticsearch
Since /var/run is a symbolic link to /run, both try to create the /run/elasticsearch directory. The tmpfiles.d happens first, and the systemd startup of elasticsearch fails because the directory already exists.
If you now run 'systemctl start elasticsearch', it works fine because systemd removed the /run/elasticsearch directory when elasticsearch failed to start previously.
After removing /usr/lib/tmpfiles.d/elasticsearch.conf, elasticsearch starts up correctly on boot.