Need to launch mongod using launchctl - mongodb

I have installed MongoDB using manual option.
When I fire mongod it will take parameters from somewhere else specially for dbPath.
I want to have my own dbPath without specifying it with --dbPath each time.
So I found option to provide mongod.conf file and call mongod --config option but still I need to pass path of .conf file.
My ultimate goal is to just launch mongod as service and it will read config file from path I configured. For this I tried LaunchAgent and LaunchDaemon with no luck. What I thought is that if I can configure LaunchAgent or Daemon then I will provide path to mongod of bin directory of MongoDB folder and provide --config and path for .conf file as argument and then I need to just launch mongod using launchctl with name mongod and it will start mongod --config <.conf file path>.
But I am not able to do so. I read nearly 15-16 posts on LaunchAgent and Daemon but did not get solution my problem. I tried to do so with making mongod.plist file at various places like /Library/LaunchDaemon, /Library/LaunchAgent and ~/Library/LaunchDaemon but I always get error "Path had bad ownership/permissions". I tried chown and chgrp but no luck.
I hope you got my point. I really need complete solution to achieve my goal.

Do you use linux or windows?
This is the default location of mongodb.conf in linux:
/etc/mongodb.conf
You can simply edit it with your parameters, and start the service using:
sudo service mongodb restart
If you are using windows, it depends on the version of MongoDB you are using, but check in:
C:\Program Files\MongoDB\Server\3.4\...
For the same file.

Related

How to set mongo db path permanently

Is there a way to over-rite the mongodb default db path. Even after editing the storage path in mongod.conf to the custom directory path. Still it looks for /data/db, and not the custom path.
Since every time mongod path needs to be specified for the custom path.
mongod --dbpath /Users/customData
Is there a permanent way to deal this.
You can try to run it as a service, so that you don't need to run this command everytime you want to use it, and it runs it in the path you set it to
Here's how:
the link
from official mongodb website: the link
According to documentation of MongoDB
To run a mongod process as a daemon (i.e. fork), and write its output
to a log file, use the --fork and --logpath options. You must create
the log directory; however, mongod will create the log file if it does
not exist.
The following command starts mongod as a daemon and records log output
to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log

Fix mongod install via command line

After installing mongodb on windows, I set up the necessary folders but made a typing mistake when doing the following command:
mongod --directoryperdb --dbpath C:\mondodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install
the folder is named mongodb but i named it mondodb by accident and can't seem to overwrite that, so when I start mongodb by doing net start mongodb I get an error in my log saying C:\mondodb\data\db not found
I tried redoing it like so mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install but it's not working.
how can I redo the mongod thingy?
There are a few different things you could try:
Go into the registry and change the service path: Modifying the "Path to executable" of a windows service. After you modify it, you can go into Services.msc, right-click on the service, go to Properties, then Look at the Path to executable: and make sure that it points to mongodb rather than mondodb.
It involves editing the registry, but service information can be found in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services. Find the service you want to redirect, locate the ImagePath subkey and change that value.
Go into a command prompt (may need to Run as Administrator) and do sc delete mongod <or whatever the service is named> -- can check services.msc for that). Then re-run your command with the correct path.
Alternately, you might try to set it up by taking a config file so that you can just change those options via config file rather than having to modify the service or delete/reinstall the service when you want to change options. I believe the command there is C:\<mongopath>\mongod.exe -f <config file name> --install.

how do I edit the Mondodb.conf file

How do I edit the mongodb.conf file?
I want to change the bind_ip from 127.0.0.1 to 0.0.0.0.
I have tried sudo mongod --bind_ip 0.0.0.0
I have tried manually editing the file (in a text editor), but it won't let me save.
I have tried changing the permissions of the file, yet I still can not save.
I didn't create a mongodb.conf file either, so I'm not sure why it was automatically set up as 127.0.0.1
I'm using Ubuntu.
I've tried searching around but I haven't had any luck.
All suggestions will be much appreciated.
Both the /etc/mongod.conf and /var/log/mongodb/mongob.log files are write restricted to super users. Your standard login account is not allowed to directly modify them.
To edit the mongod.conf file , open a terminal and run the following command (sudo will ask you for your password):
gksudo gedit /etc/mongod.conf
Edit the file to add 0.0.0.0 (or just comment the line out ), save the mongodb.conf file.
In addition mongod is a service on ubuntu so you'll need to run following command in the terminal to restart it to read the new config:
sudo service mongod restart
You can read about sudo here
If you're on windows and are wondering how to edit the config file.
Open the file
Edit the cfg file however you want.
Save as and save it to another folder somewhere else
Copy/cut and past the file back into the bin folder and accept admin permission
Go to windows services and stop->start/restart the MongoDB server service.
Done
trying using your specified mongodb.conf to mongo deamon
use following command to start the mongod daemon
mongod -f <file-locattion>/mongodb.conf
and in your mongodb.conf file add following
bind_ip=<your-pref-ip>
<rest of setting -such as data-folder etc>
using aws ubuntu instance i ssh to my instance using putty navigate to the file directory and
i used the command
sudo pico mongodb.conf
the file opened and i edited my file then saved it
by following onscreen commands

Is it possible to install mongodb without root privilages?

How can I install mongodb on a Linux server without root privileges? is this possible? What would the steps be? Is there a way to configure mongo to not use /data/db?
You may download the binaries from MongoDB website.
There are a lot of options for the command mongod to change the default behavior, one of these is:
--dbpath arg directory for datafiles
Based on comments:
But it is preferable to specify all configurations in a configuration file and just invoke mongod with:
--config filename

How do I force save the dbpath parameter?

I'm just starting out with developing with Mongodb locally and following the tutorials.
I want to use 1 path for all my development.
In the Mongodb documentation it says:
Create a data directory
By default MongoDB will store data in
/data/db, but it won't automatically
create that directory. To create it,
do:
$ mkdir -p /data/db
You can also tell
MongoDB to use a different data
directory, with the --dbpath option.
I want to use one path for all my dbpaths so that I know where they all are and not get confused.
The path I want to use is:
sudo mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
The mongodb.conf file I have is set up as thus:
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /Applications/XAMPP/xamppfiles/var/mongodb
# Only accept local connections
bind_ip = 127.0.0.1
However, I have noticed that I have to keep typing this config path in every time I want to run Mongo.
How do I make it so that Mongodb save the dbpath, or the path to the config without me having to type it out every time?
Thanks.
You can create a startup script, like a bash/cshc script. You must specify those options when starting up.
Make a bash script that runs the commands you want.
Make a file called startMongo.sh
#! /bin/bash
mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
Run command
sudo startMongo.sh