If I run the following command, everything works as expected:
sudo mongod --fork --dbpath /path/to_data/ --port 27027 --syslog
However, if I put the following command in startmongo.sh and run it with sudo, I get an error:
mongod --fork --dbpath /path/to_data/ --port 27027 --syslog
Error:
[root@server Folder]# sudo ./startmongo.sh
about to fork child process, waiting until server is ready for connections.
forked process: 2394
ERROR: child process failed, exited with error number 100
To see additional information in this output, start without the "--fork" option.
If I look at the log file I see the following:
STORAGE [initandlisten] exception in initAndListn: Location28596: Unable to determine status of lock file in the data directory /path/to_data/: boost::filesystem::status: Permission denied: "/path/tod_data/mongod.lock", terminating
So how can I start Mongo from a script?