]> granicus.if.org Git - ejabberd/commitdiff
Write PID file, path is configurable in ejabberdctl.cfg (EJAB-1023)
authorBadlop <badlop@process-one.net>
Mon, 24 Aug 2009 21:21:04 +0000 (21:21 +0000)
committerBadlop <badlop@process-one.net>
Mon, 24 Aug 2009 21:21:04 +0000 (21:21 +0000)
SVN Revision: 2526

doc/guide.html
doc/guide.tex
src/ejabberd.erl
src/ejabberd_app.erl
src/ejabberdctl.cfg.example
src/ejabberdctl.template

index 350964fac1c3c9021342b646ad36086456f754df..ef6d24757d2e489bbecf5eb187f1a6f094d93ce9 100644 (file)
@@ -3378,6 +3378,8 @@ all the environment variables and command line parameters.</P><P>The environment
        Path to the directory with binary system libraries.
 </DD><DT CLASS="dt-description"><B><TT>EJABBERD_DOC_PATH</TT></B></DT><DD CLASS="dd-description">
        Path to the directory with ejabberd documentation.
+</DD><DT CLASS="dt-description"><B><TT>EJABBERD_PID_PATH</TT></B></DT><DD CLASS="dd-description">
+       Path to the PID file that ejabberd can create when started.
 </DD><DT CLASS="dt-description"><B><TT>HOME</TT></B></DT><DD CLASS="dd-description">
        Path to the directory that is considered <TT>ejabberd</TT>&#X2019;s home.
        This path is used to read the file <TT>.erlang.cookie</TT>.
index 924ad247864d0601db0c6863b83fa5af7e1ca575..8d4f257a4cdc64999458f0ff44b01c2938002e30 100644 (file)
@@ -4327,6 +4327,8 @@ The environment variables:
        Path to the directory with binary system libraries.
   \titem{EJABBERD\_DOC\_PATH}
        Path to the directory with ejabberd documentation.
+  \titem{EJABBERD\_PID\_PATH}
+       Path to the PID file that ejabberd can create when started.
   \titem{HOME}
        Path to the directory that is considered \ejabberd{}'s home.
        This path is used to read the file \term{.erlang.cookie}.
index 0c7c56a2a10f165f48eefd947495ced38a23adba..228614b93f1515b2963c93ee7851ac2916f8e9f1 100644 (file)
@@ -28,6 +28,7 @@
 -author('alexey@process-one.net').
 
 -export([start/0, stop/0,
+        get_pid_file/0,
         get_so_path/0, get_bin_path/0]).
 
 start() ->
@@ -63,3 +64,14 @@ get_bin_path() ->
        Path ->
            Path
     end.
+
+%% @spec () -> false | string()
+get_pid_file() ->
+    case os:getenv("EJABBERD_PID_PATH") of
+       false ->
+           false;
+       "" ->
+           false;
+       Path ->
+           Path
+    end.
index 80e8ca76602e92040ba8ccaf4ccf52b42ce7d7a6..8c97394c20f8ab741d9f23322e6177f812879b70 100644 (file)
@@ -40,6 +40,7 @@
 
 start(normal, _Args) ->
     ejabberd_loglevel:set(4),
+    write_pid_file(),
     application:start(sasl),
     randoms:start(),
     db_init(),
@@ -81,6 +82,7 @@ prep_stop(State) ->
 %% All the processes were killed when this function is called
 stop(_State) ->
     ?INFO_MSG("ejabberd ~s is stopped in the node ~p", [?VERSION, node()]),
+    delete_pid_file(),
     ejabberd_debug:stop(),
     ok.
 
@@ -194,3 +196,34 @@ add_windows_nameservers() ->
     IPTs = win32_dns:get_nameservers(),
     ?INFO_MSG("Adding machine's DNS IPs to Erlang system:~n~p", [IPTs]),
     lists:foreach(fun(IPT) -> inet_db:add_ns(IPT) end, IPTs).
+
+
+%%%
+%%% PID file
+%%%
+
+write_pid_file() ->
+    case ejabberd:get_pid_file() of
+       false ->
+           ok;
+       PidFilename ->
+           write_pid_file(os:getpid(), PidFilename)
+    end.
+
+write_pid_file(Pid, PidFilename) ->
+    case file:open(PidFilename, [write]) of
+       {ok, Fd} ->
+           io:format(Fd, "~s~n", [Pid]),
+           file:close(Fd);
+       {error, Reason} ->
+           ?ERROR_MSG("Cannot write PID file ~s~nReason: ~p", [PidFilename, Reason]),
+           throw({cannot_write_pid_file, PidFilename, Reason})
+    end.
+
+delete_pid_file() ->
+    case ejabberd:get_pid_file() of
+       false ->
+           ok;
+       PidFilename ->
+           file:delete(PidFilename)
+    end.
index 0c8d0c5a6bafc3b149a37633fae4ae4927e12801..1ba413fe25270e53f9d160bb841fbad9564da225 100644 (file)
 #
 #ERLANG_NODE=ejabberd
 
+#.
+#' EJABBERD_PID_PATH: ejabberd PID file
+#
+# Indicate the full path to the ejabberd Process identifier (PID) file.
+# If this variable is defined, ejabberd writes the PID file when starts,
+# and deletes it when stops.
+# Remember to create the directory and grant write permission to ejabberd.
+#
+# Default: don't write PID file
+#
+#EJABBERD_PID_PATH=/var/run/ejabberd/ejabberd.pid
+
 #.
 #'
 # vim: foldmarker=#',#. foldmethod=marker:
index f6a30bb09143403162bb8486c4b5bd23602c731a..48a56ba5b19dc4dab8df55d256113fe7ab2d14b5 100644 (file)
@@ -118,6 +118,7 @@ export EJABBERD_LOG_PATH
 export EJABBERD_SO_PATH
 export EJABBERD_BIN_PATH
 export EJABBERD_DOC_PATH
+export EJABBERD_PID_PATH
 export ERL_CRASH_DUMP
 export ERL_INETRC
 export ERL_MAX_PORTS