Skip to content

Commit

Permalink
Fix systemctl commands checking for status
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Donald Kennedy <[email protected]>
  • Loading branch information
grkvlt committed Dec 1, 2021
1 parent 8d8d7f1 commit a4c0a44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
19 changes: 5 additions & 14 deletions catalog/common-types/mysql5.bom
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ brooklyn.catalog:
DB_URL: $brooklyn:config("mysql.url")

install.command: |
MYSQL_CFG=/etc/mysql/mysql.conf.d/
sudo test -d "$MYSQL_CFG" && MYSQL_EXISTS="0"

if [ "$MYSQL_EXISTS" ]; then
if sudo systemctl list-units --full -all | grep -Fq "mysql.service" ; then
echo "MySQL already installed."
else
echo "Installing MySQL."
Expand Down Expand Up @@ -111,14 +108,10 @@ brooklyn.catalog:
fi

customize.command: |
# When MySQL is stopped `systemctl status mysql` returns `Active: inactive (dead)`
# reminder: test for what you expect
sudo systemctl status mysql | grep 'dead' > /dev/null 2>&1
if [ $? != 0 ] ; then
if sudo systemctl show mysql --property=SubState | grep -Fq 'dead' ; then
echo "MySQL is running when configure is called. Skipping configuration assuming it has already been done. If this is not correct then stop the DB before invoking this."
else
echo "Configuring MySQL..."
# When MySQL is up `systemctl status mysql` returns `Active: active (running)`
sudo systemctl start mysql

if [ ! -z "${CREATION_SCRIPT_URL}" ] ; then
Expand All @@ -129,25 +122,23 @@ brooklyn.catalog:
fi

launch.command: |
sudo systemctl status mysql | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
if sudo systemctl show mysql --property=SubState | grep -Fq 'running' ; then
echo "MySQL is up. All is well with the world."
else
echo "MySQL is down. Starting it..."
sudo systemctl start mysql
fi

stop.command: |
sudo systemctl status mysql | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
if sudo systemctl show mysql --property=SubState | grep -Fq 'running' ; then
echo "MySQL is up. Shutting it down..."
sudo systemctl stop mysql
else
echo "MySQL is already down."
fi

checkRunning.command:
sudo /etc/init.d/mysql status | grep -i -e 'active' -e 'uptime'
sudo systemctl show mysql --property=SubState | grep -Fq 'running'

brooklyn.initializers:
- type: org.apache.brooklyn.core.sensor.StaticSensor
Expand Down
11 changes: 4 additions & 7 deletions catalog/common-types/nginx.bom
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ brooklyn.catalog:
sudo apt -y install nginx

customize.command: |
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
if sudo systemctl show nginx --property=SubState | grep -Fq 'running' ; then
echo "NginX is up. All is well with the world..."
else
echo "NginX is down. Starting it..."
Expand Down Expand Up @@ -108,25 +107,23 @@ brooklyn.catalog:
sudo systemctl restart nginx

launch.command: |
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
if sudo systemctl show nginx --property=SubState | grep -Fq 'running' ; then
echo "NginX is up. All is well with the world."
else
echo "NginX is down. Starting it..."
sudo systemctl start nginx
fi

stop.command: |
sudo systemctl status nginx | grep 'running' > /dev/null 2>&1
if [ $? == 0 ]; then
if sudo systemctl show nginx --property=SubState | grep -Fq 'running' ; then
echo "NginX is up. Shutting it down..."
sudo systemctl stop nginx
else
echo "NginX is already down."
fi

checkRunning.command:
sudo systemctl status nginx | grep -i -e 'active' -e 'online'
sudo systemctl show nginx --property=SubState | grep -Fq 'running'

brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.Transformer
Expand Down

0 comments on commit a4c0a44

Please sign in to comment.