mirror of
https://github.com/tinode/chat.git
synced 2025-03-14 10:05:07 +00:00
add NO_DB_INIT param to init-db
This commit is contained in:
@ -111,6 +111,7 @@ services:
|
||||
# Wait for tinode-0, not the database since
|
||||
# we let tinode-0 perform all database initialization and upgrade work.
|
||||
"WAIT_FOR": "tinode-0:18080"
|
||||
"NO_DB_INIT": "true"
|
||||
|
||||
tinode-2:
|
||||
<< : *tinode-base
|
||||
@ -130,6 +131,7 @@ services:
|
||||
# Wait for tinode-0, not the database since
|
||||
# we let tinode-0 perform all database initialization and upgrade work.
|
||||
"WAIT_FOR": "tinode-0:18080"
|
||||
"NO_DB_INIT": "true"
|
||||
|
||||
# Monitoring.
|
||||
# Exporters are paired with tinode instances.
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
ARG VERSION=0.16.4
|
||||
ARG VERSION=0.16
|
||||
ENV VERSION=$VERSION
|
||||
|
||||
LABEL maintainer="Tinode Team <info@tinode.co>"
|
||||
@ -40,6 +40,9 @@ ENV RESET_DB=false
|
||||
# An option to upgrade database.
|
||||
ENV UPGRADE_DB=false
|
||||
|
||||
# Don't initialize database if it's missing
|
||||
ENV NO_DB_INIT=false
|
||||
|
||||
# Load sample data to database from data.json.
|
||||
ARG SAMPLE_DATA=data.json
|
||||
ENV SAMPLE_DATA=$SAMPLE_DATA
|
||||
@ -104,6 +107,10 @@ RUN apk update && \
|
||||
|
||||
WORKDIR /opt/tinode
|
||||
|
||||
# Copy config template to the container.
|
||||
COPY config.template .
|
||||
COPY entrypoint.sh .
|
||||
|
||||
# Get the desired Tinode build.
|
||||
ADD https://github.com/tinode/chat/releases/download/v$VERSION/tinode-$TARGET_DB.linux-amd64.tar.gz .
|
||||
|
||||
@ -111,10 +118,6 @@ ADD https://github.com/tinode/chat/releases/download/v$VERSION/tinode-$TARGET_DB
|
||||
RUN tar -xzf tinode-$TARGET_DB.linux-amd64.tar.gz \
|
||||
&& rm tinode-$TARGET_DB.linux-amd64.tar.gz
|
||||
|
||||
# Copy config template to the container.
|
||||
COPY config.template .
|
||||
COPY entrypoint.sh .
|
||||
|
||||
# Create directory for chatbot data.
|
||||
RUN mkdir /botdata
|
||||
|
||||
|
@ -101,7 +101,13 @@ fi
|
||||
|
||||
# Initialize the database if it has not been initialized yet or if data reset/upgrade has been requested.
|
||||
init_stdout=./init-db-stdout.txt
|
||||
./init-db --reset=${RESET_DB} --upgrade=${UPGRADE_DB} --config=${CONFIG} --data=${SAMPLE_DATA} 1>${init_stdout}
|
||||
./init-db \
|
||||
--reset=${RESET_DB} \
|
||||
--upgrade=${UPGRADE_DB} \
|
||||
--config=${CONFIG} \
|
||||
--data=${SAMPLE_DATA} \
|
||||
--no_int=${NO_DB_INIT}
|
||||
1>${init_stdout}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "./init-db failed. Quitting."
|
||||
exit 1
|
||||
|
@ -167,6 +167,7 @@ func getPassword(n int) string {
|
||||
func main() {
|
||||
var reset = flag.Bool("reset", false, "force database reset")
|
||||
var upgrade = flag.Bool("upgrade", false, "perform database version upgrade")
|
||||
var noInit = flag.Bool("no_init", false, "check that database exists but don't create if missing")
|
||||
var datafile = flag.String("data", "", "name of file with sample data to load")
|
||||
var conffile = flag.String("config", "./tinode.conf", "config of the database connection")
|
||||
|
||||
@ -197,10 +198,13 @@ func main() {
|
||||
err := store.Open(1, config.StoreConfig)
|
||||
defer store.Close()
|
||||
|
||||
log.Println("Initializing", store.GetAdapterName(), store.GetAdapterVersion())
|
||||
log.Println("Database", store.GetAdapterName(), store.GetAdapterVersion())
|
||||
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Database not initialized") {
|
||||
if *noInit {
|
||||
log.Fatalln("Database not found.")
|
||||
}
|
||||
log.Println("Database not found. Creating.")
|
||||
} else if strings.Contains(err.Error(), "Invalid database version") {
|
||||
msg := "Wrong DB version: expected " + strconv.Itoa(store.GetAdapterVersion()) + ", got " +
|
||||
|
Reference in New Issue
Block a user