Added system.CopyDir and EdgeappsBackupPath conf
parent
e009c1f55d
commit
8bf26a334c
25
Makefile
25
Makefile
|
@ -40,15 +40,7 @@ test:
|
||||||
test-with-coverage:
|
test-with-coverage:
|
||||||
go test -tags=unit -timeout=600s -v ./... -coverprofile=coverage.out
|
go test -tags=unit -timeout=600s -v ./... -coverprofile=coverage.out
|
||||||
|
|
||||||
install-cloud: build-cloud
|
install:
|
||||||
systemctl stop edgeboxctl
|
|
||||||
cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
|
||||||
cp ./edgeboxctl/edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
|
||||||
systemctl daemon-reload
|
|
||||||
@echo "Edgeboxctl installed successfully"
|
|
||||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
|
||||||
|
|
||||||
install-prod: build-prod
|
|
||||||
sudo systemctl stop edgeboxctl
|
sudo systemctl stop edgeboxctl
|
||||||
sudo rm -rf /usr/local/bin/edgeboxctl /lib/systemd/system/edgeboxctl.service
|
sudo rm -rf /usr/local/bin/edgeboxctl /lib/systemd/system/edgeboxctl.service
|
||||||
sudo cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
sudo cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
||||||
|
@ -56,3 +48,18 @@ install-prod: build-prod
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
@echo "Edgeboxctl installed successfully"
|
@echo "Edgeboxctl installed successfully"
|
||||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
||||||
|
|
||||||
|
install-prod: build-prod install
|
||||||
|
install-cloud: build-cloud install
|
||||||
|
install-arm64: build-arm64 install
|
||||||
|
install-armhf: build-armhf install
|
||||||
|
|
||||||
|
start:
|
||||||
|
systemctl start edgeboxctl
|
||||||
|
|
||||||
|
stop:
|
||||||
|
systemctl stop edgeboxctl
|
||||||
|
|
||||||
|
log: start
|
||||||
|
journalctl -fu edgeboxctl
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"bufio"
|
"bufio"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -302,3 +303,78 @@ func RemoveTunnelService() {
|
||||||
utils.Exec(wsPath, "rm", cmdargs)
|
utils.Exec(wsPath, "rm", cmdargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyDir(src string, dest string) error {
|
||||||
|
srcInfo, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !srcInfo.IsDir() {
|
||||||
|
return fmt.Errorf("%s is not a directory", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(dest, srcInfo.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
items, err := ioutil.ReadDir(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
srcPath := filepath.Join(src, item.Name())
|
||||||
|
destPath := filepath.Join(dest, item.Name())
|
||||||
|
|
||||||
|
if item.IsDir() {
|
||||||
|
err = CopyDir(srcPath, destPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error copying directory %s to %s: %s\n", srcPath, destPath, err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = CopyFile(srcPath, destPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error copying file %s to %s: %s\n", srcPath, destPath, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CopyFile(src string, dest string) error {
|
||||||
|
srcFile, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer srcFile.Close()
|
||||||
|
|
||||||
|
destFile, err := os.Create(dest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer destFile.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(destFile, srcFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = destFile.Sync()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
srcInfo, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Chmod(dest, srcInfo.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -626,7 +626,7 @@ func taskRestoreBackup() string {
|
||||||
// Copy all files in /home/system/components/apps/ to a backup folder
|
// Copy all files in /home/system/components/apps/ to a backup folder
|
||||||
fmt.Println("Copying all files in /home/system/components/apps/ to a backup folder")
|
fmt.Println("Copying all files in /home/system/components/apps/ to a backup folder")
|
||||||
os.MkdirAll(utils.GetPath(utils.EdgeAppsBackupPath + "temp/"), 0777)
|
os.MkdirAll(utils.GetPath(utils.EdgeAppsBackupPath + "temp/"), 0777)
|
||||||
utils.CopyDir(utils.GetPath(utils.EdgeAppsPath), utils.GetPath(utils.EdgeAppsBackupPath + "temp/"))
|
system.CopyDir(utils.GetPath(utils.EdgeAppsPath), utils.GetPath(utils.EdgeAppsBackupPath + "temp/"))
|
||||||
|
|
||||||
fmt.Println("Removing all files in /home/system/components/apps/")
|
fmt.Println("Removing all files in /home/system/components/apps/")
|
||||||
os.RemoveAll(utils.GetPath(utils.EdgeAppsPath))
|
os.RemoveAll(utils.GetPath(utils.EdgeAppsPath))
|
||||||
|
@ -649,7 +649,7 @@ func taskRestoreBackup() string {
|
||||||
if strings.Contains(result, "Fatal:") {
|
if strings.Contains(result, "Fatal:") {
|
||||||
// Copy all files from backup folder to /home/system/components/apps/
|
// Copy all files from backup folder to /home/system/components/apps/
|
||||||
os.MkdirAll(utils.GetPath(utils.EdgeAppsPath), 0777)
|
os.MkdirAll(utils.GetPath(utils.EdgeAppsPath), 0777)
|
||||||
utils.CopyDir(utils.GetPath(utils.EdgeAppsBackupPath + "temp/"), utils.GetPath(utils.EdgeAppsPath))
|
system.CopyDir(utils.GetPath(utils.EdgeAppsBackupPath + "temp/"), utils.GetPath(utils.EdgeAppsPath))
|
||||||
|
|
||||||
fmt.Println("Error restoring backup: ")
|
fmt.Println("Error restoring backup: ")
|
||||||
utils.WriteOption("BACKUP_STATUS", "error")
|
utils.WriteOption("BACKUP_STATUS", "error")
|
||||||
|
|
|
@ -109,6 +109,7 @@ const CloudEnvFileLocation string = "cloudEnvFileLocation"
|
||||||
const ApiEnvFileLocation string = "apiEnvFileLocation"
|
const ApiEnvFileLocation string = "apiEnvFileLocation"
|
||||||
const ApiPath string = "apiPath"
|
const ApiPath string = "apiPath"
|
||||||
const EdgeAppsPath string = "edgeAppsPath"
|
const EdgeAppsPath string = "edgeAppsPath"
|
||||||
|
const EdgeAppsBackupPath string = "edgeAppsBackupPath"
|
||||||
const WsPath string = "wsPath"
|
const WsPath string = "wsPath"
|
||||||
|
|
||||||
// GetPath : Returns either the hardcoded path, or a overwritten value via .env file at project root. Register paths here for seamless working code between dev and prod environments ;)
|
// GetPath : Returns either the hardcoded path, or a overwritten value via .env file at project root. Register paths here for seamless working code between dev and prod environments ;)
|
||||||
|
@ -156,6 +157,13 @@ func GetPath(pathKey string) string {
|
||||||
targetPath = "/home/system/components/apps/"
|
targetPath = "/home/system/components/apps/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case EdgeAppsBackupPath:
|
||||||
|
if env["EDGEAPPS_BACKUP_PATH"] != "" {
|
||||||
|
targetPath = env["EDGEAPPS_BACKUP_PATH"]
|
||||||
|
} else {
|
||||||
|
targetPath = "/home/system/components/backups/"
|
||||||
|
}
|
||||||
|
|
||||||
case WsPath:
|
case WsPath:
|
||||||
|
|
||||||
if env["WS_PATH"] != "" {
|
if env["WS_PATH"] != "" {
|
||||||
|
|
Loading…
Reference in New Issue