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.

  • I think Ubuntu 16 is a systemd system, so, maybe write a service description file instead? Here's an example btw: gist.github.com/gambtho/36a2f01e9e7d8c1b0046fb074f1a44ee (I don't think you need all the details though).
    – wvxvw
    Nov 23 '17 at 13:37
  • Hi please explain this '$ZOOKEEPER_HOME/bin/zkServer.sh start' zookeeper line, is '$ZOOKEEPER_HOME/bin/zkServer.sh start' different from zookeeper or is it an argument pass in? Dec 13 '17 at 7:32
  • The command file path is $ZOOKEEPER_HOME/bin/zkServer.sh with start argument, and the user I want to run this command with is zookeeper. I tried without using variable $ZOOKEEPER_HOME but no difference. Thanks! Dec 13 '17 at 7:39
  • @GeorgeUdosen I want to run this command before logging in as user zookeeper. The post you suggest, running as a user try to run a command without password as another user. Dec 13 '17 at 12:02
  • @GeorgeUdosen My question is the same as that question about running Spark with the difference that I want to run a script as a special user. Dec 13 '17 at 12:05

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:


  • Hey your answer is ok but it runs my command under the user root but I want it to be run by a user named zookeeper, I have created a user named zookeeper in advance! Dec 13 '17 at 13:10
  • You know at the first line you said To run an app with a different name that the source script. I didn't want to run the app in a different name! I just to run it by a specific user at booting(before logging in) Dec 13 '17 at 13:19
  • 1
    Thanks, it solved. New problem is when zookeeper runs, it creates a zookeeper.out file on the directory the run command has been issued. For example, if I run it in home directory it creates a zookeeper.out file on home directory. Now as Zookeeper start command is running before logging in, it tries to create zookeeper.out file on path / that has no permission and fails! So is it possible to set command location run it systemd.unit? Dec 13 '17 at 13:44
  • Let us continue this discussion in chat. Dec 13 '17 at 15:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.