I personally build CouchDB from source code and run as user couchdb. Binaries are available with systemd startup scripts, they are not the topic of this guide. If you are using systemd then set the environment variable COUCHDB_QUERY_SERVER_PYTHON3= in your script.
Add user couchdb
Install runit - 18.04+ include runit-systemd
Install Python *View Server for --user couchdb (recommended) or global
Install Cloudant client
CouchDB runit setup for user couchdb
CouchDB default javascript view
Equivalent Python 3 view
Add user couchdb
sudo adduser --system --shell /bin/bash --group --gecos "CouchDB Administrator" couchdb
Install runit - 18.04+ include runit-systemd
sudo apt install runit runit-systemd
Install Python *View Server for --user couchdb (recommended) or global
pip3 install couchdb-python
* No longer maintained, I only use the view server and use cloudant for the client.
Install Cloudant client
pip3 install cloudant
CouchDB runit setup for user couchdb
sudo mkdir /var/log/couchdb
sudo chown couchdb:couchdb /var/log/couchdb
sudo mkdir /etc/sv/couchdb
sudo mkdir /etc/sv/couchdb/log
sudo vim /etc/sv/couchdb/log/run
#!/usr/bin/env sh
exec svlogd -tt /var/log/couchdb
sudo vim /etc/sv/couchdb/run
#!/usr/bin/env sh
export HOME=/home/couchdb
exec 2>&1
exec chpst -u couchdb env COUCHDB_QUERY_SERVER_PYTHON3='/usr/bin/python3 /home/couchdb/.local/bin/couchpy' /home/couchdb/couchdb/bin/couchdb
sudo chmod u+x /etc/sv/couchdb/log/run
sudo chmod u+x /etc/sv/couchdb/run
sudo ln -s /etc/sv/couchdb/ /etc/service/couchdb
Start / Stop / Status Couchdb
sudo sv status couchdb
sudo sv stop couchdb
sudo sv start couchdb
CouchDB default javascript view
{
"_id" : "_design/jsview",
"indexes" : {},
"lists" : {},
"views" : {
"vname" : {
"map" : "function (doc) {\n emit(doc._id, 1);\n}"
}
},
"shows" : {},
"language" : "javascript"
}
function (doc) {
emit(doc._id, 1);
}
Equivalent Python 3 view
{
"_id" : "_design/pyview",
"indexes" : {},
"lists" : {},
"views" : {
"vname" : {
"map" : "def fun(doc) {\n yield([_id], 1);\n}"
}
},
"shows" : {},
"language" : "python3"
}
def fun(doc):
yield(doc['_id'], 1)
Well done!
ReplyDelete