In a Linux machine, I changed the mongod.service
file to run a config file I created.
ExecStart=/usr/bin/mongod --config /etc/some_name.conf
When I start mongod with this config file manually, it runs fine. Yet when I use this config file to run the mongod daemon, it fails.
I did run systemctl daemon-reload
after the change, yet still failed.
Anybody also dealt with this issue?
Update
I've isolated the error in my log file to this line:
I STORAGE [initandlisten] exception in initAndListen: IllegalOperation:
Attempted to create a lock file on a read-only directory: /data/db, terminating
I CONTROL [initandlisten] now exiting
I've tried changing the ownership of the directory /data and /data/db to mongodb:mongodb but doesn't fix this error. Also changed the permissions to the directories with sudo chmod -R 775 /data
but still same error when I run:
sudo service mongod restart
sudo service mongod status
Status is still failed and same error in log file.
Best Answer
So, you created mongod.service file, did you remember tell to systemd that you are forking that pid to background? If not, systemd will kill that process soon after start.
Then there is that what @stennie wrote, if you start even once mongod as root user, some of the files are created as root:root and after that, nobody else (like user mongod) can not start mongod-process. So, what are those files and directories, which ownership must be set to mongod (or what ever user you use to start mongod-process)
Log file is important, because after mongod-process can write to it, it will tell what went wrong if something went wrong...