Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rabbitmq-setup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Max Drexler
rabbitmq-setup
Commits
c4f59b6c
Commit
c4f59b6c
authored
Feb 12, 2024
by
max-drexler
Browse files
Options
Downloads
Patches
Plain Diff
Dan's suggestions
parent
756f83d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rmq-setup
+15
-21
15 additions, 21 deletions
rmq-setup
with
15 additions
and
21 deletions
rmq-setup
+
15
−
21
View file @
c4f59b6c
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# Sets up a RabbitMQ server's state for the SSEC #
# Sets up a RabbitMQ server's state for the SSEC #
##############################################################################
##############################################################################
trap
"echo Exited!
1
>&2; exit;"
SIGINT SIGTERM
trap
"echo Exited! >&2; exit;"
SIGINT SIGTERM
#############################~Functions~######################################
#############################~Functions~######################################
# $1 = error message, $2 = error code, default = 1
# $1 = error message, $2 = error code, default = 1
...
@@ -22,7 +22,7 @@ err_exit() {
...
@@ -22,7 +22,7 @@ err_exit() {
else
else
CODE
=
$2
CODE
=
$2
fi
fi
echo
"
$MSG
"
1
>&2
echo
"
$MSG
"
>
&2
exit
"
$CODE
"
exit
"
$CODE
"
}
}
...
@@ -44,8 +44,6 @@ usage() {
...
@@ -44,8 +44,6 @@ usage() {
}
}
##########################~Argument Parsing~##################################
##########################~Argument Parsing~##################################
OPTIND
=
1
# Reset in case getopts has been used previously in the shell.
config_file
=
""
config_file
=
""
autorun
=
0
autorun
=
0
no_exchanges
=
0
no_exchanges
=
0
...
@@ -66,22 +64,19 @@ while getopts ":hanr" opt; do
...
@@ -66,22 +64,19 @@ while getopts ":hanr" opt; do
r
)
r
)
restart
=
1
restart
=
1
;;
;;
?
|
*
)
*
)
usage
usage
e
xit
1
e
rr_exit
"Unknown option -
$OPTARG
"
;;
;;
esac
esac
done
done
shift
$((
OPTIND
-
1
))
config_file
=
${
!OPTIND
}
[
"
${
1
:-}
"
=
"--"
]
&&
shift
config_file
=
$1
# Check arguments
# Check arguments
if
[
-z
"
$config_file
"
]
;
then
if
[
$OPTIND
-ne
$#
]
;
then
usage
usage
e
xit
1
e
rr_exit
"Expected config file, got: '
${
*
:OPTIND
}
'"
fi
fi
if
!
[
-f
"
$config_file
"
]
;
then
if
!
[
-f
"
$config_file
"
]
;
then
...
@@ -89,7 +84,7 @@ if ! [ -f "$config_file" ]; then
...
@@ -89,7 +84,7 @@ if ! [ -f "$config_file" ]; then
fi
fi
# load admin and user names and passwords
# load admin and user names and passwords
source
"
$config_file
"
&>/dev/null
source
"
$config_file
"
# Check config file
# Check config file
if
!
[[
-v
ADMIN_PASS
||
-v
ADMIN_NAME
||
-v
USER_NAME
||
-v
USER_PASS
]]
;
then
if
!
[[
-v
ADMIN_PASS
||
-v
ADMIN_NAME
||
-v
USER_NAME
||
-v
USER_PASS
]]
;
then
...
@@ -98,20 +93,20 @@ fi
...
@@ -98,20 +93,20 @@ fi
########################~Check Requirements~################################
########################~Check Requirements~################################
# Check for rabbitmqctl command
# Check for rabbitmqctl command
if
!
command
-v
rabbitmqctl
--version
&
>/dev/null
;
then
if
!
command
-v
rabbitmqctl
--version
>
/dev/null
2>&1
;
then
err_exit
"rabbitmqctl command not found! Is RabbitMQ installed?"
err_exit
"rabbitmqctl command not found! Is RabbitMQ installed?"
fi
fi
if
!
rabbitmqctl status
&
>/dev/null
;
then
if
!
rabbitmqctl status
>
/dev/null
2>&1
;
then
if
[
0
-eq
"
$autorun
"
]
;
then
if
[
0
-eq
"
$autorun
"
]
;
then
err_exit
"RabbitMQ server is not running! Use -a to autostart the server."
err_exit
"RabbitMQ server is not running! Use -a to autostart the server."
else
else
echo
"Attempting to start the RabbitMQ server..."
echo
"Attempting to start the RabbitMQ server..."
rabbitmqctl status
&
>/dev/null
rabbitmqctl status
>
/dev/null
2>&1
case
"
$?
"
in
case
"
$?
"
in
69
)
69
)
echo
"RabbitMQ node is offline, attempting systemctl start rabbitmq-server..."
echo
"RabbitMQ node is offline, attempting systemctl start rabbitmq-server..."
if
!
systemctl start rabbitmq-server
&
>/dev/null
;
then
if
!
systemctl start rabbitmq-server
>
/dev/null
2>&1
;
then
err_exit
"Error trying to start RabbitMQ, systemctl error."
err_exit
"Error trying to start RabbitMQ, systemctl error."
fi
fi
;;
;;
...
@@ -136,9 +131,9 @@ if ! rabbitmq-plugins enable rabbitmq_management; then
...
@@ -136,9 +131,9 @@ if ! rabbitmq-plugins enable rabbitmq_management; then
fi
fi
# Check for rabbitmqadmin (install if not found)
# Check for rabbitmqadmin (install if not found)
if
[
0
-eq
"
$no_exchanges
"
]
&&
!
command
-v
rabbitmqadmin
--version
&
>/dev/null
;
then
if
[
0
-eq
"
$no_exchanges
"
]
&&
!
command
-v
rabbitmqadmin
--version
>
/dev/null
2>&1
;
then
# Check for python
# Check for python
if
!
command
-v
python3
--version
&
>/dev/null
;
then
if
!
command
-v
python3
--version
>
/dev/null
2>&1
;
then
err_exit
"python3 not found! Cannot create exchanges without it. (Use -n to skip creating excahnges)"
err_exit
"python3 not found! Cannot create exchanges without it. (Use -n to skip creating excahnges)"
fi
fi
if
!
python3
-c
"from urllib.request import urlretrieve;urlretrieve('http://
$(
hostname
)
:15672/cli/rabbitmqadmin', '/usr/local/bin/rabbitmqadmin')"
;
then
if
!
python3
-c
"from urllib.request import urlretrieve;urlretrieve('http://
$(
hostname
)
:15672/cli/rabbitmqadmin', '/usr/local/bin/rabbitmqadmin')"
;
then
...
@@ -177,13 +172,12 @@ fi
...
@@ -177,13 +172,12 @@ fi
# Set user permissions:
# Set user permissions:
# Can't configure or edit anything, but can read all default exchanges + model, misc, & satellite
# Can't configure or edit anything, but can read all default exchanges + model, misc, & satellite
rabbitmqctl set_permissions
--vhost
'/'
"
$USER_NAME
"
""
""
"^(model|misc|satellite|amq
\.
gen.*|amq
\.
default)$"
rabbitmqctl set_permissions
"
$USER_NAME
"
""
""
"^(model|misc|satellite|amq
\.
gen.*|amq
\.
default)$"
# Remove default account
# Remove default account
rabbitmqctl delete_user guest
rabbitmqctl delete_user guest
###########################~Set Exchanges~###################################
###########################~Set Exchanges~###################################
if
[
0
-eq
"
$no_exchanges
"
]
;
then
if
[
0
-eq
"
$no_exchanges
"
]
;
then
echo
"Creating exchange 'model'"
echo
"Creating exchange 'model'"
rabbitmqadmin
-u
"
$ADMIN_NAME
"
-p
"
$ADMIN_PASS
"
-V
'/'
declare
exchange
name
=
model
durable
=
true type
=
topic
rabbitmqadmin
-u
"
$ADMIN_NAME
"
-p
"
$ADMIN_PASS
"
-V
'/'
declare
exchange
name
=
model
durable
=
true type
=
topic
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment