官术网_书友最值得收藏!

Time for action — checking that CouchDB is running

We are going to attempt to hit the CouchDB service on our machine by using the command line utility cURL (we'll spell it curl from here on out for the sake of simplicity) that allows you to make raw HTTP requests. curl is our main method of communication with CouchDB. Let's start with a curl statement to talk to CouchDB.

  1. Open Terminal.
  2. Run the following statement to create a request that will hit CouchDB:
    curl http://127.0.0.1:5984/ 
    
  3. Terminal will reply with the following:
    {"couchdb":"Welcome","version":"1.0.2"} 
    

What just happened?

We just used curl to communicate with the CouchDB service by issuing a GET request. By default, curl will assume that we're trying to issue a GET request unless we tell it otherwise. We issued our curl statement to http://127.0.0.1:5984. Breaking this resource down into pieces, http://127.0.0.1 is the IP of our local computer, and 5984 is the port that CouchDB runs on by default.

Running CouchDB as a background process

If we were to stop our configuration here, you would have to run couchdb b each time you started development. This will quickly turn into a pain point for us. So, let's run CouchDB as a system daemon that will always run in the background, even after you restart your computer. In order to do this, we will use a Mac OS X service management framework, called launchd, that manages system daemons and allows them to be started and stopped.

  1. Open Terminal.
  2. Kill the background process of CouchDB, by running the following command:
    couchdb -k 
    
  3. If CouchDB was running, it would return the following text:
    Apache CouchDB has been killed. 
    
  4. Let's run CouchDB as a real background process and ensure that it starts each time you start your computer by running the following statement:
    launchctl load -w /usr/local/Cellar/couchdb/1.0.2/Library/LaunchDaemons/org.apache.couchdb.plist 
    

    Note

    If your version of CouchDB is different to mine, you will have to change the version in this script that says "1.0.2", to match your version.

CouchDB is now running in the background, and even if we restart our computer, we don't have to worry about starting the service before we try to use it.

If, for some reason, you decide that you don't want CouchDB running in the background, you can unload it by running the following command:

launchctl unload /usr/local/Cellar/couchdb/1.0.2/Library/LaunchDaemons/org.apache.couchdb.plist 

You can double-check to make sure that CouchDB is running by using the curl statement that we used earlier:

  1. Open Terminal.
  2. Run the following command:
    curl http://127.0.0.1:5984/ 
    
  3. Terminal will reply with the following:
    {"couchdb":"Welcome","version":"1.0.2"} 
    
主站蜘蛛池模板: 礼泉县| 扶沟县| 嘉禾县| 长兴县| 乐昌市| 横山县| 太原市| 正蓝旗| 昔阳县| 岳西县| 固始县| 临颍县| 鹰潭市| 望奎县| 浦东新区| 阳曲县| 通渭县| 含山县| 华宁县| 略阳县| 江山市| 子长县| 景德镇市| 阿拉善右旗| 夏河县| 饶阳县| 丁青县| 长兴县| 河池市| 佳木斯市| 普安县| 丰台区| 明溪县| 广南县| 兴隆县| 赤壁市| 清涧县| 克拉玛依市| 桐柏县| 武隆县| 西乌|