Skip to content

Commit 8da3eee

Browse files
committed
refactor: standardize ghost and mysql docker modules
Refactor Ghost and MySQL modules to match uptime-kuma structure: - Use docker.io instead of docker-ce - Move container/image queries to top with proper docker filters - Remove redundant queries in each case block - Add error suppression to docker commands - Fix image query to use proper name:tag format - Improve variable quoting throughout - Add container startup wait loops - Remove unnecessary docker pull steps For Ghost module specifically: - Fix purge command "page not found" error - Use full image tag (ghost:6) instead of just ID - Suppress output in remove/purge commands Signed-off-by: Igor Pecovnik <igor@armbian.com>
1 parent 9ae22c5 commit 8da3eee

File tree

3 files changed

+96
-87
lines changed

3 files changed

+96
-87
lines changed

tests/ghost.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ENABLED=true
2+
RELEASE="noble"
3+
TESTNAME="Ghost install"
4+
5+
testcase() {(
6+
set -e
7+
./bin/armbian-config --api module_ghost purge
8+
./bin/armbian-config --api module_ghost install
9+
./bin/armbian-config --api module_ghost status
10+
)}

tools/modules/software/module_ghost.sh

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,91 +18,94 @@ function module_ghost () {
1818
local title="ghost"
1919
local condition=$(which "$title" 2>/dev/null)
2020

21-
if pkg_installed docker-ce; then
22-
local container=$(docker container ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1}')
23-
local image=$(docker image ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}')
24-
fi
25-
26-
GHOST_BASE="${SOFTWARE_FOLDER}/ghost"
21+
pkg_installed docker.io || module_docker install
22+
local container=$(docker container ls -a --filter "name=ghost" --format '{{.ID}}')
23+
local image=$(docker image ls -a --format '{{.Repository}}:{{.Tag}}' | grep '^ghost:' | head -1)
2724

2825
local commands
2926
IFS=' ' read -r -a commands <<< "${module_options["module_ghost,example"]}"
3027

31-
case $1 in
32-
"${commands[0]}")
28+
GHOST_BASE="${SOFTWARE_FOLDER}/ghost"
3329

34-
# instatall mysql if not installed
35-
if ! module_mysql status; then
36-
module_mysql install
37-
fi
30+
case "$1" in
31+
"${commands[0]}")
32+
# Install mysql if not installed
33+
if ! module_mysql status; then
34+
module_mysql install
35+
fi
36+
37+
# Exit if ghost is already running
38+
if [[ "${container}" && "${image}" ]]; then
39+
echo "Ghost container is already installed and running."
40+
exit 0
41+
fi
3842

39-
# exit if ghost is already running
40-
if module_ghost status; then
41-
exit 0
42-
fi
43+
MYSQL_USER="${2:-armbian}"
44+
MYSQL_PASSWORD="${3:-armbian}"
4345

44-
MYSQL_USER="${2:-armbian}"
45-
MYSQL_PASSWORD="${3:-armbian}"
46+
[[ -d "$GHOST_BASE" ]] || mkdir -p "$GHOST_BASE" || { echo "Couldn't create storage directory: $GHOST_BASE"; exit 1; }
47+
docker run -d \
48+
--name ghost \
49+
--net=lsio \
50+
--restart unless-stopped \
51+
-e database__client=mysql \
52+
-e database__connection__host="mysql" \
53+
-e database__connection__user="${MYSQL_USER}" \
54+
-e database__connection__password="${MYSQL_PASSWORD}" \
55+
-e database__connection__database="ghost" \
56+
-p "${module_options["module_ghost,port"]}:2368" \
57+
-e url="http://$LOCALIPADD:${module_options["module_ghost,port"]}" \
58+
-v "$GHOST_BASE:/var/lib/ghost/content" \
59+
ghost:6
4660

47-
[[ -d "$GHOST_BASE" ]] || mkdir -p "$GHOST_BASE" || { echo "Couldn't create storage directory: $GHOST_BASE"; exit 1; }
48-
docker pull ghost:5-alpine
49-
docker run -d \
50-
--name ghost \
51-
--net=lsio \
52-
--restart unless-stopped \
53-
-e database__client=mysql \
54-
-e database__connection__host="mysql" \
55-
-e database__connection__user="${MYSQL_USER}" \
56-
-e database__connection__password="${MYSQL_PASSWORD}" \
57-
-e database__connection__database="ghost" \
58-
-p ${module_options["module_ghost,port"]}:2368 \
59-
-e url=http://$LOCALIPADD:${module_options["module_ghost,port"]} \
60-
-v "$GHOST_BASE:/var/lib/ghost/content" \
61-
ghost:6
61+
# Wait for container to start
62+
for i in $(seq 1 20); do
63+
state="$(docker inspect -f '{{.State.Status}}' ghost 2>/dev/null || true)"
64+
if [[ "$state" == "running" ]]; then
65+
break
66+
fi
67+
sleep 3
68+
if [[ $i -eq 20 ]]; then
69+
echo -e "\nTimed out waiting for ${title} to start, consult logs (\`docker logs ghost\`)"
70+
exit 1
71+
fi
72+
done
6273
;;
63-
"${commands[1]}")
64-
if pkg_installed docker-ce; then
65-
local container=$(docker container ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1}')
66-
local image=$(docker image ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}')
67-
fi
74+
"${commands[1]}")
6875
if [[ "${container}" ]]; then
69-
docker container rm -f "$container" >/dev/null
70-
fi
71-
if [[ "${image}" ]]; then
72-
docker image rm "$image" >/dev/null
76+
docker container rm -f "$container" >/dev/null 2>&1
7377
fi
7478
;;
75-
"${commands[2]}")
79+
"${commands[2]}")
7680
${module_options["module_ghost,feature"]} ${commands[1]}
81+
if [[ "${image}" ]]; then
82+
docker image rm "$image" >/dev/null 2>&1 || true
83+
fi
7784
if [[ -n "${GHOST_BASE}" && "${GHOST_BASE}" != "/" ]]; then
7885
rm -rf "${GHOST_BASE}"
7986
fi
8087
;;
81-
"${commands[3]}")
82-
if pkg_installed docker-ce; then
83-
local container=$(docker container ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1}')
84-
local image=$(docker image ls -a | mawk '/(^|[[:space:]])ghost([[:space:]]|$)/{print $1":"$2}')
85-
fi
88+
"${commands[3]}")
8689
if [[ "${container}" && "${image}" ]]; then
8790
return 0
8891
else
8992
return 1
9093
fi
9194
;;
92-
"${commands[4]}")
93-
echo -e "\nUsage: ${module_options["module_ghost,feature"]} <command>"
94-
echo -e "Commands: ${module_options["module_ghost,example"]}"
95-
echo "Available commands:"
96-
echo -e "\tinstall\t- Install $title."
97-
echo -e "\t Optionally accepts arguments:"
98-
echo -e "\t db_host db_user db_pass db_name url"
99-
echo -e "\tremove\t- Remove $title."
100-
echo -e "\tpurge\t- Purge $title image and data."
101-
echo -e "\tstatus\t- Show container status."
102-
echo
95+
"${commands[4]}")
96+
echo -e "\nUsage: ${module_options["module_ghost,feature"]} <command>"
97+
echo -e "Commands: ${module_options["module_ghost,example"]}"
98+
echo "Available commands:"
99+
echo -e "\tinstall\t- Install $title."
100+
echo -e "\t Optionally accepts arguments:"
101+
echo -e "\t db_user db_pass"
102+
echo -e "\tremove\t- Remove $title."
103+
echo -e "\tpurge\t- Purge $title data folder."
104+
echo -e "\tstatus\t- Installation status $title."
105+
echo
103106
;;
104-
*)
105-
module_ghost "${commands[4]}"
107+
*)
108+
${module_options["module_ghost,feature"]} ${commands[4]}
106109
;;
107110
esac
108111
}

tools/modules/software/module_mysql.sh

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,59 @@ module_options+=(
1010
["module_mysql,port"]="3306"
1111
["module_mysql,arch"]="x86-64 arm64"
1212
)
13+
1314
#
1415
# Module mysql
1516
#
1617
function module_mysql () {
1718
local title="mysql"
1819
local condition=$(which "$title" 2>/dev/null)
1920

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/mysql?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/mysql?( |$)/{print $1":"$2}')
23-
fi
21+
pkg_installed docker.io || module_docker install
22+
local container=$(docker container ls -a --filter "name=mysql" --format '{{.ID}}')
23+
local image=$(docker image ls -a --format '{{.Repository}} {{.ID}}' | grep '^mysql ' | awk '{print $2}')
2424

2525
local commands
2626
IFS=' ' read -r -a commands <<< "${module_options["module_mysql,example"]}"
2727

2828
MYSQL_BASE="${SOFTWARE_FOLDER}/mysql"
2929

30-
case $1 in
30+
case "$1" in
3131
"${commands[0]}")
32-
33-
if module_mysql status; then
34-
echo "deb"
35-
exit 0
32+
# Exit if mysql is already running
33+
if [[ "${container}" && "${image}" ]]; then
34+
echo "MySQL container is already installed."
35+
exit 0
3636
fi
3737

38-
pkg_installed docker-ce || module_docker install
39-
# get parameters or fallback to dialog
4038
MYSQL_ROOT_PASSWORD="${2:-armbian}"
4139
MYSQL_DATABASE="${3:-armbian}"
4240
MYSQL_USER="${4:-armbian}"
4341
MYSQL_PASSWORD="${5:-armbian}"
4442

4543
[[ -d "$MYSQL_BASE" ]] || mkdir -p "$MYSQL_BASE" || { echo "Couldn't create storage directory: $MYSQL_BASE"; exit 1; }
4644

47-
docker pull mysql:lts
4845
docker run -d \
4946
--name mysql \
5047
--net=lsio \
51-
-e MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-armbian}" \
52-
-e MYSQL_DATABASE="${MYSQL_DATABASE:-armbian}" \
53-
-e MYSQL_USER="${MYSQL_USER:-armbian}" \
54-
-e MYSQL_PASSWORD="${MYSQL_PASSWORD:-armbian}" \
48+
-e MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD}" \
49+
-e MYSQL_DATABASE="${MYSQL_DATABASE}" \
50+
-e MYSQL_USER="${MYSQL_USER}" \
51+
-e MYSQL_PASSWORD="${MYSQL_PASSWORD}" \
5552
-v "${MYSQL_BASE}:/var/lib/mysql" \
56-
-p 3306:3306 \
53+
-p "${module_options["module_mysql,port"]}:3306" \
5754
--restart unless-stopped \
5855
mysql:lts
5956

57+
# Wait for MySQL to be ready
6058
until docker exec mysql \
6159
env MYSQL_PWD="$MYSQL_ROOT_PASSWORD" \
6260
mysql -uroot -e "SELECT 1;" &>/dev/null; do
6361
echo "⏳ Waiting for MySQL to accept connections..."
6462
sleep 2
6563
done
6664

65+
# Create additional databases
6766
MYSQL_DATABASES=("ghost") # Add any additional databases you want to create here
6867
for MYSQL_DATABASE in "${MYSQL_DATABASES[@]}"; do
6968
echo "⏳ Creating database: $MYSQL_DATABASE and granting privileges..."
@@ -72,17 +71,18 @@ function module_mysql () {
7271
env MYSQL_PWD="$MYSQL_ROOT_PASSWORD" \
7372
mysql -uroot <<-EOF
7473
CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\`;
75-
GRANT ALL PRIVILEGES ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%';
74+
GRANT ALL PRIVILEGES ON \`$MYSQL_DATABASE\`.* TO '${MYSQL_USER}'@'%';
7675
FLUSH PRIVILEGES;
7776
EOF
7877
done
7978
;;
8079
"${commands[1]}")
8180
if [[ "${container}" ]]; then
82-
docker container rm -f "$container" >/dev/null
81+
echo "Removing container: $container"
82+
docker container rm -f "$container"
8383
fi
8484
if [[ "${image}" ]]; then
85-
docker image rm "$image" >/dev/null
85+
docker image rm "$image"
8686
fi
8787
;;
8888
"${commands[2]}")
@@ -92,10 +92,6 @@ function module_mysql () {
9292
fi
9393
;;
9494
"${commands[3]}")
95-
if pkg_installed docker-ce; then
96-
local container=$(docker container ls -a | mawk '/mysql?( |$)/{print $1}')
97-
local image=$(docker image ls -a | mawk '/mysql?( |$)/{print $1":"$2}')
98-
fi
9995
if [[ "${container}" && "${image}" ]]; then
10096
return 0
10197
else
@@ -107,8 +103,8 @@ function module_mysql () {
107103
echo -e "Commands: ${module_options["module_mysql,example"]}"
108104
echo "Available commands:"
109105
echo -e "\tinstall\t- Install $title."
110-
echo -e "\t Optionally accepts arguments:"
111-
echo -e "\t root_password database user user_password"
106+
echo -e "\t Optionally accepts arguments:"
107+
echo -e "\t root_password database user user_password"
112108
echo -e "\tremove\t- Remove $title."
113109
echo -e "\tpurge\t- Purge $title data folder."
114110
echo -e "\tstatus\t- Installation status $title."

0 commit comments

Comments
 (0)