Ubuntu: How to start a Zookeeper daemon after booting under specific user in Ubuntu server 16.04 [duplicate]


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.


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

[Unit]  Description=Zookeeper Daemon  Wants=syslog.target    [Service]      Type=forking  WorkingDirectory=/path/to/dir/of/interest  User=zookeeper   ExecStart=/home/zookeeper_home/bin/zkServer.sh  TimeoutSec=30  Restart=on-failure    [Install]  WantedBy=multi-user.target  

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:


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »