What's a clean way to stop mongod on Mac OS X? - macos

i'm running mongo 1.8.2 and trying to see how to cleanly shut it down on Mac.
on our ubuntu servers i can shutdown mongo cleanly from the mongo shell with:
> use admin
> db.shutdownServer()
but on my Mac, it does not kill the mongod process. the output shows that it 'should be' shutdown but when i ps -ef | grep mongo it shows me an active process. also, i can still open a mongo shell and query my dbs like it was never shutdown.
the output from my db.shutdownServer() locally is:
MongoDB shell version: 1.8.2
connecting to: test
> use admin
switched to db admin
> db.shutdownServer()
Tue Dec 13 11:44:21 DBClientCursor::init call() failed
Tue Dec 13 11:44:21 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 13 11:44:21 trying reconnect to 127.0.0.1
Tue Dec 13 11:44:21 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1
Tue Dec 13 11:44:21 Error: error doing query: unknown shell/collection.js:150
i know i can just kill the process but i'd like to do it more cleanly.

It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:
launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
Then start mongod manually:
mongod -f path/to/mongod.conf --fork
You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist.
After that, db.shutdownServer() would work just fine.
Added Feb 22 2014:
If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:
brew services list
To start mongodb:
brew services start mongodb-community
To stop mongodb if it's already running:
brew services stop mongodb-community
Update*
As edufinn pointed out in the comment, brew services is now available as user-defined command and can be installed with following command: brew tap gapple/services.

If you installed mongodb with homebrew, there's an easier way:
List mongo job with launchctl:
launchctl list | grep mongo
Stop mongo job:
launchctl stop <job label>
(For me this is launchctl stop homebrew.mxcl.mongodb)
Start mongo job:
launchctl start <job label>

Simple way is to get the process id of mongodb and kill it.
Please note DO NOT USE kill -9 pid for this as it may cause damage to the database.
so,
1. get the pid of mongodb
$ pgrep mongo
you will get pid of mongo, Now
$ kill
You may use kill -15 as well

If you have installed mongodb community server via homebrew, then you can do:
brew services list
This will list the current services as below:
Name Status User Plist
mongodb-community started <your_user_name> /Users/<your_user_name>/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
redis stopped
Then you can restart mongodb by first stopping and restart:
brew services stop mongodb
brew services start mongodb

I prefer to stop the MongoDB server using the port command itself.
sudo port unload mongodb
And to start it again.
sudo port load mongodb

Check out these docs:
http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal
If you started it in a terminal you should be ok with a ctrl + 'c' -- this will do a clean shutdown.
However, if you are using launchctl there are specific instructions for that which will vary depending on how it was installed.
If you are using Homebrew it would be launchctl stop homebrew.mxcl.mongodb

The solutions provided by others used to work for me but is not working for me anymore, which is as below.
brew services stop mongodb
brew services start mongodb
brew services list gives
Name Status User Plist
mongodb-community started XXXXXXXXX /Users/XXXXXXXXX/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
So I used mongodb-community instead of mongodb which worked for me
brew services stop mongodb-community
brew services start mongodb-community

This is an old question, but its one I found while searching as well.
If you installed with brew then the solution would actually be the this:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

If the service is running via brew, you can stop it using the following command:
brew services stop mongodb

Related

Change Port using Jenkins-lts Homebrew

I was wondering how one could change Jenkins-lts default port 8080 on Mac using Homebrew Installation. Actually I have 2 folders one on :
/Users/XXXXXX/.jenkins/ In here after execute all the process still runing on Port:8080
/usr/local/Cellar/jenkins/ In here when I executed the process jenkins running on Port:8383 but any jobs work.
I took the example for other Stack Member Ifeego answered Aug 21 '18 at 8:55, This is what I did:
I have installed Jenkins LTS by brew command:
brew install jenkins-lts
So my Jenkins plist file is here:
/usr/local/Cellar/jenkins-lts/2.121.2/homebrew.mxcl.jenkins-lts.plist
You can modify the httpPort value from default 8080 to the other value,and then save the file.
Label
homebrew.mxcl.jenkins-lts
ProgramArguments
/usr/libexec/java_home
-v
1.8
--exec
java
-Dmail.smtp.starttls.enable=true
-jar
/usr/local/opt/jenkins-lts/libexec/jenkins.war
--httpListenAddress=127.0.0.1
--httpPort=8383
RunAtLoad
sudo launchctl unload command will not work for you. You must try these commands to restart your Jenkins and make the port modification works.
After executed the change on jenkins-lts.plist file:
brew services stop jenkins-lts
brew services start jenkins-lts
ifeegoo:~ ifeegoo$ brew services stop jenkins-lts
Stopping `jenkins-lts`... (might take a while)
==> Successfully stopped `jenkins-lts` (label: homebrew.mxcl.jenkins-lts)
ifeegoo:~ ifeegoo$ brew services start jenkins-lts
==> Successfully started `jenkins-lts` (label: homebrew.mxcl.jenkins-lts)
Note:When I open the terminal and run brew services start jenkins-lts jenkins go up using the new Port:8383 in these case they do not run any job, but when I run on the terminal the command: jenkins-lts the application up in the Port:8080 and here I can run all the Jobs without troubles.

Why doesn't homebrew apache start at startup?

I’m trying to figure out why my apache doesn’t start at startup… (I would like for it to).
My OS: OSX Mojave
Impressions I’m under: that I’m running homebrew’s apache
Upon a fresh boot…
If I hit http://localhost in a browser I get
Unable to connect
Firefox can’t establish a connection to the server at localhost.
Fire up terminal…
$brew services list
returns
httpd started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.httpd.plist
php started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.php.plist
(That first line makes me think httpd is running and I should be able to hit localhost).
$which -a apachectl
returns
/usr/local/bin/apachectl
/usr/sbin/apachectl
then
$apachectl configtest
returns
Syntax OK
then
$sudo apachectl -V
returns (among other things)
-D SERVER_CONFIG_FILE="/usr/local/etc/httpd/httpd.conf"
(Isn’t this brew’s httpd.conf?)
There's a brew command (which I forget) that I already ran that is supposed to run httpd at startup.
Once I run
$sudo apachectl start
everything is jake. So it’s a low-priority question, but one I would like to solve and understand.
I had the same issue with Homebrew NGINX.
Running the brew services command with sudo solved the problem for me.
It appears that the Homebrew web-server packages require sudo to start | stop | restart.
Try running:
sudo brew services start apache2

How to shut down rethinkdb running on Mac OSX

Note: We love RethinkDB but our current project does not use it so we need to free up resources on our local machine ...
We installed RethinkDB using homebrew:
brew update && brew install rethinkdb
And added the rethinkdb process to our plist as per the instructions in:
http://rethinkdb.com/docs/start-on-startup/
But now we need to shut it down to free-up the 8080 port for another service.
What command do we need to run? (thanks!)
Do this in the terminal
check to see if you started it using brew
$ brew services list
stop rethinkdb:
$ brew services stop rethinkdb
restart:
$ brew services start rethinkdb
Like this, I think, if you used launchctl:
sudo launchctl unload -w /Library/LaunchDaemons/com.rethinkdb.server.plist

Can I just kill mongod to stop mongo?

I am very new at Mongo. I am running mongod as described here in Mac OS X. I am running two mongod processes from the command line. If I need to stop the mongod processes I just execute kill <pid of mongod>. Is it the recommended way to stop mongod?
It finally succeeded (Ubuntu 15.04) with
//1.find process by name:
$ pgrep mongo
1350
//2.kill mongod-process
$ kill 1350
This is quite late, but I had same problem now, and I found one easy way :
Esan-iMac:~$mongo admin --eval "db.shutdownServer()"
MongoDB shell version: 2.6.4
connecting to: admin
2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failed
server should be down...
It's giving some odd messages, but it works.
And I made alias-command for running it easy.
alias stop-mongo='/opt/mongo/release/bin/mongo admin --eval "db.shutdownServer()"'
This works at least if you start your mongo manually (e.g. with --fork option).
The accepted answer by Esa is correct. Also, regarding whether using kill is recommended - yes, but with flag -2 or no flag, never use -9. As mentioned in docs.
kill -2 `pgrep mongo`
Alias
alias stopmongo='kill -2 `pgrep mongo`'
Windows
use admin
db.shutdownServer()
For systems with auth enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
Linux
mongod --shutdown
you can also use
kill <mongod process ID>
see http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
For year of 2020:
Mongo should be installed through Brew, rather than the old school style on linux: i.e. tar.gz package download/uncompress/configure/run.
In the brew way, if Mongo is installed by brew tap mongodb/brew and brew install mongodb-community, you could do as follows to stop (and disable) it alike Systemd on Linux.
~ brew services list
Name Status User Plist
mongodb-community started zhengxin /Users/zhengxin/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
~ brew services stop mongodb-community
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)
terminal$ kill $(pgrep mongod)
this command can help killing the mongod process. sudo pkill -f mongod
Just encountered an issue with "just killing the mongod" in mac...
The mongod is kept running as a service by "launchctl" in mac systems. "just killing" it will kill that service.
Now to use mongo shell we do mongod again, however for other development purpose like connecting from node we need to make sure to run mongod time and again.
Other alternative is shut down the system and start again.
Better Way :
Start using launchctl to manage such services. Here is an example for that :
What is the correct way to start a mongod service on linux / OS X?
The easiest way is Ctrl + C, which worked for me on a blocking bash shell under El Capitan.
If you have configured autostart, killing the process won't help, new one will start immediately. In order to disable autostart, you have to locate the autostart file first. You can try to find the file using e.g.
find / -name "mongodb.plist" or locate "mongodb.plist"
After the file is found, remove the autostart config using (you can try without sudo first, it's not needed if you have done the installation using Homebrew):
sudo launchctl unload -w <file>
If you want to kill the process anyway and it's not using autostart, remember not to use kill -9 <PID>, it can damage the db. kill -1 <PID> or kill -15 <PID> should be safe options.
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/
official guide
remember not to use kill -9
otherwise maybe you need to remove lock file in dbpath

How do I start MariaDB on boot on Mac OS X?

Just installed MariaDB (with homebrew). Everything looks like it's working, but I can't figure out how to have it automatically startup on boot on my Mac. I can't find any Mac-specific docs for this.
The installation output says:
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
I guess I don't know where the right place is.
From brew info mariadb
To have launchd start mariadb now and restart at login:
brew services start mariadb
Or, if you don't want/need a background service you can just run:
mysql.server start
Just run brew services start mariadb on terminal.
With help from Calvin's answer (deleted, I guess?), and this page, these are the steps I used to accomplish this:
cp /usr/local/Cellar/mariadb/5.5.30/homebrew.mxcl.mariadb.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
On next boot, MariaDB was up and running.
If you install MariaDB by Homebrew, you can use this to see how to start your mariadb at login.
brew info mariadb
To have launchd start mariadb at login:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
You need to use launchd. See $ man launchd.
Additionally, Nathan wrote a good article on launchd.

Resources