Compare commits

..

No commits in common. "80fc8b40cd1623bce4fe27ca073af6bb336830f7" and "a8b1da4b7c97bbda2b43ae735076baa866c4c563" have entirely different histories.

3 changed files with 18 additions and 116 deletions

View File

@ -69,8 +69,5 @@ start:
stop: stop:
systemctl stop edgeboxctl systemctl stop edgeboxctl
status:
systemctl status edgeboxctl
log: start log: start
journalctl -fu edgeboxctl journalctl -fu edgeboxctl

View File

@ -11,7 +11,6 @@ import (
"github.com/edgebox-iot/edgeboxctl/internal/system" "github.com/edgebox-iot/edgeboxctl/internal/system"
"github.com/edgebox-iot/edgeboxctl/internal/utils" "github.com/edgebox-iot/edgeboxctl/internal/utils"
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
) )
// EdgeApp : Struct representing an EdgeApp in the system // EdgeApp : Struct representing an EdgeApp in the system
@ -19,7 +18,6 @@ type EdgeApp struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Experimental bool `json:"experimental"`
Status EdgeAppStatus `json:"status"` Status EdgeAppStatus `json:"status"`
Services []EdgeAppService `json:"services"` Services []EdgeAppService `json:"services"`
InternetAccessible bool `json:"internet_accessible"` InternetAccessible bool `json:"internet_accessible"`
@ -71,7 +69,6 @@ const optionsEnvFilename = "/edgeapp.env"
const authEnvFilename = "/auth.env" const authEnvFilename = "/auth.env"
const runnableFilename = "/.run" const runnableFilename = "/.run"
const appdataFoldername = "/appdata" const appdataFoldername = "/appdata"
const postInstallFilename = "/edgebox-postinstall.done"
const myEdgeAppServiceEnvFilename = "/myedgeapp.env" const myEdgeAppServiceEnvFilename = "/myedgeapp.env"
const defaultContainerOperationSleepTime time.Duration = time.Second * 10 const defaultContainerOperationSleepTime time.Duration = time.Second * 10
@ -89,7 +86,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
edgeAppName := ID edgeAppName := ID
edgeAppDescription := "" edgeAppDescription := ""
edgeAppExperimental := false
edgeAppOptions := []EdgeAppOption{} edgeAppOptions := []EdgeAppOption{}
edgeAppEnv, err := godotenv.Read(utils.GetPath(utils.EdgeAppsPath) + ID + envFilename) edgeAppEnv, err := godotenv.Read(utils.GetPath(utils.EdgeAppsPath) + ID + envFilename)
@ -103,9 +99,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
if edgeAppEnv["EDGEAPP_DESCRIPTION"] != "" { if edgeAppEnv["EDGEAPP_DESCRIPTION"] != "" {
edgeAppDescription = edgeAppEnv["EDGEAPP_DESCRIPTION"] edgeAppDescription = edgeAppEnv["EDGEAPP_DESCRIPTION"]
} }
if edgeAppEnv["EDGEAPP_EXPERIMENTAL"] == "true" {
edgeAppExperimental = true
}
} }
needsConfig := false needsConfig := false
@ -238,7 +231,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
ID: ID, ID: ID,
Name: edgeAppName, Name: edgeAppName,
Description: edgeAppDescription, Description: edgeAppDescription,
Experimental: edgeAppExperimental,
Status: GetEdgeAppStatus(ID), Status: GetEdgeAppStatus(ID),
Services: GetEdgeAppServices(ID), Services: GetEdgeAppServices(ID),
InternetAccessible: edgeAppInternetAccessible, InternetAccessible: edgeAppInternetAccessible,
@ -271,54 +263,22 @@ func IsEdgeAppInstalled(ID string) bool {
} }
func writeAppRunnableFiles(ID string) bool {
edgeAppPath := utils.GetPath(utils.EdgeAppsPath)
_, err := os.Stat(edgeAppPath + ID + runnableFilename)
if os.IsNotExist(err) {
_, err := os.Create(edgeAppPath + ID + runnableFilename)
if err != nil {
log.Fatal("Runnable file for EdgeApp could not be created!")
return false
}
// Check the block default apps option
blockDefaultAppsOption := utils.ReadOption("DASHBOARD_BLOCK_DEFAULT_APPS_PUBLIC_ACCESS")
if blockDefaultAppsOption != "yes" {
// Create myedgeapp.env file with default network URL
envFilePath := edgeAppPath + ID + myEdgeAppServiceEnvFilename
var networkURL string
domainName := utils.ReadOption("DOMAIN_NAME")
if domainName != "" {
networkURL = ID + "." + domainName
} else if diagnostics.GetReleaseVersion() == diagnostics.CLOUD_VERSION {
cluster := utils.ReadOption("CLUSTER")
username := utils.ReadOption("USERNAME")
if cluster != "" && username != "" {
networkURL = username + "-" + ID + "." + cluster
}
} else {
networkURL = ID + "." + system.GetHostname() + ".local" // default
}
env, _ := godotenv.Unmarshal("INTERNET_URL=" + networkURL)
err = godotenv.Write(env, envFilePath)
if err != nil {
log.Printf("Error creating myedgeapp.env file: %s", err)
// result = false
}
}
}
return true
}
func SetEdgeAppInstalled(ID string) bool { func SetEdgeAppInstalled(ID string) bool {
result := true result := true
edgeAppPath := utils.GetPath(utils.EdgeAppsPath)
_, err := os.Stat(edgeAppPath + ID + runnableFilename)
if os.IsNotExist(err) {
_, err := os.Create(edgeAppPath + ID + runnableFilename)
result = true
if err != nil {
log.Fatal("Runnable file for EdgeApp could not be created!")
result = false
}
if writeAppRunnableFiles(ID) {
buildFrameworkContainers() buildFrameworkContainers()
} else { } else {
@ -332,21 +292,6 @@ func SetEdgeAppInstalled(ID string) bool {
} }
func SetEdgeAppBulkInstalled(IDs []string) bool {
result := true
for _, ID := range IDs {
writeAppRunnableFiles(ID)
}
buildFrameworkContainers()
return result
}
func SetEdgeAppNotInstalled(ID string) bool { func SetEdgeAppNotInstalled(ID string) bool {
// Stop the app first // Stop the app first
@ -385,12 +330,6 @@ func SetEdgeAppNotInstalled(ID string) bool {
log.Println(err) log.Println(err)
} }
err = os.Remove(utils.GetPath(utils.EdgeAppsPath) + ID + postInstallFilename)
if err != nil {
result = false
log.Println(err)
}
buildFrameworkContainers() buildFrameworkContainers()
return result return result

View File

@ -56,10 +56,6 @@ type taskInstallEdgeAppArgs struct {
ID string `json:"id"` ID string `json:"id"`
} }
type taskInstallBulkEdgeAppsArgs struct {
IDS []string `json:"ids"`
}
type taskRemoveEdgeAppArgs struct { type taskRemoveEdgeAppArgs struct {
ID string `json:"id"` ID string `json:"id"`
} }
@ -303,18 +299,6 @@ func ExecuteTask(task Task) Task {
task.Result = sql.NullString{String: taskResult, Valid: true} task.Result = sql.NullString{String: taskResult, Valid: true}
} }
case "install_bulk_edgeapps":
log.Println("Installing Bulk EdgeApps...")
var args taskInstallBulkEdgeAppsArgs
err := json.Unmarshal([]byte(task.Args.String), &args)
if err != nil {
log.Printf("Error reading arguments of install_bulk_edgeapps task: %s", err)
} else {
taskResult := taskInstallBulkEdgeApps(args)
task.Result = sql.NullString{String: taskResult, Valid: true}
}
case "remove_edgeapp": case "remove_edgeapp":
log.Println("Removing EdgeApp...") log.Println("Removing EdgeApp...")
@ -991,19 +975,12 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
} }
func taskStartTunnel() string { func taskStartTunnel() string {
fmt.Println("Executing taskStartTunnel") fmt.Println("Executing taskStartTunnel")
system.StartService("cloudflared")
// Read tunnel status to check if cloudflare is configured domainName := utils.ReadOption("DOMAIN_NAME")
tunnelStatus := utils.ReadOption("TUNNEL_STATUS") status := "{\"status\": \"connected\", \"domain\": \"" + domainName + "\"}"
if tunnelStatus != "" { utils.WriteOption("TUNNEL_STATUS", status)
// Only start cloudflared if we have a tunnel configured return "{\"status\": \"ok\"}"
system.StartService("cloudflared")
domainName := utils.ReadOption("DOMAIN_NAME")
status := "{\"status\": \"connected\", \"domain\": \"" + domainName + "\"}"
utils.WriteOption("TUNNEL_STATUS", status)
}
return "{\"status\": \"ok\"}"
} }
func taskStopTunnel() string { func taskStopTunnel() string {
@ -1107,16 +1084,6 @@ func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
return string(resultJSON) return string(resultJSON)
} }
func taskInstallBulkEdgeApps(args taskInstallBulkEdgeAppsArgs) string {
fmt.Println("Executing taskInstallBulkEdgeApps for " + strings.Join(args.IDS, ", "))
// args.Apps is a list of edgeapp ids
edgeapps.SetEdgeAppBulkInstalled(args.IDS)
taskGetEdgeApps()
return "{\"status\": \"ok\"}"
}
func taskRemoveEdgeApp(args taskRemoveEdgeAppArgs) string { func taskRemoveEdgeApp(args taskRemoveEdgeAppArgs) string {
fmt.Println("Executing taskRemoveEdgeApp for " + args.ID) fmt.Println("Executing taskRemoveEdgeApp for " + args.ID)
@ -1323,7 +1290,6 @@ func taskCheckSystemUpdates() string {
func taskUpdateSystem() string { func taskUpdateSystem() string {
fmt.Println("Executing taskUpdateSystem") fmt.Println("Executing taskUpdateSystem")
system.ApplyUpdates() system.ApplyUpdates()
utils.WriteOption("LAST_UPDATE", strconv.FormatInt(time.Now().Unix(), 10))
return "{result: true}" return "{result: true}"
} }