Supervisor starts rabbitmq and reports an error

  • I restarted the server today, and found that the rabbitmq process managed by the supervisor failed to start. I checked the log and found that it always reported an error, and recorded the solution.

Error: erlexec: HOME must be set

  • Looking for blogs of many people on the Internet, the general statement is to add to the script of the process startup:
export HOME=/usr/local/erlang
export PATH=$PATH:$HOME/bin  
  • The default HONE of the system is /root, which may cause the erlang language environment to not be able to obtain the HOME parameter; the above modification can be used in the processes managed by chkconfig and service management, but for processes managed by supervisor, since the process startup is named in supervisor.conf , you cannot directly modify the HOME parameter.

Solution: Add the above statement to the supervisor's startup script.

vi Ssupervisor.conf

#!/bin/sh
# chkconfig: 2345 70 90

export HOME=/usr/local/erlang
export PATH=$PATH:$HOME/bin
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
  • Doing so ensures that HOME is only temporarily changed, but has no effect on the system's HOME.

Traceability

  • Why is there this error?

This error is not the cause of rabbitmq, but the erlang locale; look at an erl process:

ps aux | grep beam

# 结果:
root      1779  0.4  0.5 3863876 86060 ?       Sl   19:21   0:06 /usr/local/erlang/bin/x86_64-unknown-linux-gnu/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 32000 -K true -B i -- -root /usr/local/erlang -progname erl -- -home /root 
  • It can be seen that the -home parameter is added to the startup, and an erl instance is started, which calls the c file of erlexec;
# erlexec.c 文件的路径为/usr/local/erlang/erts/etc/common/erlexec.c

# 部分代码
static char * home;
static char ** Eargsp = NULL;
static int EargsCnt = 0;
static char **argsp = NULL;

static void get_home( void )
{
    home = get_env("HOME");
    if (home == NULL)
        error("HOME must be set");
}
  • You can see that the get_env function gets the HOME environment variable, and if the acquisition fails, it outputs 'HOME must be set'.

  • What I don't understand at present is that the HOME parameter has a default value of /root, why the get_env function cannot get it, but returns null; it needs to be further studied;

rabbitmq restart failed

  • After finding the process of manually killing rabbitmq, supervisor restarting rabbitmq either fails or does not restart;

  • It is possible to start and stop rabbitmq by using supervisor background process management, but if you manually kill the rabbitmq process, you cannot restart the process;

reason:

  1. After rabbitmq is started using rabbitmq-server start or rabbitmq-server, there will be two processes, one is the node service program of erlang; the other is the application of rabbitmq; the application of rabbitmq runs on the node of erlang;

  2. If the application process of rabbitmq is forcibly killed, the supervisor will try to start it. At this time, it will try to start the node service program of erlang and the application of rabbitmq, and find that there is already a node service program of erlang, so the startup will fail;

  3. If the erlang node service program is forcibly killed, both the erlang node service program and the rabbitmq application will be stopped. If the configuration parameter is autorestart=unexpected, then the supervisor will not restart the process. If the parameter is set to autorestart= true, then the supervisor will restart the erlang node service program and the rabbitmq application;

in conclusion:

  1. It is not very appropriate to manage the rabbitmq process by the supervisor, because the restart fails when the rabbitmq application crashes and the erlang node service program is normal;

  2. If only the node is running, but there is no rabbitmq application instance, then the management background of rabbitmq cannot be logged in.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324817095&siteId=291194637