[ejabberd] help with the start and stop of a ejabber server

Felipe Brito Vasconcellos fbv at trf4.gov.br
Fri May 27 18:19:41 MSD 2005


Hello.

I have done here a shell script (it is attached for those who want to 
use it too) to start, stop, restart and status of my service. A good 
thing is to put it at /etc/init.d on a suse system and then you can 
start and stop it using yast and runlevel editor. So, you can tell to 
the system this service should start at boot time or not.

I renamed it to rcejabberd. But you can put the ejabberd at /etc/init.d 
to see a service named ejabberd in runlevel editor. Then you can symlink 
it at /usr/sbin/rcejabberd to have the behavior of a suse system.

You can type rcejabberd start | stop | restart | status

Start execute the comand below.

The problem is with the STOP behavior. Here I look for every erlang 
process and get their PIDs and then kill them.

Here ->  erlang=$(ps ax | grep -i erlang | grep -v grep | awk '{print $1}')

So, I want to improve this behavior to a more smoothly one. :)

The status behavior is the same of the stop, but instead of killing the 
process I just show their PIDs. ;)

It is not the best solution. I want help to improve it and give it to 
the community.

My start method is ok.

I test if there is a erlang process running, if not, ok, the service can 
be started. I do this test here because the only thing that runs in 
erlang is the ejabberd.

The command is

/usr/local/bin/erl -pa /var/lib/ejabberd/ebin -sname ejabberd -s 
ejabberd -ejabberd config \"/etc/ejabberd/ejabberd.cfg\"  log_path 
\"/var/log/ejabberd/ejabberd.log\" -sasl sasl_error_logger 
\{file,\"/var/log/ejabberd/sasl.log\"\} -mnesia dir 
\"/var/lib/ejabberd/spool\" -detached 1>> "$LOG_DIR/$user-$data.log" 2>&1

ok. No trouble. The service goes up nicely.

So, help?

Question:  my ejabberd is running ok with -detached option. How can I 
get an erl console to type erlang commands in this server? Or, exist a 
erl -stop command? Something like this.

Thanks a lot! Hope I can help the project. :)

-- 
Felipe Brito Vasconcellos
Suporte Linux - fone (51) 3213-3624
Secretaria de Recursos Tecnológicos - Diretoria de Informática
Tribunal Regional Federal da 4ª Região 

-------------- next part --------------
#!/bin/bash
# Script de controle do servidor de mensagens instantâneas do TRF4
#
# Autor: Felipe Brito Vasconcellos <fbv at trf4.gov.br>
# Ramal 3624
# Versão 1.1 de 01/04/2005
#
# Uso: para iniciar o serviço disparar o comando
#      ejabberd start
#
#      para parar o serviço disparar o comando
#      ejabberd stop
#
### BEGIN INIT INFO
# Provides:       ejabberd
# Required-Start: $network
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:
# Description:    Start the ejabberd daemon
### END INIT INFO

# Descomentar a linha abaixo se o serviço for acessado por mais de 1024 usuários simultâneos
#export ERL_MAX_PORTS=32000

. /etc/rc.status
rc_reset

# Variaveis de controle para fins de geração de log
user=$(who am i | awk '{print $1}')      # Usuário que está executando o script
data=$(date +%Y%m%d)                     # Data da execução AnoMêsDia
LOG_DIR=/var/log/ejabberd                # Diretório de log padrão

start()
{
  /usr/local/bin/erl -pa /var/lib/ejabberd/ebin -sname ejabberd -s ejabberd -ejabberd config \"/etc/ejabberd/ejabberd.cfg\"  log_path \"/var/log/ejabberd/ejabberd.log\" -sasl sasl_error_logger \{file,\"/var/log/ejabberd/sasl.log\"\} -mnesia dir \"/var/lib/ejabberd/spool\" -detached 1>> "$LOG_DIR/$user-$data.log" 2>&1
  echo "$(date +%H:%M:%S): Usuário $user iniciou o serviço." >> "$LOG_DIR/$user-$data.log"
}

stop()
{
#PIDS=$(ps ax | grep -i erlang | awk '{print $1}')
  kill -9 $erlang >> "$LOG_DIR/$user-$data.log" 1>> "$LOG_DIR/$user-$data.log" 2>&1
  echo "$(date +%H:%M:%S): Usuário $user parou o serviço." >> "$LOG_DIR/$user-$data.log"
}

erlang=$(ps ax | grep -i erlang | grep -v grep | awk '{print $1}')

case "$1" in
  start)

    # Inicializa o serviço ejabberd
    if [[ $erlang ]]; then
      echo "Serviço já está no ar. PIDs dos processos:" $erlang
      exit 1
    else
      echo -n "Inicializando o ejabberd..."
      start
      rc_status -v
    fi
    ;;

  stop)

    # Para o serviço ejabberd
    if [[ ! $erlang ]]; then
      echo "Serviço não está no ar."
      exit 1
    else
      echo -n "Parando o serviço..."
      stop
      rc_status -v
    fi
    ;;

  restart)

    # Reinicia o serviço
    echo -n "Parando o serviço..."
    stop
    rc_status -v

    echo -n "Inicializando o ejabberd..."
    start
    rc_status -v
    ;;

  status)

    # Devolve PIDs dos processos
    if [[ $erlang ]]; then
      echo "Serviço está no ar. PIDs dos processos: " $erlang
    else
      echo -n "Serviço não está no ar."
    fi
    ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;

esac


More information about the ejabberd mailing list