-
Notifications
You must be signed in to change notification settings - Fork 61
Supervisor
1.1. Running Zookeeper with Supervisor
Supervisor monitors programs and automatically restarts them if they fail, which is useful for long-running tools like Flask, Zookeeper, and Storm.
## Download and Configure Supervisornode:~$ sudo apt-get install supervisor
Next restart the supervisor service
node:~$ sudo service supervisor restart
Supervisor will now run any programs that have scripts in the /etc/supervisor/conf.d
directory (see Zookeeper example in the next section).
Now we can run Supervisor with the various supervisorctl commands
node:~$ sudo supervisorctl help
A few useful commands are status, start, restart, and stop (you may need sudo).
For example, you can stop a specific process (e.g. Zookeeper) with:
node:~$ sudo supervisorctl stop zookeeper
This is the proper way to stop a process under supervision. If you start it again and check the status with
node:~$ sudo supervisorctl start zookeeper node:~$ sudo supervisorctl status
you can see the process ids and uptime. If you try to kill the process without using supervisorctl, it will restart itself automatically (which is the whole point of Supervisor!)
You may find it useful to see the tail of a given log with:
node:~$ sudo supervisorctl tail zookeeper
Supervisor is useful for many applications like Kafka, Storm, or even running your Flask microserver. To add new programs simply and another configuration file (e.g. kafka.conf) to the conf.d directory and repeat the reread and update commands from above.
If you have the WebUI enabled, you can view and control Supervisor more conveniently by going to http://<node’s-public-dns>:9002
. In particular, the “Clear Log” and “Tail -f” features are really nice for debugging.
First, if Zookeeper is still running from the Zookeeper Dev, stop it with:
node:~$ sudo /usr/local/zookeeper/bin/zkServer.sh stop
Write a configuration script in the /etc/supervisor/conf.d
directory:
node:~$ sudo nano /etc/supervisor/conf.d/zookeeper.conf
With the following configuration
[program:zookeeper] command=/usr/local/zookeeper/bin/zkServer.sh start-foreground autorestart=true user=root stderr_logfile=/usr/local/zookeeper/zk.err.log stdout_logfile=/usr/local/zookeeper/zk.out.log stopasgroup=true killasgroup=true stopsignal=KILL
Now every time this node is started, the command following command will be ran, and importantly it will run this again if Zookeeper fails, rather than you checking it all the time and manually restarting. It also redirects standard error and output to the corresponding logs for easy troubleshooting.
In order to update Supervisor to read this new configuration file, you need to have it re-read the file and update it with the supervisorctl command
node:~$ sudo supervisorctl reread node:~$ sudo supervisorctl update
That’s it, Supervisor will now keep Zookeeper up, even if unforeseen errors cause it to fail.
Find out more about the Insight Data Engineering Fellows Program in New York and Silicon Valley, apply today, or sign up for program updates.
You can also read our engineering blog here.