What is Supervisor and how can you use it at Hipex?
Supervisorctl is a tool with which you can manage and monitor your own processes on the server. Every user has an own supervisorctl instance and therefore each user can manage its own processes without influencing the processes of another user. The biggest advantage of Supervisorctl is that you can manage your processes at one place.
At Hipex, you can make use of Supervisor with all available plans. In the steps below, we explain to you how to run a process yourself via Supervisor. In this example, we are going to run a Redis process.
Before we start, it is important to map the folder structure of the Hipex establishment. The location of Supervisor is for every plan:
/home/<username>/supervisor. The image below reflects the underlying folder structure.
Below an explanation of the concerned folder structure:
/home/<username>/supervisor └── log ├── supervisor.d ├── supervisor.pid └── supervisor.sock
All log files of Supervisor are located in this directory
All process configurations are located in this directory. When you want to run a process by the means of Supervisor, place the concercing configuration in this directory. How you create this kind of configuration will be explained in this article.
Every Supervisor instance will be runned as a process on the server. The process identification file of the concerning supervisor instance is in the supervisor.pid.
This is the Unix socket where the Supervisor instance is running under.
Now, the folder structure has been explained, we can start with making the configuration. As mentioned before, we make a Supervisor configuration for Redis in this article.
First of all, we start with the process name, the so-called “program”. Soon, you will see the provided name in Supervisor, this will be the name of the process. In our example, the process will be called “redis-session”:
How the concerned configuration file looks like can be read in this article.
Of course, we want to keep control over errors that might occur. To facilitate it, we provide the locations where any errors may be written to:
To the stdout_logfile option we can give the location to the file where the "stdout" output may be written to. stdout stands for the standard Linux output stream. Linux ensures that errors that occur will be written to here.
To the stderr_logfile option we can provide the location to the file where the "stderr" output may be written to. stderr stands for the standard Linux error stream. Linux ensures that errors that occur will be written to here:
If we merge all configurations above, we come to the following file.
[program:redis-session] command=/usr/bin/redis-server /home/<username>/redis/session.conf environment=HOME='/home/<username>/.bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin' stdout_logfile=/home/<username>/supervisor/log/redis-session.log stderr_logfile=/home/<username>/supervisor/log/redis-session.error.log
Now we have determined the configuration we can start with adding the process. For this, we create a file at the location
/home/<username>/supervisor/supervisor.d Good to know is that Supervisor reads files that end with the extension “.conf”. We name our configuration file redis-session.conf. Put the relevant configuration in this file and save it.
Then we run the command "supervisor":
Then execute "reread", with reread you let the Supervisor reload his configuration files:
supervisor> reread redis-session: available
You should see that the newly added program is available. We can then add this with "add":
supervisor> add redis-session redis-session: added process group
Finally, we can request the status with "status":
supervisor> status redis-session redis-session RUNNING pid 4581, uptime 0:00:01
We see that the instance is running (status RUNNING).
In addition to the mentioned reread, add and status actions, there are many others available, we would like to refer you to the documentation of Supervisor.
In this article we have limited ourselves to creating a basic supervisor configuration. For all configuration options, please refer to the documentation of supervisor.