From 69805f36fa8b517242c4729da03e208f6afe6dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Wed, 17 Dec 2008 13:52:44 +0000 Subject: [PATCH] Merge from trunk (r1730 to r1734). PR: EJABP-1 SVN Revision: 1735 --- ChangeLog | 28 +++++++++ README | 2 +- doc/guide.html | 114 +++++++++++++++++++--------------- doc/guide.tex | 92 +++++++++++++++------------ src/ejabberd.cfg.example | 5 +- src/ejabberd_admin.erl | 17 +++++ src/ejabberd_logger_h.erl | 7 ++- src/mod_pubsub/mod_pubsub.erl | 112 +++++++++++++++++---------------- 8 files changed, 228 insertions(+), 149 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba97da968..51a2c7540 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2008-12-17 Jean-Sébastien Pédron + + Merge from trunk (r1730 to r1734). + +2008-12-16 Badlop + + * src/mod_pubsub/mod_pubsub.erl: Fix update pubsub tables from + ejabberd 1.x to 2.x (EJAB-817) + + * doc/guide.tex: Fix capitalization of some section titles + + * doc/guide.tex: Mention as optional Requirements: mysql, pgsql + and pam + + * src/ejabberd_admin.erl: Command reopen-log must also rotate + sasl.log (thanks to Alexander Tsvyashchenko)(EJAB-711) + * src/ejabberd_logger_h.erl: Export the function rotate_log/1 + * doc/guide.tex: Improve explanation of log files rotation + + * doc/guide.tex: Improve explanation of watchdog admins + option: only useful for developers (EJAB-816) + * src/ejabberd.cfg.example: Likewise + + * doc/guide.tex: Say 'higher' instead of 'newer' in requirements + * README: Likewise + + * doc/guide.tex: Simplify example mod_muc configuration + 2008-12-16 Jean-Sébastien Pédron Merge from trunk (r1709 to r1730). diff --git a/README b/README index e798e9095..bbc9511ab 100644 --- a/README +++ b/README @@ -9,7 +9,7 @@ To compile ejabberd you need: - GNU Make - GCC - libexpat 1.95 or higher - - Erlang/OTP R10B-9 or newer + - Erlang/OTP R10B-9 or higher - OpenSSL 0.9.6 or higher, for STARTTLS, SASL and SSL encryption. Optional, highly recommended. - Zlib 1.2.3 or higher, for Stream Compression support diff --git a/doc/guide.html b/doc/guide.html index e33aaf296..2982f355d 100644 --- a/doc/guide.html +++ b/doc/guide.html @@ -96,7 +96,7 @@ BLOCKQUOTE.figure DIV.center DIV.center HR{display:none;}
  • Chapter 2  Installing ejabberd -
  • Chapter 4  Managing an ejabberd server +
  • Chapter 4  Managing an ejabberd Server
  • Chapter 6  Clustering
    • @@ -199,9 +199,9 @@ BLOCKQUOTE.figure DIV.center DIV.center HR{display:none;}
  • Chapter 7  Debugging
  • Appendix A  Internationalization and Localization
  • Appendix B  Release Notes @@ -304,8 +304,8 @@ or with the command bin/ejabberdctl live in other Operating Systems. This way you see the error message provided by Erlang and can identify what is exactly the problem.

    The ejabberdctl administration script is included in the bin directory. Please refer to the section 4.1 for details about ejabberdctl, -and configurable options to fine tune the Erlang runtime system.

    -

    2.2  Installing ejabberd with Operating System specific packages

    Some Operating Systems provide a specific ejabberd package adapted to +and configurable options to fine tune the Erlang runtime system.

    +

    2.2  Installing ejabberd with Operating System Specific Packages

    Some Operating Systems provide a specific ejabberd package adapted to the system architecture and libraries. It usually also checks dependencies and performs basic configuration tasks like creating the initial @@ -330,10 +330,13 @@ as long as your system have all the dependencies.

  • GCC
  • Libexpat 1.95 or higher -
  • Erlang/OTP R10B-9 or newer. +
  • Erlang/OTP R10B-9 or higher.
  • OpenSSL 0.9.6 or higher, for STARTTLS, SASL and SSL encryption. Optional, highly recommended.
  • Zlib 1.2.3 or higher, for Stream Compression support (XEP-0138). Optional. -
  • GNU Iconv 1.8 or higher, for the IRC Transport (mod_irc). Optional. Not needed on systems with GNU Libc. +
  • Erlang mysql library. Optional. For MySQL authentication or storage. See section 3.2.1. +
  • Erlang pgsql library. Optional. For PostgreSQL authentication or storage. See section 3.2.3. +
  • PAM library. Optional. For Pluggable Authentication Modules (PAM). See section 3.1.4. +
  • GNU Iconv 1.8 or higher, for the IRC Transport (mod_irc). Optional. Not needed on systems with GNU Libc. See section 3.3.6.
  • 2.4.2  Download Source Code

    Released versions of ejabberd are available in the ProcessOne ejabberd downloads page: @@ -400,7 +403,7 @@ to install ejabberd.

    The files and directories created are, by de .erlang.cookie

    Erlang cookie file (see section 5.3)
    acl.DCD, ...
    Mnesia database spool files (*.DCD, *.DCL, *.DAT)
    -
    /var/log/ejabberd/
    Log directory (see section 7.2): +
    /var/log/ejabberd/
    Log directory (see section 7.1):
    ejabberd.log
    ejabberd service log
    sasl.log
    Erlang/OTP system log @@ -1254,7 +1257,7 @@ For that purpose, the options described in the next sections must be set inside a host_cofig for each vhost (see section 3.1.2). For example:

    {host_config, "public.example.org", [
    -  {odbc_server, {pgsql, "localhost", "database", "ejabberd", "password"}},
    +  {odbc_server, {pgsql, "localhost", "database-public-example-org", "ejabberd", "password"}},
       {auth_method, [odbc]}
     ]}.
     

    @@ -2106,16 +2109,16 @@ to new hardware. This will involve service breakdowns around 23:00 UMT. We apologise for this inconvenience.’ to conference.example.org, it will be displayed in all active rooms. In this example the history feature is disabled. -
    {acl, admins, {user, "admin", "example.org"}}.
    +
    {acl, admin, {user, "admin", "example.org"}}.
     
    -{access, muc_admins, [{allow, admins}]}.
    +{access, muc_admin, [{allow, admin}]}.
     
     {modules,
      [
       ...
       {mod_muc, [{access, all},
                  {access_create, all},
    -             {access_admin, muc_admins},
    +             {access_admin, muc_admin},
                  {history_size, 0}]},
       ...
      ]}.
    @@ -2132,20 +2135,20 @@ and the default value of 20 history messages will be send to the users.
     
    {acl, paying_customers, {user, "customer1", "example.net"}}.
     {acl, paying_customers, {user, "customer2", "example.com"}}.
     {acl, paying_customers, {user, "customer3", "example.org"}}.
    -{acl, admins, {user, "admin", "example.org"}}.
    +{acl, admin, {user, "admin", "example.org"}}.
     
    -{access, muc_admins, [{allow, admins},
    +{access, muc_admin, [{allow, admin},
                           {deny, all}]}.
     {access, muc_access, [{allow, paying_customers},
    -                      {allow, admins},
    +                      {allow, admin},
                           {deny, all}]}.
     
     {modules,
      [
       ...
       {mod_muc, [{access, muc_access},
    -             {access_create, muc_admins},
    -             {access_admin, muc_admins}]},
    +             {access_create, muc_admin},
    +             {access_admin, muc_admin}]},
       ...
      ]}.
     
  • In the following example, MUC anti abuse options are used. An @@ -2164,7 +2167,7 @@ the newly created rooms have by default those options. [ ... {mod_muc, [{access, muc_access}, - {access_create, muc_admins}, + {access_create, muc_admin}, {default_room_options, [ {allow_change_subj, false}, @@ -2174,7 +2177,7 @@ the newly created rooms have by default those options. {title, "New chatroom"}, {anonymous, false} ]}, - {access_admin, muc_admins}]}, + {access_admin, muc_admin}]}, ... ]}.
  • @@ -2897,8 +2900,8 @@ answers ejabberd’s version when queried.

    Options: The default value is true.

    iqdisc
    This specifies the processing discipline for Software Version (jabber:iq:version) IQ queries (see section 3.3.2). -

    -

    Chapter 4  Managing an ejabberd server

    +

    +

    Chapter 4  Managing an ejabberd Server

    4.1  ejabberdctl

    4.1.1  Commands

    The ejabberdctl command line administration script allows to start, stop and perform many other administrative tasks in a local or remote ejabberd server.

    When ejabberdctl is executed without any parameter, @@ -2915,8 +2918,9 @@ The more interesting ones are: help

    Get help about ejabberdctl or any available command. Try ejabberdctl help help.
    status
    Check the status of the ejabberd server.
    stop
    Stop the ejabberd server which is running in the machine. -
    reopen-log
    If you use a tool to rotate logs, you have to configure it -so that this command is executed after each rotation. +
    reopen-log
    Reopen the log files after they were renamed. +If the old files were not renamed before calling this command, +they are automatically renamed to "*-old.log". See section 7.1.
    backup, restore, install-fallback, dump, load
    You can use these commands to create and restore backups.
    import-file, import-dir
    @@ -2933,8 +2937,8 @@ error is represented by 1, and other codes may be used for specifical results. This can be used by other scripts to determine automatically if a command succedded or failed, -for example using: echo $?

    -

    4.1.2  Erlang runtime system

    ejabberd is an Erlang/OTP application that runs inside an Erlang runtime system. +for example using: echo $?

    +

    4.1.2  Erlang Runtime System

    ejabberd is an Erlang/OTP application that runs inside an Erlang runtime system. This system is configured using environment variables and command line parameters. The ejabberdctl administration script uses many of those possibilities. You can configure some of them with the file ejabberdctl.cfg, @@ -3133,8 +3137,8 @@ However, the cookie system is not ultimately effective to prevent unauthorized access or intrusion to an Erlang node. The communication between Erlang nodes are not encrypted, so the cookie could be read sniffing the traffic on the network. -The recommended way to secure the Erlang node is to block the port 4369.

    -

    5.4  Erlang node name

    An Erlang node may have a node name. +The recommended way to secure the Erlang node is to block the port 4369.

    +

    5.4  Erlang Node Name

    An Erlang node may have a node name. The name can be short (if indicated with the command-line parameter -sname) or long (if indicated with the parameter -name). Starting an Erlang node with -sname limits the communication between Erlang nodes to the LAN.

    Using the option -sname instead of -name is a simple method @@ -3142,8 +3146,8 @@ to difficult unauthorized access to your Erlang node. However, it is not ultimately effective to prevent access to the Erlang node, because it may be possible to fake the fact that you are on another network using a modified version of Erlang epmd. -The recommended way to secure the Erlang node is to block the port 4369.

    -

    5.5  Securing sensible files

    ejabberd stores sensible data in the file system either in plain text or binary files. +The recommended way to secure the Erlang node is to block the port 4369.

    +

    5.5  Securing Sensible Files

    ejabberd stores sensible data in the file system either in plain text or binary files. The file system permissions should be set to only allow the proper user to read, write and execute those files and directories.

    ejabberd configuration file: /etc/ejabberd/ejabberd.cfg
    @@ -3256,20 +3260,8 @@ domain.

    Chapter 7  Debugging

    -

    -

    7.1  Watchdog Alerts

    -

    ejabberd includes a watchdog mechanism. -If a process in the ejabberd server consumes too much memory, -a message is sent to the Jabber accounts defined with the option -watchdog_admins - in the ejabberd configuration file. -Example configuration: -

    {watchdog_admins, ["admin2@localhost", "admin2@example.org"]}.
    -

    To remove watchdog admins, remove them in the option. -To remove all watchdog admins, set the option with an empty list: -

    {watchdog_admins, []}.
    -

    -

    7.2  Log Files

    An ejabberd node writes two log files: +

    +

    7.1  Log Files

    An ejabberd node writes two log files:

    ejabberd.log
    is the ejabberd service log, with the messages reported by ejabberd code
    sasl.log
    is the Erlang/OTP system log, with the messages reported by Erlang/OTP using SASL (System Architecture Support Libraries) @@ -3285,12 +3277,32 @@ The possible levels are:

    For example, the default configuration is:

    {loglevel, 4}.
    -

    -

    7.3  Debug Console

    The Debug Console is an Erlang shell attached to an already running ejabberd server. +

    The log files grow continually, so it is recommended to rotate them periodically. +To rotate the log files, rename the files and then reopen them. +The ejabberd command reopen-log +(please refer to section 4.1.1) +reopens the log files, +and also renames the old ones if you didn’t rename them.

    +

    7.2  Debug Console

    The Debug Console is an Erlang shell attached to an already running ejabberd server. With this Erlang shell, an experienced administrator can perform complex tasks.

    This shell gives complete control over the ejabberd server, so it is important to use it with extremely care. There are some simple and safe examples in the article -Interconnecting Erlang Nodes

    To exit the shell, close the window or press the keys: control+c control+c.

    +Interconnecting Erlang Nodes

    To exit the shell, close the window or press the keys: control+c control+c.

    +

    7.3  Watchdog Alerts

    +

    ejabberd includes a watchdog mechanism that may be useful to developers +when troubleshooting a problem related to memory usage. +If a process in the ejabberd server consumes a lot of memory, +a message is sent to the Jabber accounts defined with the option +watchdog_admins + in the ejabberd configuration file. +Note that the threshold to define what is too much memory usage +is only configurable editing the source code. +Example configuration: +

    {watchdog_admins, ["admin2@localhost", "admin2@example.org"]}.
    +

    To remove watchdog admins, remove them in the option. +To remove all watchdog admins, set the option with an empty list: +

    {watchdog_admins, []}.
    +

    Appendix A  Internationalization and Localization

    The source code of ejabberd supports localization. The translators can edit the diff --git a/doc/guide.tex b/doc/guide.tex index d40cd8ae5..0ca65220b 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -261,7 +261,7 @@ The \term{ejabberdctl} administration script is included in the \term{bin} direc Please refer to the section~\ref{ejabberdctl} for details about \term{ejabberdctl}, and configurable options to fine tune the Erlang runtime system. -\makesection{install.os}{Installing \ejabberd{} with Operating System specific packages} +\makesection{install.os}{Installing \ejabberd{} with Operating System Specific Packages} Some Operating Systems provide a specific \ejabberd{} package adapted to the system architecture and libraries. @@ -301,10 +301,13 @@ To compile \ejabberd{} on a `Unix-like' operating system, you need: \item GNU Make \item GCC \item Libexpat 1.95 or higher -\item Erlang/OTP R10B-9 or newer. +\item Erlang/OTP R10B-9 or higher. \item OpenSSL 0.9.6 or higher, for STARTTLS, SASL and SSL encryption. Optional, highly recommended. \item Zlib 1.2.3 or higher, for Stream Compression support (\xepref{0138}). Optional. -\item GNU Iconv 1.8 or higher, for the IRC Transport (mod\_irc). Optional. Not needed on systems with GNU Libc. +\item Erlang mysql library. Optional. For MySQL authentication or storage. See section \ref{compilemysql}. +\item Erlang pgsql library. Optional. For PostgreSQL authentication or storage. See section \ref{compilepgsql}. +\item PAM library. Optional. For Pluggable Authentication Modules (PAM). See section \ref{pam}. +\item GNU Iconv 1.8 or higher, for the IRC Transport (mod\_irc). Optional. Not needed on systems with GNU Libc. See section \ref{modirc}. \end{itemize} \makesubsection{download}{Download Source Code} @@ -2756,16 +2759,16 @@ Examples: it will be displayed in all active rooms. In this example the history feature is disabled. \begin{verbatim} -{acl, admins, {user, "admin", "example.org"}}. +{acl, admin, {user, "admin", "example.org"}}. -{access, muc_admins, [{allow, admins}]}. +{access, muc_admin, [{allow, admin}]}. {modules, [ ... {mod_muc, [{access, all}, {access_create, all}, - {access_admin, muc_admins}, + {access_admin, muc_admin}, {history_size, 0}]}, ... ]}. @@ -2784,20 +2787,20 @@ Examples: {acl, paying_customers, {user, "customer1", "example.net"}}. {acl, paying_customers, {user, "customer2", "example.com"}}. {acl, paying_customers, {user, "customer3", "example.org"}}. -{acl, admins, {user, "admin", "example.org"}}. +{acl, admin, {user, "admin", "example.org"}}. -{access, muc_admins, [{allow, admins}, +{access, muc_admin, [{allow, admin}, {deny, all}]}. {access, muc_access, [{allow, paying_customers}, - {allow, admins}, + {allow, admin}, {deny, all}]}. {modules, [ ... {mod_muc, [{access, muc_access}, - {access_create, muc_admins}, - {access_admin, muc_admins}]}, + {access_create, muc_admin}, + {access_admin, muc_admin}]}, ... ]}. \end{verbatim} @@ -2824,7 +2827,7 @@ defined, but some user restriction could be added as well: [ ... {mod_muc, [{access, muc_access}, - {access_create, muc_admins}, + {access_create, muc_admin}, {default_room_options, [ {allow_change_subj, false}, @@ -2834,7 +2837,7 @@ defined, but some user restriction could be added as well: {title, "New chatroom"}, {anonymous, false} ]}, - {access_admin, muc_admins}]}, + {access_admin, muc_admin}]}, ... ]}. \end{verbatim} @@ -3727,7 +3730,7 @@ Options: \iqdiscitem{Software Version (\ns{jabber:iq:version})} \end{description} -\makechapter{manage}{Managing an \ejabberd{} server} +\makechapter{manage}{Managing an \ejabberd{} Server} \makesection{ejabberdctl}{\term{ejabberdctl}} @@ -3753,8 +3756,9 @@ The more interesting ones are: \titem{help} Get help about ejabberdctl or any available command. Try \term{ejabberdctl help help}. \titem{status} Check the status of the \ejabberd{} server. \titem{stop} Stop the \ejabberd{} server which is running in the machine. -\titem{reopen-log} If you use a tool to rotate logs, you have to configure it - so that this command is executed after each rotation. +\titem{reopen-log} Reopen the log files after they were renamed. + If the old files were not renamed before calling this command, + they are automatically renamed to \term{"*-old.log"}. See section \ref{logfiles}. \titem {backup, restore, install-fallback, dump, load} You can use these commands to create and restore backups. %%More information about backuping can @@ -3782,7 +3786,7 @@ if a command succedded or failed, for example using: \term{echo \$?} -\makesubsection{erlangconfiguration}{Erlang runtime system} +\makesubsection{erlangconfiguration}{Erlang Runtime System} \ejabberd{} is an Erlang/OTP application that runs inside an Erlang runtime system. This system is configured using environment variables and command line parameters. @@ -4041,7 +4045,7 @@ so the cookie could be read sniffing the traffic on the network. The recommended way to secure the Erlang node is to block the port 4369. -\makesection{nodename}{Erlang node name} +\makesection{nodename}{Erlang Node Name} An Erlang node may have a node name. The name can be short (if indicated with the command-line parameter \term{-sname}) @@ -4056,7 +4060,7 @@ using a modified version of Erlang \term{epmd}. The recommended way to secure the Erlang node is to block the port 4369. -\makesection{secure-files}{Securing sensible files} +\makesection{secure-files}{Securing Sensible Files} \ejabberd{} stores sensible data in the file system either in plain text or binary files. The file system permissions should be set to only allow the proper user to read, @@ -4276,26 +4280,6 @@ The syntax is the following: \makechapter{debugging}{Debugging} \ind{debugging} -\makesection{watchdog}{Watchdog Alerts} -\ind{debugging!watchdog} - -\ejabberd{} includes a watchdog mechanism. -If a process in the \ejabberd{} server consumes too much memory, -a message is sent to the Jabber accounts defined with the option -\term{watchdog\_admins} -\ind{options!watchdog\_admins} in the \ejabberd{} configuration file. -Example configuration: -\begin{verbatim} -{watchdog_admins, ["admin2@localhost", "admin2@example.org"]}. -\end{verbatim} - -To remove watchdog admins, remove them in the option. -To remove all watchdog admins, set the option with an empty list: -\begin{verbatim} -{watchdog_admins, []}. -\end{verbatim} - - \makesection{logfiles}{Log Files} An \ejabberd{} node writes two log files: @@ -4319,6 +4303,13 @@ For example, the default configuration is: {loglevel, 4}. \end{verbatim} +The log files grow continually, so it is recommended to rotate them periodically. +To rotate the log files, rename the files and then reopen them. +The ejabberd command \term{reopen-log} +(please refer to section \ref{commands}) +reopens the log files, +and also renames the old ones if you didn't rename them. + \makesection{debugconsole}{Debug Console} @@ -4333,6 +4324,29 @@ There are some simple and safe examples in the article To exit the shell, close the window or press the keys: control+c control+c. +\makesection{watchdog}{Watchdog Alerts} +\ind{debugging!watchdog} + +\ejabberd{} includes a watchdog mechanism that may be useful to developers +when troubleshooting a problem related to memory usage. +If a process in the \ejabberd{} server consumes a lot of memory, +a message is sent to the Jabber accounts defined with the option +\term{watchdog\_admins} +\ind{options!watchdog\_admins} in the \ejabberd{} configuration file. +Note that the threshold to define what is too much memory usage +is only configurable editing the source code. +Example configuration: +\begin{verbatim} +{watchdog_admins, ["admin2@localhost", "admin2@example.org"]}. +\end{verbatim} + +To remove watchdog admins, remove them in the option. +To remove all watchdog admins, set the option with an empty list: +\begin{verbatim} +{watchdog_admins, []}. +\end{verbatim} + + \appendix{} \makechapter{i18ni10n}{Internationalization and Localization} diff --git a/src/ejabberd.cfg.example b/src/ejabberd.cfg.example index 022a9ebc2..6a6b52494 100644 --- a/src/ejabberd.cfg.example +++ b/src/ejabberd.cfg.example @@ -72,8 +72,9 @@ {loglevel, 4}. %% -%% watchdog_admins: If an ejabberd process consumes too much memory, -%% send live notifications to those Jabber accounts. +%% watchdog_admins: Only useful for developers: if an ejabberd process +%% consumes a lot of memory, send live notifications to these Jabber +%% accounts. %% %%{watchdog_admins, ["bob@example.com"]}. diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index e08765fff..993ac64ce 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -158,8 +158,25 @@ reopen_log() -> ejabberd_hooks:run(reopen_log_hook, []), %% TODO: Use the Reopen log API for logger_h ? ejabberd_logger_h:reopen_log(), + case application:get_env(sasl,sasl_error_logger) of + {ok, {file, SASLfile}} -> + error_logger:delete_report_handler(sasl_report_file_h), + ejabberd_logger_h:rotate_log(SASLfile), + error_logger:add_report_handler(sasl_report_file_h, + {SASLfile, get_sasl_error_logger_type()}); + _ -> false + end, ok. +%% Function copied from Erlang/OTP lib/sasl/src/sasl.erl which doesn't export it +get_sasl_error_logger_type () -> + case application:get_env (sasl, errlog_type) of + {ok, error} -> error; + {ok, progress} -> progress; + {ok, all} -> all; + {ok, Bad} -> exit ({bad_config, {sasl, {errlog_type, Bad}}}); + _ -> all + end. %%% %%% Account management diff --git a/src/ejabberd_logger_h.erl b/src/ejabberd_logger_h.erl index 2e750ca34..e8e6f3baa 100644 --- a/src/ejabberd_logger_h.erl +++ b/src/ejabberd_logger_h.erl @@ -31,7 +31,7 @@ %% gen_event callbacks -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, - code_change/3, reopen_log/0]). + code_change/3, reopen_log/0, rotate_log/1]). -record(state, {fd, file}). @@ -206,10 +206,11 @@ write_time({{Y,Mo,D},{H,Mi,S}}, Type) -> io_lib:format("~n=~s==== ~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w ===~n", [Type, Y, Mo, D, H, Mi, S]). -%% Rename the log file if it the filename exists +%% @doc Rename the log file if exists, to "*-old.log". %% This is needed in systems when the file must be closed before rotation (Windows). %% On most Unix-like system, the file can be renamed from the command line and -%%the log can directly be reopened. +%% the log can directly be reopened. +%% @spec (Filename::string()) -> ok rotate_log(Filename) -> case file:read_file_info(Filename) of {ok, _FileInfo} -> diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 754d947a6..48d2ca061 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -242,60 +242,66 @@ update_database(Host) -> [host_node, host_parent, info] -> ?INFO_MSG("upgrade pubsub tables",[]), F = fun() -> - NewRecords = - lists:foldl( - fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) -> - ItemsList = - lists:foldl( - fun({item, IID, Publisher, Payload}, Acc) -> - C = {Publisher, unknown}, - M = {Publisher, now()}, - mnesia:write( - #pubsub_item{itemid = {IID, NodeId}, - creation = C, - modification = M, - payload = Payload}), - [{Publisher, IID} | Acc] - end, [], Items), - Owners = - dict:fold( - fun(JID, {entity, Aff, Sub}, Acc) -> - UsrItems = - lists:foldl( - fun({P, I}, IAcc) -> - case P of - JID -> [I | IAcc]; - _ -> IAcc - end - end, [], ItemsList), - mnesia:write( - #pubsub_state{stateid = {JID, NodeId}, - items = UsrItems, - affiliation = Aff, - subscription = Sub}), - case Aff of - owner -> [JID | Acc]; - _ -> Acc - end - end, [], Entities), - mnesia:delete({pubsub_node, NodeId}), - [#pubsub_node{nodeid = NodeId, - parentid = ParentId, - owners = Owners, - options = Options} | - RecList] - end, [], - mnesia:match_object( - {pubsub_node, {Host, '_'}, '_', '_'})), - mnesia:delete_table(pubsub_node), - mnesia:create_table(pubsub_node, - [{disc_copies, [node()]}, - {attributes, record_info(fields, pubsub_node)}]), - lists:foreach(fun(Record) -> - mnesia:write(Record) - end, NewRecords) + lists:foldl( + fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) -> + ItemsList = + lists:foldl( + fun({item, IID, Publisher, Payload}, Acc) -> + C = {Publisher, unknown}, + M = {Publisher, now()}, + mnesia:write( + #pubsub_item{itemid = {IID, NodeId}, + creation = C, + modification = M, + payload = Payload}), + [{Publisher, IID} | Acc] + end, [], Items), + Owners = + dict:fold( + fun(JID, {entity, Aff, Sub}, Acc) -> + UsrItems = + lists:foldl( + fun({P, I}, IAcc) -> + case P of + JID -> [I | IAcc]; + _ -> IAcc + end + end, [], ItemsList), + mnesia:write( + #pubsub_state{stateid = {JID, NodeId}, + items = UsrItems, + affiliation = Aff, + subscription = Sub}), + case Aff of + owner -> [JID | Acc]; + _ -> Acc + end + end, [], Entities), + mnesia:delete({pubsub_node, NodeId}), + [#pubsub_node{nodeid = NodeId, + parentid = ParentId, + owners = Owners, + options = Options} | + RecList] + end, [], + mnesia:match_object( + {pubsub_node, {Host, '_'}, '_', '_'})) end, - mnesia:transaction(F); + {atomic, NewRecords} = mnesia:transaction(F), + {atomic, ok} = mnesia:delete_table(pubsub_node), + {atomic, ok} = mnesia:create_table(pubsub_node, + [{disc_copies, [node()]}, + {attributes, record_info(fields, pubsub_node)}]), + FNew = fun() -> lists:foreach(fun(Record) -> + mnesia:write(Record) + end, NewRecords) + end, + case mnesia:transaction(FNew) of + {atomic, Result} -> + ?INFO_MSG("Pubsub tables updated correctly: ~p", [Result]); + {aborted, Reason} -> + ?ERROR_MSG("Problem updating Pubsub tables:~n~p", [Reason]) + end; _ -> ok end.