36 lines
1.0 KiB
Bash
Executable File
36 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Mattermost init script — creates admin user on first boot.
|
|
# This is mounted into the container and replaces the default command.
|
|
|
|
set -e
|
|
|
|
# Start Mattermost server in the background.
|
|
/entrypoint.sh mattermost server &
|
|
MM_PID=$!
|
|
|
|
# Wait for the server to be ready.
|
|
echo "init: waiting for Mattermost to start..."
|
|
for i in $(seq 1 30); do
|
|
if curl -sf http://localhost:8065/api/v4/system/ping > /dev/null 2>&1; then
|
|
echo "init: Mattermost is ready"
|
|
break
|
|
fi
|
|
if [ "$i" = "30" ]; then
|
|
echo "init: Mattermost failed to start within 60s"
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
# Create admin user (idempotent — ignores if already exists).
|
|
echo "init: creating admin user..."
|
|
/mattermost/bin/mattermost user create \
|
|
--email admin@example.com \
|
|
--username admin \
|
|
--password admin \
|
|
--system_admin 2>/dev/null && echo "init: admin user created" \
|
|
|| echo "init: admin user already exists (or creation skipped)"
|
|
|
|
# Bring Mattermost to the foreground.
|
|
wait $MM_PID
|