Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 332391

Summary: net-misc/rabbitmq-server-1.8.1: Enhanced ebuild and init script (and version bump)
Product: Gentoo Linux Reporter: Stefan Schlott <stefan>
Component: [OLD] ServerAssignee: Benedikt Böhm (RETIRED) <hollow>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on: 334979    
Bug Blocks:    
Attachments: Diff against rabbitmq-server-1.8.0.ebuild
Don't start rabbitmq directly; use su to drop root privileges
Diff against rabbitmq-server-1.8.0.ebuild
Patches for the files directory

Description Stefan Schlott 2010-08-12 06:44:36 UTC
The ebuild creates a user and a group for the server, but the init script runs it as root.

Reproducible: Always

Steps to Reproduce:
As root:
1. /etc/init.d/rabbitmq start
2. ps aux | grep rabbit
Actual Results:  
rabbitmq is running as root

Expected Results:  
rabbitmq should be running as unprivileged user "rabbitmq"

The rabbitmq user needs a writeable home directory; Erlang tries to create a so-called cookie file (for ipc, I suppose) there.
Comment 1 Stefan Schlott 2010-08-12 06:48:36 UTC
Created attachment 242529 [details, diff]
Diff against rabbitmq-server-1.8.0.ebuild

Path will do two things:
- create rabbitmq user with shell and writable home directory
- install man pages
Comment 2 Stefan Schlott 2010-08-12 06:50:32 UTC
Created attachment 242531 [details, diff]
Don't start rabbitmq directly; use su to drop root privileges

Patch against net-misc/rabbitmq-server/files/rabbitmq-server.init
Comment 3 Benedikt Böhm (RETIRED) gentoo-dev 2010-08-12 12:47:41 UTC
(In reply to comment #2)
> Created an attachment (id=242531) [details]
> Don't start rabbitmq directly; use su to drop root privileges
> 
> Patch against net-misc/rabbitmq-server/files/rabbitmq-server.init

the su approach is really ugly. can you try to make rabbitmq work with start-stop-daemon?
Comment 4 Stefan Schlott 2010-08-13 07:31:04 UTC
start-stop-daemon is a bit tricky, because only a process name of the Erlang runtime is visible. But, well, here we go...

Added some more features:
- Config file for rabbitmq environment variables
- Empty directory /etc/rabbitmq - the default directory for holding the cluster config file
- Man page installation
- Proper stopping of Erlang port mapper

I'll attach a diff against the 1.8.0 ebuild and second diff for the files directory (I had to create two new files).
Comment 5 Stefan Schlott 2010-08-13 07:32:22 UTC
Created attachment 242721 [details, diff]
Diff against rabbitmq-server-1.8.0.ebuild

Second version, see comment 4
Comment 6 Stefan Schlott 2010-08-13 07:32:53 UTC
Created attachment 242723 [details, diff]
Patches for the files directory

Second version, see comment 4
Comment 7 Stefan Schlott 2010-08-13 07:33:31 UTC
Comment on attachment 242529 [details, diff]
Diff against rabbitmq-server-1.8.0.ebuild

Obsoleted by update, see comment 4
Comment 8 Stefan Schlott 2010-08-13 07:33:40 UTC
Comment on attachment 242531 [details, diff]
Don't start rabbitmq directly; use su to drop root privileges

Obsoleted by update, see comment 4
Comment 9 Benedikt Böhm (RETIRED) gentoo-dev 2010-08-13 08:48:34 UTC
i have tried your init script, but it does not work (at least on baselayout-2/openrc):


# /etc/init.d/rabbitmq start
 * Starting RabbitMQ... ...
usage: epmd [-d|-debug] [DbgExtra...] [-port No] [-daemon]
            [-d|-debug] [-port No] [-names|-kill]

See the Erlang epmd manual page for info about the usage.
The -port and DbgExtra options are

    -port No
        Let epmd listen to another port than default 4369
    -d
    -debug
        Enable debugging. This will give a log to
        the standard error stream. It will shorten
        the number of saved used node names to 5.

        If you give more than one debug flag you may
        get more debugging information.

    -packet_timout Seconds
        Set the number of seconds a connection can be
        inactive before epmd times out and closes the
        connection (default 60).

    -delay_accept Seconds
        To simulate a busy server you can insert a
        delay between epmd gets notified about that
        a new connection is requested and when the
        connections gets accepted.

    -delay_write Seconds
        Also a simulation of a busy server. Inserts
        a delay before a reply is sent.
 * start-stop-daemon: failed to start `/usr/lib/erlang/bin/epmd' [ !! ]
 * ERROR: rabbitmq failed to start


i've looked at upstreams init script, and it does not seem to support running as user rabbitmq either. i've tried to make it work with openrcs start-stop-daemon, but i cannot seem to make it work. i've also noticed that epmd is being run as rabbitmq too, which may not be a good idea if multiple erlang applications are running, but i'm no erlang expert ...
Comment 10 Stefan Schlott 2010-08-13 09:06:48 UTC
(In reply to comment #9)
> i have tried your init script, but it does not work (at least on
> baselayout-2/openrc):
> 
> # /etc/init.d/rabbitmq start
>  * Starting RabbitMQ... ...
> usage: epmd [-d|-debug] [DbgExtra...] [-port No] [-daemon]
>             [-d|-debug] [-port No] [-names|-kill]

Since I don't start epmd myself, I suspect this might be an issue with rabbitmq's startup scripts. Since I can't reproduce the problem, it's up to you to find out what's going wrong :-) Try finding the location where the problem occurs (bash -x...).

Regarding starting epmd: Erlang starts the daemon automatically on demand. So perhaps shutting it down when terminating rabbitmq is not 100% correct... if you consider installations with several Erlang nodes per machine, a separate start script would be the clean solution (which should live in the Erlang package). My guess is that this is a rather obscure situation (otherwise, Erlang wouldn't start the daemon by itself), though.
Comment 11 Benedikt Böhm (RETIRED) gentoo-dev 2010-08-28 14:34:24 UTC
i've copied debians rabbitmq-script-wrapper, which basically uses the same su approach you had in the beginning. anything else seems to be a waste of time to debug. thanks!

as soon as bug 334979 is fixed, the rabbitmq init script will use epmd as dependency too.