{"id":128,"date":"2015-03-10T21:04:05","date_gmt":"2015-03-10T21:04:05","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=128"},"modified":"2015-03-10T21:04:05","modified_gmt":"2015-03-10T21:04:05","slug":"set-up-mongodb-as-a-daemon-service-on-a-mac","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=128","title":{"rendered":"Set up Mongodb as a daemon \/ service on a Mac &#8211;"},"content":{"rendered":"<h1>Launch MongoDB on Startup or User Login<\/h1>\n<p>A quick post on setting up Mongodb to start automatically on a Mac so I can do my other work. To start, I found a link to Apple&#8217;s info about Mac daemons and services.<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/MacOSX\/Conceptual\/BPSystemStartup\/Chapters\/Introduction.html\" title=\"Apple's documentation on Daemons and Services\">About Daemons and Services<\/a><\/p>\n<p>Which lead me to the section that specifically talks about Launching Custom Daemons Using launchd.<\/p>\n<p><a href=\"https:\/\/developer.apple.com\/library\/mac\/documentation\/MacOSX\/Conceptual\/BPSystemStartup\/Chapters\/CreatingLaunchdJobs.html#\/\/apple_ref\/doc\/uid\/10000172i-SW7-BCIEDDBJ\" title=\"Launching Custom Daemons Using launchd\">Launching Custom Daemons Using launchd<\/a><\/p>\n<p>Which talks about system daemons.<\/p>\n<p>It uses the plist files in the following folders \/System\/Library\/LaunchDaemons\/ and \/Library\/LaunchDaemons\/ to register daemons. It attempts to launch the daemons in a somewhat random order, if a daemon has a dependency, its launch is deferred momentarily while other daemons are launched.<\/p>\n<h2>MONGODB as a daemon \/ service for mac<\/h2>\n<h2>Create a link to the MONGODB plist file<\/h2>\n<h3>(s = symbolic, f = replace existing, n = link is seen as a normal file)<\/h3>\n<h2>To start using the current users LaunchAgents<\/h2>\n<p>ln -sfv \/usr\/local\/opt\/mongodb\/*.plist ~\/Library\/LaunchAgents<\/p>\n<h3>use launchctl to direct launchd to load mongodb .<\/h3>\n<p>launchctl load ~\/Library\/LaunchAgents\/homebrew.mxcl.mongodb.plist<\/p>\n<h2>To start as a system wide daemon use the following<\/h2>\n<p>ln -sfv \/usr\/local\/opt\/mongodb\/*.plist \/Library\/LaunchDaemons\/<\/p>\n<h3>use launchctl to direct launchd to load mongodb .<\/h3>\n<p>launchctl load \/Library\/LaunchDaemons\/homebrew.mxcl.mongodb.plist<\/p>\n<p>homebrew.mxcl.mongodb.plist<\/p>\n<p>This file tells launchd how to launch the application, where the config files and log files should be and should look something like this.<br \/>\n<code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<br \/>\n&lt;!DOCTYPE plist PUBLIC \"-\/\/Apple\/\/DTD PLIST 1.0\/\/EN\" \"http:\/\/www.apple.com\/DTDs\/PropertyList-1.0.dtd\"&gt;<br \/>\n&lt;plist version=\"1.0\"&gt;<br \/>\n&lt;dict&gt;<br \/>\n  &lt;key&gt;Label&lt;\/key&gt;<br \/>\n  &lt;string&gt;homebrew.mxcl.mongodb&lt;\/string&gt;<br \/>\n  &lt;key&gt;ProgramArguments&lt;\/key&gt;<br \/>\n  &lt;array&gt;<br \/>\n    &lt;string&gt;\/usr\/local\/opt\/mongodb\/bin\/mongod&lt;\/string&gt;<br \/>\n    &lt;string&gt;--config&lt;\/string&gt;<br \/>\n    &lt;string&gt;\/usr\/local\/etc\/mongod.conf&lt;\/string&gt;<br \/>\n  &lt;\/array&gt;<br \/>\n  &lt;key&gt;RunAtLoad&lt;\/key&gt;<br \/>\n  &lt;true\/&gt;<br \/>\n  &lt;key&gt;KeepAlive&lt;\/key&gt;<br \/>\n  &lt;false\/&gt;<br \/>\n  &lt;key&gt;WorkingDirectory&lt;\/key&gt;<br \/>\n  &lt;string&gt;\/usr\/local&lt;\/string&gt;<br \/>\n  &lt;key&gt;StandardErrorPath&lt;\/key&gt;<br \/>\n  &lt;string&gt;\/usr\/local\/var\/log\/mongodb\/output.log&lt;\/string&gt;<br \/>\n  &lt;key&gt;StandardOutPath&lt;\/key&gt;<br \/>\n  &lt;string&gt;\/usr\/local\/var\/log\/mongodb\/output.log&lt;\/string&gt;<br \/>\n  &lt;key&gt;HardResourceLimits&lt;\/key&gt;<br \/>\n  &lt;dict&gt;<br \/>\n    &lt;key&gt;NumberOfFiles&lt;\/key&gt;<br \/>\n    &lt;integer&gt;1024&lt;\/integer&gt;<br \/>\n  &lt;\/dict&gt;<br \/>\n  &lt;key&gt;SoftResourceLimits&lt;\/key&gt;<br \/>\n  &lt;dict&gt;<br \/>\n    &lt;key&gt;NumberOfFiles&lt;\/key&gt;<br \/>\n    &lt;integer&gt;1024&lt;\/integer&gt;<br \/>\n  &lt;\/dict&gt;<br \/>\n&lt;\/dict&gt;<br \/>\n&lt;\/plist&gt;<\/code><\/p>\n<p>The config location is referenced in above plist file (<code><string>--config<\/string><\/code>). Currently, the default points to \/usr\/local\/etc\/mongod.conf. Set the dbPath to the path to the db for your implementation.<\/p>\n<p>mongod.conf<br \/>\n<code>systemLog:<br \/>\n  destination: filexvc<br \/>\n  path: \/usr\/local\/var\/log\/mongodb\/mongo.log<br \/>\n  logAppend: true<br \/>\nstorage:<br \/>\n  dbPath: \/dbData\/db<br \/>\nnet:<br \/>\n  bindIp: 127.0.0.1<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Launch MongoDB on Startup or User Login A quick post on setting up Mongodb to start automatically on a Mac so I can do my other work. To start, I found a link to Apple&#8217;s info about Mac daemons and services. About Daemons and Services Which lead me to the section that specifically talks about [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":9,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}