Rabbitmq installation and admin user creation - rabbitmq

I am trying to install rabbitmq using a batch file on windows .It installs properly but when i try to create user as administrator ,it executes only first command and then stops.I also tried using "--quiet" argument. Following is my batch file :
cd ../rabbitmq
rabbitmq-server-3.8.3.exe /S /D=%CD%
cd rabbitmq_server-3.8.3/sbin
Please suggest a suitable solution.
rabbitmqctl --quiet add_user test test -> (stops here .doesnt execute next commands)
rabbitmqctl --quiet set_user_tags test administrator
rabbitmqctl --quiet set_permissions -p / test "." "." ".*"
Please suggest a suitable solution. Thanks :)

As we are calling a bat file from another bat file we need to add "CALL" befor each statement.For eg.
CALL rabbitmqctl --quiet add_user test test
CALL rabbitmqctl --quiet set_user_tags test administrator

Related

Why do I have to spawn a new shell when doing remote sudo ssh commands to get proper file permissions?

I'm using password-less key based login with sudo to execute remote commands. I have figured out that I have to spawn a new shell to execute commands that write to root areas of the remote file system. But, I would like a clear explanation of exactly why this is the case?
This fails:
sudo -u joe ssh example.com "sudo echo test > /root/echo_test"
with:
bash: /root/echo_test: Permission denied
This works fine:
sudo -u joe ssh example.com "sudo bash -c 'echo test > /root/echo_test'"
It's the same reason that a local sudo echo test >/root/echo_test will fail (if you are not root) -- the redirection is done by the shell (not the sudo or echo command) which is running as the normal user. sudo only runs the echo command as root.
With sudo -u joe ssh example.com "sudo echo test > /root/echo_test", the remote shell is running as a normal user (probably joe) and does not have permission to write to the file. Using an extra bash invokation works, because sudo then runs bash as root (rather than echo), and that bash can open the file and do the redirect.

How to delete rabbitmq shovels through commandline

I created shovels using ,
rabbitmqctl set_parameter shovel "MyShovel" ......
Now i want to delete it,
Can you please tell me on how to achieve it using commandline.
I tried this and it works more or less instantly:
rabbitmqctl clear_parameter shovel MyShovel
You can also list and delete shovels from the command line using rabbitmqadmin
Listing Shovels command
rabbitmqadmin --host=HOST --port=443 --ssl --vhost=/ --username=USERNAME --password=PASSWORD -f tsv -q list parameters name component
Delete a Shovel command
rabbitmqadmin --host=HOST --port=443 --ssl --vhost=/ --username=USERNAME --password=PASSWORD -f tsv -q delete parameter component=shovel name=nameOfShovel

Within a Docker image, "Slapd stop" succeeds but slapd is still running

I'm trying to create an openLDAP docker image with custom schema, and I would like to have a working LDAP service before modifying it.
I installed slapd and ldap-utils in my docker image, by putting in the dockerfile:
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y slapd ldap-utils
At this point, when I open a bash in a new container, service slapd status or /etc/init.d/slapd status output both "slapd is not running". Indeed, the policy-rc denies the execution of start after the installation of a package.
Well, no problem, service slapd start returns OK and starts the slapd service. I can search in my LDAP, modify it, everything is fine.
The problem comes when I want to restart the slapd service. service slapd restart, or service slapd force-reload or service slapd stop and service slapd start all fail at the "start" comand. The "stop" command returns OK. However, this time, service slapd status returns "slapd is running". Also, I still can search in my LDAP.
To know a bit more about what happened, I tried to start the slapd service with the debug option, as:
slapd -h 'ldap:/// ldapi:///' -g openldap -u openldap -F /etc/ldap/slapd.d -d stats
Unfortunately, this hangs at "slapd starting" and never finishes.
Thanks for any help :)
I have the same issue. When being inside the container the only way I find to stop slapd is pkill slapd
Nevertheless this is not working with Dockerfile and run pkill slapd
I just encountered the same issue in a docker image based on minideb (Debian Buster).
When executing service slapd stop, the stop_slapd shell function of the /etc/init.d/slapd script is invoked, which in turn executes this command:
start-stop-daemon --stop --quiet --oknodo --retry TERM/10 \
--pidfile "/var/run/slapd/slapd.pid" \
--exec /usr/sbin/slapd 2>&1
When you execute this command in a root shell and omit the --quiet flag the following error is shown:
root#4d1b74229670:/# start-stop-daemon --stop --oknodo --retry TERM/10 --pidfile /var/run/slapd/slapd.pid --exec /usr/sbin/slapd
No /usr/sbin/slapd found running; none killed.
The /var/run/slapd/slapd.pid file exists, the /usr/sbin/slapd executable path is correct too and the process is visible like this:
root#4d1b74229670:/# ps -efww | grep slapd
openldap 764 1 0 20:13 ? 00:00:00 /usr/sbin/slapd -h ldap:/// ldapi:/// -g openldap -u openldap -F /etc/ldap/slapd.d
root 779 1 0 20:22 pts/0 00:00:00 grep slapd
To work around this I changed the stop_slapd in /etc/init.d/slapd function and replaced --exec $SLAPD with --name slapd:
stop_slapd() {
reason="`start-stop-daemon --stop --quiet --oknodo --retry TERM/10 \
--pidfile "$SLAPD_PIDFILE" \
--name slapd 2>&1`"
}
I applied the change using sed:
sed -i 's/--exec $SLAPD 2/--name slapd 2/' /etc/init.d/slapd
This is another way to fix the issue:
SLAPD_PID=$(cat /run/slapd/slapd.pid)
kill -15 $SLAPD_PID
while [ -e /proc/$SLAPD_PID ]; do sleep 0.1; done # wait until slapd is terminated

docker rabbitmq hostname issue

I am build an image using Dockerfile, and I would like to add users to RabbitMQ right after installation. The problem is that during build hostname of the docker container is different from when I run the resultant image. RabbitMQ loses that user; because of changed hostname it uses another DB.
I connot change /etc/hosts and /etc/hostname files from inside a container, and looks that RabbitMQ is not picking my changes to RABBITMQ_NODENAME and HOSTNAME variables.
The only thing that I found working is running this before starting RabbitMQ broker:
echo "NODENAME=rabbit#localhost" >> /etc/rabbitmq/rabbitmq.conf.d/ewos.conf
But then I will have to run docker image with changed hostname all the time.
docker run -h="localhost" image
Any ideas on what can be done? Maybe the solution is to add users to RabbitMQ not on build but on image run?
Just here is example how to configure from Dockerfile properly:
ENV HOSTNAME localhost
RUN /etc/init.d/rabbitmq-server start ; rabbitmqctl add_vhost /test; /etc/init.d/rabbitmq-server stop
This is remember your config.
Yes, I would suggest to add users when the container runs for the first time.
Instead of starting RabbitMQ directly, you can run a wrapper script that will take care of all the setup, and then start RabbitMQ. If the last step of the wrapper script is a process start, remember that you can use exec so that the new process replaces the script itself.
This is how I did it.
Dockerfile
FROM debian:jessie
MAINTAINER Francesco Casula <fra.casula#gmail.com>
VOLUME ["/var/www"]
WORKDIR /var/www
ENV HOSTNAME my-docker
ENV RABBITMQ_NODENAME rabbit#my-docker
COPY scripts /root/scripts
RUN /bin/bash /root/scripts/os-setup.bash && \
/bin/bash /root/scripts/install-rabbitmq.bash
CMD /etc/init.d/rabbitmq-server start && \
/bin/bash
os-setup.bash
#!/bin/bash
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 my-docker" >> /etc/hosts
echo "my-docker" > /etc/hostname
install-rabbitmq.bash
#!/bin/bash
echo "NODENAME=rabbit#my-docker" > /etc/rabbitmq/rabbitmq-env.conf
echo 'deb http://www.rabbitmq.com/debian/ testing main' | tee /etc/apt/sources.list.d/rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add -
apt-get update
cd ~
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server_3.6.5-1_all.deb
dpkg -i rabbitmq-server_3.6.5-1_all.deb
apt-get install -f -y
/etc/init.d/rabbitmq-server start
sleep 3
rabbitmq-plugins enable amqp_client mochiweb rabbitmq_management rabbitmq_management_agent \
rabbitmq_management_visualiser rabbitmq_web_dispatch webmachine
rabbitmqctl delete_user guest
rabbitmqctl add_user bunny password
rabbitmqctl set_user_tags bunny administrator
rabbitmqctl delete_vhost /
rabbitmqctl add_vhost symfony_prod
rabbitmqctl set_permissions -p symfony_prod bunny ".*" ".*" ".*"
rabbitmqctl add_vhost symfony_dev
rabbitmqctl set_permissions -p symfony_dev bunny ".*" ".*" ".*"
rabbitmqctl add_vhost symfony_test
rabbitmqctl set_permissions -p symfony_test bunny ".*" ".*" ".*"
/etc/init.d/rabbitmq-server restart
IS_RABBIT_INSTALLED=`rabbitmqctl status | grep RabbitMQ | grep "3\.6\.5" | wc -l`
if [ "$IS_RABBIT_INSTALLED" = "0" ]; then
exit 1
fi
IS_RABBIT_CONFIGURED=`rabbitmqctl list_users | grep bunny | grep "administrator" | wc -l`
if [ "$IS_RABBIT_CONFIGURED" = "0" ]; then
exit 1
fi
Don't forget to run the container by specifying the right host with the -h flag:
docker run -h my-docker -it --name=my-docker -v $(pwd)/htdocs:/var/www my-docker
The only thing that helped me was to change default value in rabbitmq-env.conf of MNESIA_BASE property to MNESIA_BASE=/data and I added this command RUN mkdir /data in Dockerfile before starting server and add users.

How can I switch to the user jenkins in the middle of a ssh script?

I run
ssh root#myhost "sh -x" < myremotecommands.sh
where myremotecommands.sh contains:
#!/bin/sh
sudo su
apt-get update
sudo su -l -p jenkins
whoami
however the command whoami returns 'root'.
I need to be user jenkins to perform some installations.
How can I switch to the user jenkins in the middle of the script ?
You just have to use "su" command with "-s /bin/bash" argument. It´s needed because jenkins user was not supposed to be used interactively, so it doesn´t have the bash defined.
su jenkins -s /bin/bash
After this, the "whoami" command will report you as "jenkins" user.
Use $USER. That will give you the username you logged in as. Whoami returns the user you're currently operating as.
Problem solved:
#!/bin/sh
sudo su
apt-get update
su jenkins <<HERE
whoami
echo usr=$USER
HERE
will output:
jenkins
usr=root
Source:
http://www.daniweb.com/software-development/shell-scripting/threads/14498