Commit Graph

35 Commits

Author SHA1 Message Date
Loïc Hoguin fb985bb8b9
Fix the CLI's main module on Windows 2025-03-26 16:32:38 +01:00
Michael Klishin 28602bea37
scripts/rabbitmqctl: allow standard input reads for 'import_definitions'
It was not listed in 7da7d4e1e, even though the command
accepts definitions via standard input.

References #10268.
Closes #13157.
2025-01-26 18:36:08 -05:00
Michael Klishin 968eefa1bb
Bump (c) line year
There are no functional changes to this massive diff.
2025-01-01 17:54:10 -05:00
Michal Kuratczyk 72dc78fd31
Fix accepting input from the CLI (#11060)
Follow-up to https://github.com/rabbitmq/rabbitmq-server/pull/10268.

There were still cases where input was ignored, eg.
`rabbitmq-diagnostics -n node observer`
2024-04-23 08:56:10 +02:00
Luke Bakken 8ba0562149 No need for `|| exit "$?"`
Follow-up to #10819

@dumbbell made a note that the `|| exit "$?"` code is probably redundant.

@lukebakken tested this patch using the RMQ docker image and `dash`, and
the test procedure provided by @giner here:

https://github.com/rabbitmq/rabbitmq-server/pull/10819#issuecomment-2014141937

```sh
mkdir ~/ubuntu_24.04
vagrant init ubuntu/noble64
cd ~/ubuntu_24.04
vagrant up
vagrant ssh

sudo apt update
sudo apt install docker.io
newgrp docker

mkdir -p /tmp/rabbitmq
cd /tmp/rabbitmq
cat > Dockerfile << 'EOF'
from "rabbitmq"
RUN sed -i 's/wait "\$rabbitmq_server_pid" || true/wait "$rabbitmq_server_pid" || (exit "$?")/g' "$(which rabbitmq-server)"
EOF
docker build -t rabbitmq-test-script .

docker rm -f rabbitmq-orig 2>/dev/null
docker run --restart on-failure -d --name rabbitmq-orig rabbitmq

docker rm -f rabbitmq-test-script 2>/dev/null
docker run --restart on-failure -d --name rabbitmq-test-script rabbitmq-test-script

sleep 5
docker exec rabbitmq-orig /bin/sh -c 'kill -USR2 $(pidof beam.smp)'
docker exec rabbitmq-test-script /bin/sh -c 'kill -USR2 $(pidof beam.smp)'

sleep 5
echo
echo "*** rabbitmq-orig ***"
docker logs rabbitmq-orig 2>&1 | grep "User defined signal\|Starting RabbitMQ"
echo
echo "*** rabbitmq-test-script ***"
docker logs rabbitmq-test-script 2>&1 | grep "User defined signal\|Starting RabbitMQ"
echo
docker ps -a

```
2024-04-11 15:07:37 -04:00
Stanislav German-Evtushenko 0263b4cdfe Update deps/rabbit/scripts/rabbitmq-server
Co-authored-by: Luke Bakken <lukerbakken@gmail.com>
2024-04-09 14:56:50 -07:00
Stanislav German-Evtushenko c87f0e9c20 Update deps/rabbit/scripts/rabbitmq-server
Co-authored-by: Luke Bakken <lukerbakken@gmail.com>
2024-04-09 14:56:50 -07:00
Stanislav German-Evtushenko a80ebff1bf rabbitmq-server: Propagate exit code
Exit code is useful for monitoring and process supervisors when it comes
to deciding on what to do when the process exits, for example we may
want to restart it or send a report. The current implementation of
`rabbitmq-server` script does not propagate the exit code in a general
case which makes it impossible to know whether the exit was clean and,
for example, use restart policy `on-failure` in docker.

This change makes the exit code to be propagated.
2024-04-09 14:56:50 -07:00
Michael Klishin f414c2d512
More missed license header updates #9969 2024-02-05 11:53:50 -05:00
Luke Bakken 7da7d4e1e7
Ensure `-noinput` is applied correctly
Follow-up to:
* #10131
* #10257

The following `rabbitmqctl` commands may require `stdin` input:
* `add_user`
* `authenticate_user`
* `change_password`
* `decode`
* `encode`
* `eval`
* `hash_password`

The following `rabbitmq-diagnostics` commands may require `stdin` input:
* `observer`
* `remote_shell`
2024-01-02 13:40:00 -08:00
Luke Bakken 3f33dfa227
Add -noinput via `rabbitmq-env`
Follow-up to #10131
2023-12-30 16:27:02 -08:00
Luke Bakken cb28ffc05b
Ensure that elixir escript does not read from stdin
This change ensures that you do not have to redirect `stdin` from
`/dev/null` to use `rabbitmqctl` and related utilities in a `while` /
`read` shell loop.

References:
* https://github.com/lukebakken/vesc-1073/blob/main/delete.bash#L24-L32
* https://github.com/rabbitmq/support-tools/pull/38
2023-12-14 06:13:56 -08:00
Michael Klishin 1b642353ca
Update (c) according to [1]
1. https://investors.broadcom.com/news-releases/news-release-details/broadcom-and-vmware-intend-close-transaction-november-22-2023
2023-11-21 23:18:22 -05:00
David Ansari c914e43097 Do not enable OTP feature at runtime
Since Erlang/OTP 26:
```
OTP-18445
Application(s):
erts, stdlib
It is no longer necessary to enable a feature in the runtime system in order to load modules that are using it.
It is sufficient to enable the feature in the compiler when compiling it.
That means that to use feature maybe_expr in Erlang/OTP 26, it is sufficient to enable it during compilation.
In Erlang/OTP 27, feature maybe_expr will be enabled by default, but it will be possible to disable it.
```
2023-10-27 09:26:31 +02:00
Luke Bakken 057f9460d7
Allow several env variables to be set in rabbitmq-env-conf.bat
Fixes #9258

This patch allows the following variables to be set by `rabbitmq-env-conf.bat`:

* `LOG_BASE`
* `MNESIA_BASE`
* `CONFIG_FILE`
2023-09-03 09:39:47 -07:00
Luke Bakken 96c3560986
Fix remote_shell on win32
This command requires werl.exe. In OTP 26, this will still work because werl.exe is the same as erl.exe
2023-02-27 08:49:58 -08:00
Rin Kuryloski 609171ec70 Rename the tanzu cli scope to vmware
And update other references to commercial editions
2023-02-16 13:49:54 +01:00
David Ansari 79c12b60bc Use maybe expression instead of messy patterns
This commit is pure refactoring making the code base more maintainable.

Replace rabbit_misc:pipeline/3 with the new OTP 25 experimental maybe
expression because
"Frequent ways in which people work with sequences of failable
operations include folds over lists of functions, and abusing list
comprehensions. Both patterns have heavy weaknesses that makes them less
than ideal."
https://www.erlang.org/eeps/eep-0049#obsoleting-messy-patterns

Additionally, this commit is more restrictive in the type spec of
rabbit_mqtt_processor state fields.
Specifically, many fields were defined to be `undefined | T` where
`undefined` was only temporarily until the first CONNECT packet was
processed by the processor.
It's better to initialise the MQTT processor upon first CONNECT packet
because there is no point in having a processor without having received
any packet.
This allows many type specs in the processor to change from `undefined |
T` to just `T`.
Additionally, memory is saved by removing the `received_connect_packet`
field from the `rabbit_mqtt_reader` and `rabbit_web_mqtt_handler`.
2023-02-07 16:36:08 +01:00
Michael Klishin ec4f1dba7d
(c) year bump: 2022 => 2023 2023-01-01 23:17:36 -05:00
Luke Bakken f53f379217
Add +pc unicode to `erl` args - https://www.erlang.org/doc/apps/stdlib/unicode_usage.html#heuristic-string-detection 2022-10-10 10:32:07 +04:00
Luke Bakken 28d6b19bfb
Set ERL_MAX_ETS_TABLES and ERL_MAX_PORTS in the same manner as on Windows
See discussion here: https://github.com/docker-library/rabbitmq/issues/545
2022-08-30 15:31:43 -07:00
David Ansari fba455c61c Revert "Set kernel param prevent_overlapping_partitions to true"
This reverts commit 8070344a38.

We learnt during the last 6 days on master branch that RabbitMQ
- as of today - is not compatible with kernel parameter
`prevent_overlapping_partitions` set to `true`.

RabbitMQ explicitly disconnects node in at least two places:
1. rabbit_node_monitor to "promote" a partial network partition
to a full partition, and
2. rabbit_mnesia after a node reset to disconnect it from the
rest of the cluster.
There is no atomicity in the way we disconnect several nodes,
because it's a simple loop. Therefore, remote nodes may/will detect
disconnection at different times obviously. In global's new
behavior behind prevent_overlapping_partitions, our attempt to
disconnect all nodes in rabbit_mnesia creates a partial network
partition from global's point of view, leading to a complete
disconnection of the cluster.

For example, test
```
make ct-clustering_management t=cluster_size_3:join_and_part_cluster
```
was flaky and demonstrates the 2nd bullet point above where RabbitMQ
interfering with Erlang distribution conflicts with global's
prevent_overlapping_partitions.
When RabbitMQ resets a node, its last step is to loop over
clustered nodes and disconnect from them one at a time.
In this test with a 3-node cluster where we reset node A:
1. Node A instructs node B and C to remove node A from their view
   of the cluster
2. Node A disconnects from node B
3. global on node B get a nodedow event for node A, but node C is
   still connected to node A
4. global on node B concludes there is a network partition and
   disconnect from node A and node C
At this point, each node is on its own.
Nothing in RabbitMQ tries to restore the connection between
nodes B and C.

The correct path forward is:
1. Get rid of Mnesia replacing it with Khepri.
2. Once mirrored classic queues are removed, get rid of rabbit_node_monitor.
3. Have a clear and consistent view of the nodes comprising a RabbitMQ Cluster:
   In other words, do not use different sources of truths like nodes(),
   Mnesia, Ra clusters, global monitor at different places in the code.

For the time being we live with `prevent_overlapping_partitions` set to `false`
and with the workaround for global:sync/0 being stuck introduced in
9fcb31f348
2022-08-10 17:07:30 +00:00
David Ansari 8070344a38 Set kernel param prevent_overlapping_partitions to true
This kernel parameter got introduced in Erlang 24.3.
It is set to `false` by default in Erlang 24.
It is set to `true` by default in Erlang 25.

This commit requires Erlang >= 24.3.

As described in commit message
4bf78d822d
setting this flag to `true` will prevent global:sync/0 from hanging
in the presence of network failures.

Instead of relying on our own workaround of global:sync/0 being stuck
introduced in
9fcb31f348
let us instead rely on the official Erlang fix that comes by setting
prevent_overloapping_partitions to true.
2022-08-08 06:41:09 +00:00
Michael Klishin 7c47d0925a
Revert "Correct a double quote introduced in #4603"
This reverts commit 6a44e0e2ef.

That wiped a lot of files unintentionally
2022-04-20 16:05:56 +04:00
Michael Klishin 6a44e0e2ef
Correct a double quote introduced in #4603 2022-04-20 16:01:29 +04:00
Michael Klishin c38a3d697d
Bump (c) year 2022-03-21 01:21:56 +04:00
Michael Klishin 5c7b714b6e
Disable kernel.prevent_overlapping_parititions in rabbitmq-service.bat 2022-03-10 13:10:03 +04:00
Michael Klishin bcb3145a2f
Disable kernel.prevent_overlapping_partitions at VM startup time 2022-03-10 13:05:27 +04:00
Michael Klishin f7d32d69f8 Introduce a new CLI tool (scope), rabbitmq-tanzu
For Tanzu (commercial) plugins to attach their commands to instead of
polluting rabbitmqctl.

Pair: @pjk25
(cherry picked from commit 6e0f2436fa)
2021-11-30 14:54:09 +00:00
Michael Klishin 040f8cc912
Replace a few more leftover MPLv1.1 license headers
Most files have been using the MPLv2 headers for months now.
These were detected by the OSL process.
2021-05-19 21:20:47 +03:00
Jean-Sébastien Pédron cdcf602749
Switch from Lager to the new Erlang Logger API for logging
The configuration remains the same for the end-user. The only exception
is the log root directory: it is now set through the `log_root`
application env. variable in `rabbit`. People using the Cuttlefish-based
configuration file are not affected by this exception.

The main change is how the logging facility is configured. It now
happens in `rabbit_prelaunch_logging`. The `rabbit_lager` module is
removed.

The supported outputs remain the same: the console, text files, the
`amq.rabbitmq.log` exchange and syslog.

The message text format slightly changed: the timestamp is more precise
(now to the microsecond) and the level can be abbreviated to always be
4-character long to align all messages and improve readability. Here is
an example:

    2021-03-03 10:22:30.377392+01:00 [dbug] <0.229.0> == Prelaunch DONE ==
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>  Starting RabbitMQ 3.8.10+115.g071f3fb on Erlang 23.2.5
    2021-03-03 10:22:30.377860+01:00 [info] <0.229.0>  Licensed under the MPL 2.0. Website: https://rabbitmq.com

The example above also shows that multiline messages are supported and
each line is prepended with the same prefix (the timestamp, the level
and the Erlang process PID).

JSON is also supported as a message format and now for any outputs.
Indeed, it is possible to use it with e.g. syslog or the exchange. Here
is an example of a JSON-formatted message sent to syslog:

    Mar  3 11:23:06 localhost rabbitmq-server[27908] <0.229.0> - {"time":"2021-03-03T11:23:06.998466+01:00","level":"notice","msg":"Logging: configured log handlers are now ACTIVE","meta":{"domain":"rabbitmq.prelaunch","file":"src/rabbit_prelaunch_logging.erl","gl":"<0.228.0>","line":311,"mfa":["rabbit_prelaunch_logging","configure_logger",1],"pid":"<0.229.0>"}}

For quick testing, the values accepted by the `$RABBITMQ_LOGS`
environment variables were extended:
  * `-` still means stdout
  * `-stderr` means stderr
  * `syslog:` means syslog on localhost
  * `exchange:` means logging to `amq.rabbitmq.log`

`$RABBITMQ_LOG` was also extended. It now accepts a `+json` modifier (in
addition to the existing `+color` one). With that modifier, messages are
formatted as JSON intead of plain text.

The `rabbitmqctl rotate_logs` command is deprecated. The reason is
Logger does not expose a function to force log rotation. However, it
will detect when a file was rotated by an external tool.

From a developer point of view, the old `rabbit_log*` API remains
supported, though it is now deprecated. It is implemented as regular
modules: there is no `parse_transform` involved anymore.

In the code, it is recommended to use the new Logger macros. For
instance, `?LOG_INFO(Format, Args)`. If possible, messages should be
augmented with some metadata. For instance (note the map after the
message):

    ?LOG_NOTICE("Logging: switching to configured handler(s); following "
                "messages may not be visible in this log output",
                #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),

Domains in Erlang Logger parlance are the way to categorize messages.
Some predefined domains, matching previous categories, are currently
defined in `rabbit_common/include/logging.hrl` or headers in the
relevant plugins for plugin-specific categories.

At this point, very few messages have been converted from the old
`rabbit_log*` API to the new macros. It can be done gradually when
working on a particular module or logging.

The Erlang builtin console/file handler, `logger_std_h`, has been forked
because it lacks date-based file rotation. The configuration of
date-based rotation is identical to Lager. Once the dust has settled for
this feature, the goal is to submit it upstream for inclusion in Erlang.
The forked module is calld `rabbit_logger_std_h` and is based
`logger_std_h` in Erlang 23.0.
2021-03-11 15:17:36 +01:00
Carl Hörberg 413bfe7b37 Disable Erlang busy wait by default
By disabling Erlang busy wait threshold CPU usage with 5000 idle connection
drops from 110% to 14%. Throughput does not seem to be affected at all,
if any thing it actually goes up a bit when you have 5000 idle connections
(because less CPU cycles are wasted polling idle connections).

rabbitmq-perf-test-2.13.0/bin/runjava com.rabbitmq.perf.PerfTest -s 8000 -z 15

With default erlang busy wait threshold:
id: test-115706-497, sending rate avg: 39589 msg/s
id: test-115706-497, receiving rate avg: 39570 msg/s

With busy wait disabled:
id: test-115807-719, sending rate avg: 40340 msg/s
id: test-115807-719, receiving rate avg: 40301 msg/s

rabbitmq-diagnostics runtime_thread_stats output while running the
PerfTest:

with default busy wait threshold:

Stats per type:
         async    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
           aux    0.01%    0.00%    0.00%    0.00%    0.00%    0.00%   99.98%
dirty_cpu_sche    0.00%    0.00%    0.00%    0.03%    0.05%    0.00%   99.92%
dirty_io_sched    0.00%    0.00%    0.00%    0.00%    0.01%    0.00%   99.99%
          poll    0.00%    0.67%    0.00%    0.00%    0.00%    0.00%   99.33%
     scheduler    0.69%    0.18%   28.41%    5.49%    9.50%    7.43%   48.29%

without busy wait threshold:

Stats per type:
         async    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
           aux    0.01%    0.00%    0.00%    0.00%    0.01%    0.00%   99.98%
dirty_cpu_sche    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
dirty_io_sched    0.00%    0.00%    0.00%    0.00%    0.00%    0.00%  100.00%
          poll    0.00%    0.77%    0.00%    0.00%    0.00%    0.00%   99.23%
     scheduler    0.70%    0.14%   28.29%    5.41%    0.86%    7.22%   57.38%
2021-02-10 12:35:12 +01:00
Luke Bakken 7a3bd539d3
Pass RABBITMQ_NODENAME via Windows service environment
Without this change using anything other than `rabbit` or the `rabbitmq-env-conf.bat` file will result in `erlang_dist_running_with_unexpected_nodename`

Follow-up to #2673

cc @dumbbell @michaelklishin
2020-12-07 12:03:06 -08:00
Lajos Gerecs 8fdbc222e3 allow configuring multiple rmq bases for multiple services
Currently RABBITMQ_BASE is always dynamically picked up from the
environment. This change would fix it at the time of configuration
of the service allowing multiple RabbitMQ services to be configured.
2020-12-05 22:13:00 +01:00
Philip Kuryloski a1fe3ab061 Change repo "root" to deps/rabbit
rabbit must not be the monorepo root application, as other applications depend on it
2020-11-13 14:34:42 +01:00