Compare commits
No commits in common. "80fc8b40cd1623bce4fe27ca073af6bb336830f7" and "a8b1da4b7c97bbda2b43ae735076baa866c4c563" have entirely different histories.
80fc8b40cd
...
a8b1da4b7c
3
Makefile
3
Makefile
|
@ -69,8 +69,5 @@ start:
|
|||
stop:
|
||||
systemctl stop edgeboxctl
|
||||
|
||||
status:
|
||||
systemctl status edgeboxctl
|
||||
|
||||
log: start
|
||||
journalctl -fu edgeboxctl
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/system"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
)
|
||||
|
||||
// EdgeApp : Struct representing an EdgeApp in the system
|
||||
|
@ -19,7 +18,6 @@ type EdgeApp struct {
|
|||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Experimental bool `json:"experimental"`
|
||||
Status EdgeAppStatus `json:"status"`
|
||||
Services []EdgeAppService `json:"services"`
|
||||
InternetAccessible bool `json:"internet_accessible"`
|
||||
|
@ -71,7 +69,6 @@ const optionsEnvFilename = "/edgeapp.env"
|
|||
const authEnvFilename = "/auth.env"
|
||||
const runnableFilename = "/.run"
|
||||
const appdataFoldername = "/appdata"
|
||||
const postInstallFilename = "/edgebox-postinstall.done"
|
||||
const myEdgeAppServiceEnvFilename = "/myedgeapp.env"
|
||||
const defaultContainerOperationSleepTime time.Duration = time.Second * 10
|
||||
|
||||
|
@ -89,7 +86,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
|||
|
||||
edgeAppName := ID
|
||||
edgeAppDescription := ""
|
||||
edgeAppExperimental := false
|
||||
edgeAppOptions := []EdgeAppOption{}
|
||||
|
||||
edgeAppEnv, err := godotenv.Read(utils.GetPath(utils.EdgeAppsPath) + ID + envFilename)
|
||||
|
@ -103,9 +99,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
|||
if edgeAppEnv["EDGEAPP_DESCRIPTION"] != "" {
|
||||
edgeAppDescription = edgeAppEnv["EDGEAPP_DESCRIPTION"]
|
||||
}
|
||||
if edgeAppEnv["EDGEAPP_EXPERIMENTAL"] == "true" {
|
||||
edgeAppExperimental = true
|
||||
}
|
||||
}
|
||||
|
||||
needsConfig := false
|
||||
|
@ -238,7 +231,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
|||
ID: ID,
|
||||
Name: edgeAppName,
|
||||
Description: edgeAppDescription,
|
||||
Experimental: edgeAppExperimental,
|
||||
Status: GetEdgeAppStatus(ID),
|
||||
Services: GetEdgeAppServices(ID),
|
||||
InternetAccessible: edgeAppInternetAccessible,
|
||||
|
@ -271,53 +263,21 @@ 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 {
|
||||
|
||||
result := true
|
||||
edgeAppPath := utils.GetPath(utils.EdgeAppsPath)
|
||||
|
||||
if writeAppRunnableFiles(ID) {
|
||||
_, 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
|
||||
}
|
||||
|
||||
buildFrameworkContainers()
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
// Stop the app first
|
||||
|
@ -385,12 +330,6 @@ func SetEdgeAppNotInstalled(ID string) bool {
|
|||
log.Println(err)
|
||||
}
|
||||
|
||||
err = os.Remove(utils.GetPath(utils.EdgeAppsPath) + ID + postInstallFilename)
|
||||
if err != nil {
|
||||
result = false
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
buildFrameworkContainers()
|
||||
|
||||
return result
|
||||
|
|
|
@ -56,10 +56,6 @@ type taskInstallEdgeAppArgs struct {
|
|||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type taskInstallBulkEdgeAppsArgs struct {
|
||||
IDS []string `json:"ids"`
|
||||
}
|
||||
|
||||
type taskRemoveEdgeAppArgs struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
@ -303,18 +299,6 @@ func ExecuteTask(task Task) Task {
|
|||
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":
|
||||
|
||||
log.Println("Removing EdgeApp...")
|
||||
|
@ -991,19 +975,12 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
|
|||
}
|
||||
|
||||
func taskStartTunnel() string {
|
||||
fmt.Println("Executing taskStartTunnel")
|
||||
|
||||
// Read tunnel status to check if cloudflare is configured
|
||||
tunnelStatus := utils.ReadOption("TUNNEL_STATUS")
|
||||
if tunnelStatus != "" {
|
||||
// Only start cloudflared if we have a tunnel configured
|
||||
system.StartService("cloudflared")
|
||||
domainName := utils.ReadOption("DOMAIN_NAME")
|
||||
status := "{\"status\": \"connected\", \"domain\": \"" + domainName + "\"}"
|
||||
utils.WriteOption("TUNNEL_STATUS", status)
|
||||
}
|
||||
|
||||
return "{\"status\": \"ok\"}"
|
||||
fmt.Println("Executing taskStartTunnel")
|
||||
system.StartService("cloudflared")
|
||||
domainName := utils.ReadOption("DOMAIN_NAME")
|
||||
status := "{\"status\": \"connected\", \"domain\": \"" + domainName + "\"}"
|
||||
utils.WriteOption("TUNNEL_STATUS", status)
|
||||
return "{\"status\": \"ok\"}"
|
||||
}
|
||||
|
||||
func taskStopTunnel() string {
|
||||
|
@ -1107,16 +1084,6 @@ func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
|
|||
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 {
|
||||
fmt.Println("Executing taskRemoveEdgeApp for " + args.ID)
|
||||
|
||||
|
@ -1323,7 +1290,6 @@ func taskCheckSystemUpdates() string {
|
|||
func taskUpdateSystem() string {
|
||||
fmt.Println("Executing taskUpdateSystem")
|
||||
system.ApplyUpdates()
|
||||
utils.WriteOption("LAST_UPDATE", strconv.FormatInt(time.Now().Unix(), 10))
|
||||
return "{result: true}"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue