Ubuntu – How to start a Zookeeper daemon after booting under specific user in Ubuntu server 16.04

bashcommand lineserverstartup

I want to start Zookeeper daemon after Ubuntu server 16.04 booting (not after logging) under user named zookeeper. So I changed the file /etc/rc.local like the following:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

echo 'never'; defrag_file_pathname

su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper &

exit 0

, adding the line su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper & before exit 0. But the process is not started after restarting!

What's wrong here?

details: The zookeeper user is in sudo group and has password.

details: When I run command su -c '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper & in terminal, it needs password to run.

Best Answer

Create a .service file in /etc/systemd/system/zoo.service and add the following lines:

Description=Zookeeper Daemon



Now setup the service:

sudo systemctl start zoo
sudo systemctl enable zoo

Check status:

sudo systemctl status zoo

Please read for further details creating daemons: