Skip to content

Instantly share code, notes, and snippets.

@pawlik
Created February 13, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlik/2f8ed8e5609326c7f84d to your computer and use it in GitHub Desktop.
Save pawlik/2f8ed8e5609326c7f84d to your computer and use it in GitHub Desktop.
cmd script to enable/disable maintenance mode in magento 1.*
package main
import (
"fmt"
io "io/ioutil"
"os"
"flag"
)
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [-off]\n", os.Args[0])
/*
Below: when registering flag var you specify default (2nd param),
flag knows now how to print that information - neat
*/
flag.PrintDefaults()
os.Exit(2)
}
// just generic results reporting
func report_result(success_message string, error error) {
if error == nil {
fmt.Println(success_message)
} else {
fmt.Println(error)
os.Exit(1)
}
}
func enable_maintenance() {
error := io.WriteFile("maintenance.flag", []byte(""), 0644)
report_result("Maintenance mode on", error)
}
func disable_maintenance() {
err := os.Remove("maintenance.flag")
report_result("Maintenance mode off", err)
}
func main() {
flag.Usage = usage // this will be auto-called when running program with -h
disable := flag.Bool("off", false, "disable maintenance") // register cmd flag
// apparently returns pointer to bool (probably after parsing it set's the value)
// guessing - couldn't find docs
flag.Parse() // needs to be called after all flags registered
if *disable == false {
enable_maintenance()
} else {
disable_maintenance()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment