Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend setup database create dump #2184

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ inplace-conf-common: dist
--with-domserver_tmpdir=$(CURDIR)/output/tmp \
--with-judgehost_tmpdir=$(CURDIR)/output/tmp \
--with-judgehost_judgedir=$(CURDIR)/output/judgings \
--with-domserver_databasedumpdir=$(CURDIR)/output/db-dumps \
--with-baseurl='http://localhost/domjudge/' \
CFLAGS='$(MAINT_CXFLAGS) -std=c11' \
CXXFLAGS='$(MAINT_CXFLAGS) -std=c++11' \
Expand Down
95 changes: 49 additions & 46 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -161,34 +161,35 @@ fi
# These are defaults that can still be overridden below!
if test "x$FHS_ENABLED" = xyes ; then
if test "x$DOMSERVER_BUILD_ENABLED" = xyes; then
AC_SUBST(domserver_root, '')
AC_SUBST(domserver_bindir, $bindir)
AC_SUBST(domserver_etcdir, $sysconfdir/${PACKAGE_TARNAME})
AC_SUBST(domserver_webappdir, $datadir/${PACKAGE_TARNAME}/webapp)
AC_SUBST(domserver_sqldir, $datadir/${PACKAGE_TARNAME}/sql)
AC_SUBST(domserver_libdir, $libdir/${PACKAGE_TARNAME})
AC_SUBST(domserver_libvendordir, $libdir/${PACKAGE_TARNAME}/vendor)
AC_SUBST(domserver_logdir, $localstatedir/log/${PACKAGE_TARNAME})
AC_SUBST(domserver_rundir, $localstatedir/run/${PACKAGE_TARNAME})
AC_SUBST(domserver_tmpdir, /tmp)
AC_SUBST(domserver_exampleprobdir,$datadir/${PACKAGE_TARNAME}/example_problems)
AC_SUBST(domserver_root, '')
AC_SUBST(domserver_bindir, $bindir)
AC_SUBST(domserver_etcdir, $sysconfdir/${PACKAGE_TARNAME})
AC_SUBST(domserver_webappdir, $datadir/${PACKAGE_TARNAME}/webapp)
AC_SUBST(domserver_sqldir, $datadir/${PACKAGE_TARNAME}/sql)
AC_SUBST(domserver_libdir, $libdir/${PACKAGE_TARNAME})
AC_SUBST(domserver_libvendordir, $libdir/${PACKAGE_TARNAME}/vendor)
AC_SUBST(domserver_logdir, $localstatedir/log/${PACKAGE_TARNAME})
AC_SUBST(domserver_rundir, $localstatedir/run/${PACKAGE_TARNAME})
AC_SUBST(domserver_tmpdir, /tmp)
AC_SUBST(domserver_exampleprobdir, $datadir/${PACKAGE_TARNAME}/example_problems)
AC_SUBST(domserver_databasedumpdir, $localstatedir/lib/${PACKAGE_TARNAME}/db-dumps)
fi

if test "x$JUDGEHOST_BUILD_ENABLED" = xyes; then
AC_SUBST(judgehost_root, '')
AC_SUBST(judgehost_bindir, $bindir)
AC_SUBST(judgehost_etcdir, $sysconfdir/${PACKAGE_TARNAME})
AC_SUBST(judgehost_libdir, $libdir/${PACKAGE_TARNAME})
AC_SUBST(judgehost_libjudgedir, $libdir/${PACKAGE_TARNAME}/judge)
AC_SUBST(judgehost_logdir, $localstatedir/log/${PACKAGE_TARNAME})
AC_SUBST(judgehost_rundir, $localstatedir/run/${PACKAGE_TARNAME})
AC_SUBST(judgehost_tmpdir, /tmp)
AC_SUBST(judgehost_judgedir, $localstatedir/lib/${PACKAGE_TARNAME}/judgings)
AC_SUBST(judgehost_chrootdir, /chroot/${PACKAGE_TARNAME})
AC_SUBST(judgehost_cgroupdir, /sys/fs/cgroup)
AC_SUBST(judgehost_root, '')
AC_SUBST(judgehost_bindir, $bindir)
AC_SUBST(judgehost_etcdir, $sysconfdir/${PACKAGE_TARNAME})
AC_SUBST(judgehost_libdir, $libdir/${PACKAGE_TARNAME})
AC_SUBST(judgehost_libjudgedir, $libdir/${PACKAGE_TARNAME}/judge)
AC_SUBST(judgehost_logdir, $localstatedir/log/${PACKAGE_TARNAME})
AC_SUBST(judgehost_rundir, $localstatedir/run/${PACKAGE_TARNAME})
AC_SUBST(judgehost_tmpdir, /tmp)
AC_SUBST(judgehost_judgedir, $localstatedir/lib/${PACKAGE_TARNAME}/judgings)
AC_SUBST(judgehost_chrootdir, /chroot/${PACKAGE_TARNAME})
AC_SUBST(judgehost_cgroupdir, /sys/fs/cgroup)
fi

AC_SUBST(domjudge_docdir, $docdir)
AC_SUBST(domjudge_docdir, $docdir)
fi

# }}}
Expand All @@ -205,38 +206,39 @@ AC_DEFUN([AX_PATH], [
AX_WITH_COMMENT(2,[ ])
AX_WITH_COMMENT(3,[Fine tuning of installation root paths when FHS is disabled (the default):])
if test "x$DOMSERVER_BUILD_ENABLED" = xyes; then
AX_PATH(domserver_root, [$prefix/domserver])
AX_PATH(domserver_root, [$prefix/domserver])
fi
if test "x$JUDGEHOST_BUILD_ENABLED" = xyes; then
AX_PATH(judgehost_root, [$prefix/judgehost])
AX_PATH(judgehost_root, [$prefix/judgehost])
fi
AX_PATH(domjudge_docdir, [$prefix/doc])
AX_PATH(domjudge_docdir, [$prefix/doc])
AX_WITH_COMMENT(4,[ ])
AX_WITH_COMMENT(5,[More fine tuning of all installation (sub)directories:])
if test "x$DOMSERVER_BUILD_ENABLED" = xyes; then
AX_PATH(domserver_bindir, [$domserver_root/bin])
AX_PATH(domserver_etcdir, [$domserver_root/etc])
AX_PATH(domserver_webappdir, [$domserver_root/webapp])
AX_PATH(domserver_sqldir, [$domserver_root/sql])
AX_PATH(domserver_libdir, [$domserver_root/lib])
AX_PATH(domserver_libvendordir, [$domserver_root/lib/vendor])
AX_PATH(domserver_logdir, [$domserver_root/log])
AX_PATH(domserver_rundir, [$domserver_root/run])
AX_PATH(domserver_tmpdir, [$domserver_root/tmp])
AX_PATH(domserver_exampleprobdir, [$domserver_root/example_problems])
AX_PATH(domserver_bindir, [$domserver_root/bin])
AX_PATH(domserver_etcdir, [$domserver_root/etc])
AX_PATH(domserver_webappdir, [$domserver_root/webapp])
AX_PATH(domserver_sqldir, [$domserver_root/sql])
AX_PATH(domserver_libdir, [$domserver_root/lib])
AX_PATH(domserver_libvendordir, [$domserver_root/lib/vendor])
AX_PATH(domserver_logdir, [$domserver_root/log])
AX_PATH(domserver_rundir, [$domserver_root/run])
AX_PATH(domserver_tmpdir, [$domserver_root/tmp])
AX_PATH(domserver_exampleprobdir, [$domserver_root/example_problems])
AX_PATH(domserver_databasedumpdir, [$domserver_root/db-dumps])
fi
if test "x$JUDGEHOST_BUILD_ENABLED" = xyes; then
AX_WITH_COMMENT(6,[ ])
AX_PATH(judgehost_bindir, [$judgehost_root/bin])
AX_PATH(judgehost_etcdir, [$judgehost_root/etc])
AX_PATH(judgehost_libdir, [$judgehost_root/lib])
AX_PATH(judgehost_libjudgedir, [$judgehost_root/lib/judge])
AX_PATH(judgehost_logdir, [$judgehost_root/log])
AX_PATH(judgehost_rundir, [$judgehost_root/run])
AX_PATH(judgehost_tmpdir, [$judgehost_root/tmp])
AX_PATH(judgehost_judgedir, [$judgehost_root/judgings])
AX_PATH(judgehost_chrootdir, [/chroot/${PACKAGE_TARNAME}])
AX_PATH(judgehost_cgroupdir, [/sys/fs/cgroup])
AX_PATH(judgehost_bindir, [$judgehost_root/bin])
AX_PATH(judgehost_etcdir, [$judgehost_root/etc])
AX_PATH(judgehost_libdir, [$judgehost_root/lib])
AX_PATH(judgehost_libjudgedir, [$judgehost_root/lib/judge])
AX_PATH(judgehost_logdir, [$judgehost_root/log])
AX_PATH(judgehost_rundir, [$judgehost_root/run])
AX_PATH(judgehost_tmpdir, [$judgehost_root/tmp])
AX_PATH(judgehost_judgedir, [$judgehost_root/judgings])
AX_PATH(judgehost_chrootdir, [/chroot/${PACKAGE_TARNAME}])
AX_PATH(judgehost_cgroupdir, [/sys/fs/cgroup])
fi
AX_WITH_COMMENT(7,[ ])

Expand Down Expand Up @@ -386,6 +388,7 @@ echo " - sql..............: AX_VAR_EXPAND($domserver_sqldir)"
echo " - tmp..............: AX_VAR_EXPAND($domserver_tmpdir)"
echo " - webapp...........: AX_VAR_EXPAND($domserver_webappdir)"
echo " - example_problems.: AX_VAR_EXPAND($domserver_exampleprobdir)"
echo " - database_dumps...: AX_VAR_EXPAND($domserver_databasedumpdir)"
fi
if test "x$JUDGEHOST_BUILD_ENABLED" = xyes; then
echo ""
Expand Down
56 changes: 29 additions & 27 deletions paths.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,41 @@ pdfdir = @pdfdir@
psdir = @psdir@

# Installation paths
domserver_bindir = @domserver_bindir@
domserver_etcdir = @domserver_etcdir@
domserver_webappdir = @domserver_webappdir@
domserver_sqldir = @domserver_sqldir@
domserver_libdir = @domserver_libdir@
domserver_libvendordir = @domserver_libvendordir@
domserver_logdir = @domserver_logdir@
domserver_rundir = @domserver_rundir@
domserver_tmpdir = @domserver_tmpdir@
domserver_exampleprobdir = @domserver_exampleprobdir@
PHPVERSION = @PHPVERSION@

judgehost_bindir = @judgehost_bindir@
judgehost_etcdir = @judgehost_etcdir@
judgehost_libdir = @judgehost_libdir@
judgehost_libjudgedir = @judgehost_libjudgedir@
judgehost_logdir = @judgehost_logdir@
judgehost_rundir = @judgehost_rundir@
judgehost_tmpdir = @judgehost_tmpdir@
judgehost_judgedir = @judgehost_judgedir@
judgehost_chrootdir = @judgehost_chrootdir@
judgehost_cgroupdir = @judgehost_cgroupdir@

domjudge_docdir = @domjudge_docdir@

systemd_unitdir = @systemd_unitdir@
domserver_bindir = @domserver_bindir@
domserver_etcdir = @domserver_etcdir@
domserver_webappdir = @domserver_webappdir@
domserver_sqldir = @domserver_sqldir@
domserver_libdir = @domserver_libdir@
domserver_libvendordir = @domserver_libvendordir@
domserver_logdir = @domserver_logdir@
domserver_rundir = @domserver_rundir@
domserver_tmpdir = @domserver_tmpdir@
domserver_exampleprobdir = @domserver_exampleprobdir@
domserver_databasedumpdir = @domserver_databasedumpdir@
PHPVERSION = @PHPVERSION@

judgehost_bindir = @judgehost_bindir@
judgehost_etcdir = @judgehost_etcdir@
judgehost_libdir = @judgehost_libdir@
judgehost_libjudgedir = @judgehost_libjudgedir@
judgehost_logdir = @judgehost_logdir@
judgehost_rundir = @judgehost_rundir@
judgehost_tmpdir = @judgehost_tmpdir@
judgehost_judgedir = @judgehost_judgedir@
judgehost_chrootdir = @judgehost_chrootdir@
judgehost_cgroupdir = @judgehost_cgroupdir@

domjudge_docdir = @domjudge_docdir@

systemd_unitdir = @systemd_unitdir@

# The tmpdir's are not in these lists, since they would otherwise get
# their permissions overwritten in FHS install mode.
domserver_dirs = $(domserver_bindir) $(domserver_etcdir) \
$(domserver_libdir) $(domserver_libvendordir) \
$(domserver_logdir) $(domserver_rundir) \
$(addprefix $(domserver_webappdir)/public/images/,affiliations countries teams) \
$(domserver_exampleprobdir)
$(domserver_exampleprobdir) $(domserver_databasedumpdir)

judgehost_dirs = $(judgehost_bindir) $(judgehost_etcdir) $(judgehost_libdir) \
$(judgehost_libjudgedir) $(judgehost_logdir) \
Expand Down Expand Up @@ -142,6 +143,7 @@ define substconfigvars
-e 's,@domserver_rundir[@],@domserver_rundir@,g' \
-e 's,@domserver_tmpdir[@],@domserver_tmpdir@,g' \
-e 's,@domserver_exampleprobdir[@],@domserver_exampleprobdir@,g' \
-e 's,@domserver_databasedumpdir[@],@domserver_databasedumpdir@,g' \
-e 's,@judgehost_bindir[@],@judgehost_bindir@,g' \
-e 's,@judgehost_etcdir[@],@judgehost_etcdir@,g' \
-e 's,@judgehost_libdir[@],@judgehost_libdir@,g' \
Expand Down
40 changes: 36 additions & 4 deletions sql/dj_setup_database.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BINDIR="@domserver_bindir@"
ETCDIR="@domserver_etcdir@"
WEBAPPDIR="@domserver_webappdir@"
EXAMPLEPROBDIR="@domserver_exampleprobdir@"
DATABASEDUMPDIR="@domserver_databasedumpdir@"

PASSWDFILE="$ETCDIR/dbpasswords.secret"

Expand All @@ -22,7 +23,7 @@ verbose()

usage() {
cat <<EOF
Usage: $0 [option]... <command>
Usage: $0 [option]... <command> [argument]

Commands:
status check database installation status
Expand All @@ -34,6 +35,7 @@ Commands:
install-examples install examples only
install-loadtest configure for load testing. WARNING: CREATES A LOT OF EXTRA ITEMS!
upgrade upgrade MySQL database schema to current version
dump [filename] backup the current database to file (without .sql.gz suffix)

Options:
-u <user> connect to MySQL with DB admin <user>
Expand All @@ -48,8 +50,7 @@ not have to pass any of the options above.
EOF
}

# Wrapper around mysql command to allow setting options, user, etc.
mysql()
mysql_options()
{
local user pass

Expand All @@ -68,7 +69,13 @@ mysql()
fi

[ -z "$USE_SOCKET" ] && port="-P$DBPORT"
command mysql $user ${pass:+"$pass"} -h "$DBHOST" ${port:+"$port"} --silent --skip-column-names "$@"
echo $user ${pass:+"$pass"} -h "$DBHOST" ${port:+"$port"}
}

# Wrapper around mysql command to allow setting options, user, etc.
mysql()
{
command mysql $(mysql_options) --silent --skip-column-names "$@"
}

# Quick shell hack to get a key from an INI file.
Expand Down Expand Up @@ -234,6 +241,10 @@ install_examples()
( cd "$EXAMPLEPROBDIR" && yes y | "$BINDIR"/import-contest )
}

create_database_dump () {
sudo mysqldump $(mysql_options) --opt --skip-lock-tables domjudge | pv | gzip > "$DATABASEDUMPDIR/${1}.sql.gz"
}

### Script starts here ###

# Parse command-line options:
Expand Down Expand Up @@ -354,6 +365,27 @@ upgrade)
verbose "DOMjudge database upgrade completed."
;;

dump)
read_dbpasswords
DUMPNAME="$2"
if [ -z "$DUMPNAME" ]; then
usage
exit 1
fi

if [ -f "${DATABASEDUMPDIR}/${DUMPNAME}.sql.gz" ]; then
while true; do
read -p "Overwrite existing database dump (y/N)? " yn
case $yn in
[Yy]* ) break ;;
''|[Nn]* ) exit 0;;
esac
done
fi
create_database_dump $DUMPNAME
exit 0
;;

*)
echo "Error: Unknown subcommand '$1'"
usage
Expand Down
Loading