56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
|
// package main is the main package for the LapisDeploy program
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"os/exec"
|
||
|
"strings"
|
||
|
"syscall"
|
||
|
"log"
|
||
|
"os"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/gogs/git-module"
|
||
|
)
|
||
|
|
||
|
// startServer attempts to start a Lapis server in the given repository.
|
||
|
func restartServer(name string) DeployError {
|
||
|
log.Printf("Restarting Lapis server on repository %s...", name)
|
||
|
|
||
|
old_cwd, _ := os.Getwd()
|
||
|
defer syscall.Chdir(old_cwd)
|
||
|
syscall.Chdir(configuration.sites_dir+"/"+name)
|
||
|
|
||
|
out, err := exec.Command("lapis", "build").CombinedOutput()
|
||
|
if err != nil {
|
||
|
return newDeployError(1, "restartServer", fmt.Sprintf("Failed to run 'lapis build' in repository '%s'", name), string(out))
|
||
|
}
|
||
|
log.Printf("[lapis build] %s", out)
|
||
|
if !strings.Contains(string(out), "HUP") {
|
||
|
return newDeployError(1, "restartServer", "'lapis build' command returned unexpected value!", string(out))
|
||
|
}
|
||
|
return DeployError{}
|
||
|
}
|
||
|
|
||
|
// pullRepo attempts to pull or clone a repository using the given name and url
|
||
|
func pullRepo(url string, name string) DeployError {
|
||
|
exists, err := fileExists(configuration.sites_dir+"/"+name)
|
||
|
if err != nil {
|
||
|
return newDeployError(1, "fileExists",
|
||
|
fmt.Sprintf("Failed to check whether folder '%s' exists while pulling down repository '%s'!", name, name), "")
|
||
|
}
|
||
|
if !exists {
|
||
|
log.Printf("Cloning repository %s...", name)
|
||
|
if err = git.Clone(url, configuration.sites_dir+"/"+name); err != nil {
|
||
|
return newDeployError(1, "pullRepo", fmt.Sprintf("Failed to pull down repository '%s'", name), "")
|
||
|
}
|
||
|
} else {
|
||
|
log.Printf("Pulling down repository %s...", name)
|
||
|
repo,err := git.Open(configuration.sites_dir+"/"+name)
|
||
|
if err != nil {
|
||
|
return newDeployError(1, "pullRepo", fmt.Sprintf("Failed to open git repository '%s'", name), "")
|
||
|
}
|
||
|
repo.Pull()
|
||
|
}
|
||
|
return DeployError{}
|
||
|
}
|