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?
So when you using fork without using sudo effective uid don't have permission.
Edit: So I mean, if you don't want to daemonize process you should use nohup with
&
and mange everything within script. With your logsdata directory /path/to_data/: boost::filesystem::status: Permission denied
mean newly spawned process don't have permission to access files or data. Here--fork
is doing something interesting so it doesn't work as you mentioned above.You can try two options:
nohup mongod --fork --dbpath /path/to_data/ --port 27027 --syslog &
Hope this will help.