added health check for each of the services

This commit is contained in:
2024-09-24 09:43:23 +08:00
parent b42a631447
commit 46996732e9
2 changed files with 23 additions and 8 deletions
+6
View File
@@ -36,6 +36,12 @@ app.use("/user/register", registerRoutes);
app.use("/popcen", authenticateToken, popcenRoutes);
app.use("/popcenCount", authenticateToken, popcenCountRoutes);
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on port ${PORT} in ${process.env.NODE_ENV || 'development'} mode`);
+17 -8
View File
@@ -10,12 +10,14 @@ services:
MYSQL_DATABASE: popcenauth
MYSQL_USER: admin
ports:
- "3308:3306" # Different port for the auth DB
- "3308:3306"
volumes:
#- D:/Projects/AuthenticatedAPIDocker/app/mysql/etc/mysql/mysqlauth/etc:/etc
- D:/Projects/AuthenticatedAPIDocker/app/mysql/mysqldata_auth:/var/lib/mysql
# extra_hosts:
# - "host.docker.internal:host-gateway"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 10s
retries: 5
# Data Database
mysql-data:
@@ -26,12 +28,16 @@ services:
MYSQL_DATABASE: popcen
MYSQL_USER: admin # Change to root
ports:
- "3309:3306" # Default port for the data DB
- "3309:3306"
volumes:
# - D:/Projects/AuthenticatedAPIDocker/app/mysql/etc/mysql/mysqldata/etc:/etc
- D:/Projects/AuthenticatedAPIDocker/app/mysql/mysqldata:/var/lib/mysql
extra_hosts:
- "host.docker.internal:host-gateway"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 10s
retries: 5
# Node.js Service
nodejs:
@@ -46,12 +52,10 @@ services:
# Auth DB connection
AUTH_DB_HOST: mysql-auth
AUTH_DB_USER: root
#AUTH_DB_PORT: 3306
AUTH_DB_NAME: popcenauth
# Data DB connection
DATA_DB_HOST: mysql-data
#DATA_DB_PORT: 3306
DATA_DB_USER: root
DATA_DB_NAME: popcen
@@ -59,6 +63,11 @@ services:
- mysql-auth
- mysql-data
command: "node server.js"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
mysqldata_auth: