only restart xochitl if service enabled

This commit is contained in:
evan 2021-03-12 23:21:23 -06:00
parent 8531bea5e3
commit 7e50dbb48f

15
main.go
View file

@ -42,7 +42,7 @@ func main() {
// ----- Parse options -----
debug := flag.Bool("debug", false, "enable debug output")
debug_flag := flag.Bool("debug", false, "enable debug output")
test := flag.Bool("test", false, "use /tmp as output dir")
restart := flag.Bool("restart", false, "restart xochitl after saving PDF")
CONN_HOST := flag.String("host", CONN_HOST, "override bind address")
@ -50,8 +50,9 @@ func main() {
flag.Parse()
if *debug {
if *debug_flag {
LOG_LEVEL = "debug"
debug("Debugging enabled")
}
if *test {
XOCHITL_DIR = "/tmp/"
@ -77,9 +78,13 @@ func main() {
// Restart xochitl
if *restart {
stdout, err := exec.Command("systemctl", "restart", "xochitl").CombinedOutput()
if err != nil {
fmt.Println("xochitl restart failed with message:", string(stdout))
stdout, exitcode := exec.Command("systemctl", "is-enabled", "xochitl").CombinedOutput()
if exitcode != nil {
debug("Restarting xochitl")
stdout, err := exec.Command("systemctl", "restart", "xochitl").CombinedOutput()
if err != nil {
fmt.Println("xochitl restart failed with message:", string(stdout))
}
}
}