Add systemd Startup Script For CouchDB

Add systemd Startup Script For CouchDB

Get Social!

couchdb-whiteCurrently, version 2.0 of CouchDB doesn’t come with any form of startup script. I’m sure that as the CouchDB 2 branch becomes more mature and it’s added to the various software repositories startup scripts will be shipped as standard, but until then we have to make do.

The below script is a systemd startup script with a cat command to create the file with the required content in the systemd config directories. Run the below script to create the startup file. You’ll need to change /usr/bin/couchdb to be the location of your couchdb executable.

cat <<EOT >> /etc/systemd/system/couchdb.service
[Unit]
Description=Couchdb service
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/usr/bin/couchdb -o /dev/stdout -e /dev/stderr
Restart=always
EOT

You’ll then need to reload the systemd daemon and add the couchdb service to the startup routine. Run the below commands to enable CouchDB at machine startup.

systemctl  daemon-reload
systemctl  start couchdb.service
systemctl  enable couchdb.service

 


12 Comments

Dennis

13-Feb-2017 at 1:49 pm

Thankx, worked :)

Dennis

14-Feb-2017 at 10:45 am

Autostart on reboot didn’t work yet. I had to add the lines:

[Install]
WantedBy=multi-user.target

to the file. After this “enable” created a symlink in /etc/systemd/system/multi-user.target.wants/

    james.coyle

    14-Feb-2017 at 10:50 am

    Thanks for the info, Dennis.

Eric

17-Apr-2017 at 9:00 pm

Great article!
This worked for me, but only by changing the user to root. I was wondering how you were able to run this as couchdb.

Ronan

23-May-2017 at 8:03 am

Eric, in /usr/bin you need to be root to execute. But you can install couchdb on different path to work with couchdb user.

Alfredo

2-Jun-2017 at 7:08 pm

Thank you!
This is my final file using all the instructions from the installation guide of couchdb:

—————————
# cat /etc/systemd/system/couchdb.service
[Unit]
Description=Couchdb service
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/home/couchdb/couchdb/bin/couchdb -o /dev/stdout -e /dev/stderr
Restart=always

[Install]
WantedBy=multi-user.target
—————————

Rick Berger

26-Sep-2017 at 11:48 pm

If I do a ‘systemctl stop couchdb.service’, I note that ‘/var/lib/couchdb/bin/../erts-8.2.1/bin/epmd -daemon’ is still running. Any way to get that to stop, too?

Steven Buehler

18-Jun-2018 at 1:15 am

Won’t start:

● couchdb.service – Couchdb service
Loaded: loaded (/etc/systemd/system/couchdb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-06-17 20:14:45 EDT; 2s ago
Process: 19066 ExecStart=/usr/bin/couchdb -o /dev/stdout -e /dev/stderr (code=exited, status=203/EXEC)
Main PID: 19066 (code=exited, status=203/EXEC)

Jun 17 20:14:45 raspberrypi systemd[1]: couchdb.service: Failed with result ‘exit-code’.
Jun 17 20:14:45 raspberrypi systemd[1]: couchdb.service: Service hold-off time over, scheduling restart.
Jun 17 20:14:45 raspberrypi systemd[1]: Stopped Couchdb service.
Jun 17 20:14:45 raspberrypi systemd[1]: couchdb.service: Start request repeated too quickly.
Jun 17 20:14:45 raspberrypi systemd[1]: Failed to start Couchdb service.
Jun 17 20:14:45 raspberrypi systemd[1]: couchdb.service: Unit entered failed state.
Jun 17 20:14:45 raspberrypi systemd[1]: couchdb.service: Failed with result ‘exit-code’.

Tom

17-Jul-2018 at 9:52 am

i still get -bash: /etc/systemd/system/couchdb.service: Permission denied

even though i changed the path to my installation path of couchdb. changing user to root doesn’t help either.

    Yoann

    18-Nov-2018 at 9:53 pm

    Same problem for me

Lawrence Mugambi

22-May-2019 at 10:12 pm

On CentOS it enabling the service doesn’t work unless you put a section

[Install]
WantedBy=multi-user.target

Srinivas Suryadevara

16-Jul-2019 at 2:54 pm

Does chkconfig –level 2345 couchdb on also enables CouchDB auto restart enables

Leave a Reply

Visit our advertisers

Quick Poll

Do you use GlusterFS in your workplace?

Visit our advertisers