From df4cfa3567bcf4d239b52d66176d7749f9535f7b Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Thu, 8 Sep 2022 12:06:19 +0200 Subject: [PATCH] Add 'wdcli monday' command --- cmd/monday.go | 71 ++++++++++++++++++++++++++++++ cmd/wdcli/main.go | 1 + distillery/monday_full.sh | 34 -------------- distillery/monday_short.sh | 30 ------------- distillery/update_prefix_config.sh | 43 ------------------ go.mod | 2 +- go.sum | 4 +- 7 files changed, 75 insertions(+), 110 deletions(-) create mode 100644 cmd/monday.go delete mode 100644 distillery/monday_full.sh delete mode 100644 distillery/monday_short.sh delete mode 100644 distillery/update_prefix_config.sh diff --git a/cmd/monday.go b/cmd/monday.go new file mode 100644 index 0000000..fac52c4 --- /dev/null +++ b/cmd/monday.go @@ -0,0 +1,71 @@ +package cmd + +import ( + "os" + + wisski_distillery "github.com/FAU-CDI/wisski-distillery" + "github.com/FAU-CDI/wisski-distillery/env" + "github.com/FAU-CDI/wisski-distillery/internal/logging" +) + +// Monday is the 'monday' command +var Monday wisski_distillery.Command = monday{} + +type monday struct { + UpdateInstances bool `short:"u" long:"update-instances" description:"Fully update instances. May take a long time, and is potentially breaking. "` + Positionals struct { + GraphdbZip string `positional-arg-name:"PATH_TO_GRAPHDB_ZIP" required:"1-1" description:"path to the graphdb.zip file"` + } `positional-args:"true"` +} + +func (monday) Description() wisski_distillery.Description { + return wisski_distillery.Description{ + Requirements: env.Requirements{ + NeedsConfig: true, + }, + Command: "monday", + Description: "Runs regular monday tasks", + } +} + +func (monday monday) AfterParse() error { + _, err := os.Stat(monday.Positionals.GraphdbZip) + if os.IsNotExist(err) { + return errNoGraphDBZip.WithMessageF(monday.Positionals.GraphdbZip) + } + if err != nil { + return err + } + return nil +} + +func (monday monday) Run(context wisski_distillery.Context) error { + if err := logging.LogOperation(func() error { + return context.Exec("backup") + }, context.IOStream, "Running backup"); err != nil { + return err + } + + if err := logging.LogOperation(func() error { + return context.Exec("system_update", monday.Positionals.GraphdbZip) + }, context.IOStream, "Running system_update"); err != nil { + return err + } + + if err := logging.LogOperation(func() error { + return context.Exec("rebuild") + }, context.IOStream, "Running rebuild"); err != nil { + return err + } + + if monday.UpdateInstances { + if err := logging.LogOperation(func() error { + return context.Exec("blind_update") + }, context.IOStream, "Running blind_update"); err != nil { + return err + } + } + + logging.LogMessage(context.IOStream, "Done, have a great week!") + return nil +} diff --git a/cmd/wdcli/main.go b/cmd/wdcli/main.go index 3800146..78de9dc 100644 --- a/cmd/wdcli/main.go +++ b/cmd/wdcli/main.go @@ -47,6 +47,7 @@ func init() { wdcli.Register(cmd.Snapshot) wdcli.Register(cmd.Backup) wdcli.Register(cmd.Cron) + wdcli.Register(cmd.Monday) } // an error when no arguments are provided. diff --git a/distillery/monday_full.sh b/distillery/monday_full.sh deleted file mode 100644 index 56457de..0000000 --- a/distillery/monday_full.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -e - -# read the lib/shared.sh and read the slug argument. -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "$DIR" -source "$DIR/lib/lib.sh" - -# Read the 'GRAPHDB_ZIP' argument from the command line. -# If it's not set, throw an error. -GRAPHDB_ZIP=$1 -if [ -z "$GRAPHDB_ZIP" ]; then - log_error "Usage: monday.sh GRAPHDB_ZIP" - exit 1; -fi; - - -# Backup -log_info " => Running backup, this will take a long time" -bash backup_all.sh - -# system install -log_info " => Reinstalling system" -bash system_install.sh "$GRAPHDB_ZIP" - -# rebuild all the systems -log_info " => Rebuilding all instances" -bash rebuild_all.sh - -# perform all the blind updates -log_info " => Performing updates" -bash blind_update_all.sh - -log_info " => Done, have a great week" diff --git a/distillery/monday_short.sh b/distillery/monday_short.sh deleted file mode 100644 index db9cc04..0000000 --- a/distillery/monday_short.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set -e - -# read the lib/shared.sh and read the slug argument. -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "$DIR" -source "$DIR/lib/lib.sh" - -# Read the 'GRAPHDB_ZIP' argument from the command line. -# If it's not set, throw an error. -GRAPHDB_ZIP=$1 -if [ -z "$GRAPHDB_ZIP" ]; then - log_error "Usage: monday_short.sh GRAPHDB_ZIP" - exit 1; -fi; - - -# Backup -log_info " => Running backup, this will take a long time" -bash backup_all.sh - -# system install -log_info " => Reinstalling system" -bash system_install.sh "$GRAPHDB_ZIP" - -# rebuild all the systems -log_info " => Rebuilding all instances" -bash rebuild_all.sh - -log_info " => Done, have a great week" diff --git a/distillery/update_prefix_config.sh b/distillery/update_prefix_config.sh deleted file mode 100644 index 76f46f9..0000000 --- a/distillery/update_prefix_config.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e - -# read the lib/shared.sh -DISABLE_LOG=1 -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "$DIR" -source "$DIR/lib/lib.sh" -DISABLE_LOG=0 - -log_info " => Writing prefix configuration" - -echo -n "# Prefix configuration, last updated on" | tee "$DEPLOY_PREFIX_CONFIG" -date | tee -a "$DEPLOY_PREFIX_CONFIG" - -# update all the instances -for slug in $(sql_bookkeep_list); do - INSTANCE_DOMAIN="$(compute_instance_url "$slug")" - - read -r INSTANCE_BASE_DIR MYSQL_DATABASE MYSQL_USER GRAPHDB_REPO GRAPHDB_USER GRAPHDB_PASSWORD <<< "$(sql_bookkeep_load "${slug}" "filesystem_base,sql_database,sql_user,graphdb_repository,graphdb_user,graphdb_password" | tail -n +2)" - - INSTANCE_NOPREFIX_FILE="$(compute_instance_noprefixfile "$INSTANCE_BASE_DIR" )" - INSTANCE_PREFIX_FILE="$(compute_instance_prefixfile "$INSTANCE_BASE_DIR" )" - if [ -f "$INSTANCE_NOPREFIX_FILE" ]; then - continue - fi - - pushd "$INSTANCE_BASE_DIR" > /dev/null - - echo "$INSTANCE_DOMAIN:" | tee -a "$DEPLOY_PREFIX_CONFIG" - docker-compose exec barrel /user_shell.sh -c "drush php:script /wisskiutils/list_uri_prefixes.php" | tee -a "$DEPLOY_PREFIX_CONFIG" - - if [ -f "$INSTANCE_PREFIX_FILE" ]; then - cat "$INSTANCE_PREFIX_FILE" | tee -a "$DEPLOY_PREFIX_CONFIG" - fi - - popd > /dev/null -done - -log_info " => Restarting resolver" - -cd "$DEPLOY_RESOLVER_DIR" -docker-compose restart \ No newline at end of file diff --git a/go.mod b/go.mod index 67f73d9..c06f685 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/alessio/shellescape v1.4.1 github.com/feiin/sqlstring v0.3.0 github.com/pkg/errors v0.9.1 - github.com/tkw1536/goprogram v0.0.10 + github.com/tkw1536/goprogram v0.0.11 golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e gorm.io/driver/mysql v1.3.6 gorm.io/gorm v1.23.8 diff --git a/go.sum b/go.sum index 8a36b0d..8f89ecf 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/tkw1536/goprogram v0.0.10 h1:NRnAW46Vl9ro01eLDhlb7R56HsCls43h2anNXjwMPP4= -github.com/tkw1536/goprogram v0.0.10/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4= +github.com/tkw1536/goprogram v0.0.11 h1:RDcPvpObL6mViB2knUj+v0AyP+XL6vvMEA0auB2Ahz4= +github.com/tkw1536/goprogram v0.0.11/go.mod h1:rX9MKOpJ9qAu4jHV2+n64SKmm3c2D3Hh1V8zC1H3jB4= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=