[OpenNESS-dev] How to run a shell script from the edgenode code

Mokhtar, Amr amr.mokhtar at intel.com
Thu Apr 16 13:54:43 UTC 2020


Not sure if I am following..

Probably worth checking if all the X-term-related env variables are properly available in the container before testing the golang changes.
Try to login to the running container (through `docker exec -it ` command) and see if the variables are available.

From: Ashish Saxena <Ashish.Saxena at hsc.com>
Sent: Thursday 16 April 2020 12:32
To: Mokhtar, Amr <amr.mokhtar at intel.com>
Cc: developer at mail.openness.org
Subject: RE: How to run a shell script from the edgenode code

Hi Amr,

Thanks for replying.
Actually I am passing xauth volumes to the application also .
I am setting shared_memory and network fields also into the application container.

Following is my code:
diff --git a/pkg/eva/eva_deploy.go b/pkg/eva/eva_deploy.go
index 2d508d6..32332a9 100644
--- a/pkg/eva/eva_deploy.go
+++ b/pkg/eva/eva_deploy.go
@@ -15,6 +15,7 @@ import (
        "path"
        "path/filepath"
        "time"
+       //"bytes"

        "math"
        "regexp"
@@ -624,6 +625,18 @@ func processEAC(EACJson string, EACHandlers map[string]EACHandler,
                }
        }
}
+/*
+func Shellout(command string) (error, string, string) {
+    var stdout bytes.Buffer
+    var stderr bytes.Buffer
+    const ShellToUse = "bash"
+    cmd := exec.Command(ShellToUse, "-c", command)
+    cmd.Stdout = &stdout
+    cmd.Stderr = &stderr
+    err := cmd.Run()
+    return err, stdout.String(), stderr.String()
+}
+*/

func (s *DeploySrv) syncDeployContainer(ctx context.Context,
        dapp *metadata.DeployedApp) {
@@ -674,9 +687,41 @@ func (s *DeploySrv) syncDeployContainer(ctx context.Context,
                Memory:   int64(dapp.App.Memory) * 1024 * 1024,
                NanoCPUs: nanoCPUs,
        }
+/*
+            path_to_script := "/opt/edgenode/echo_display.sh"
+            err, display, errout := Shellout(path_to_script)
+            if err != nil {
+            log.Errf("error: %v\n", err)
+            }
+*/
+           cmd := exec.Command("/opt/edgenode/echo_display.sh")
+
+               out, err := cmd.CombinedOutput()
+               if err != nil {
+                log.Errf("cmd.Run() failed with %s\n", err)
+             }

+            display := string(out)
+
+            log.Infof("display variable= %v\n",display)
+            log.Errf("then error: %v\n", err)
+            final_display2 := "DISPLAY="+display
+            final_display := strings.TrimSuffix(final_display2,"\n")
+            log.Infof("final display variable= %v\n", final_display)
+
+
        hostCfg := container.HostConfig{
                Resources: resources,
-               CapAdd:    []string{"NET_ADMIN"}}
+               CapAdd:    []string{"NET_ADMIN"},
+               Binds: []string{"/root/.Xauthority:/root/.Xauthority:rw"},
+                NetworkMode:   "host",
+                ShmSize: 1073741824,
+        }
+

        if s.cfg.UseCNI {
                infraCtrID, cniErr := cni.CreateInfrastructureContainer(ctx, dapp)
@@ -690,6 +735,7 @@ func (s *DeploySrv) syncDeployContainer(ctx context.Context,

        containerCfg := container.Config{
                Image: dapp.App.Id,
+               Env:   []string{final_display},
        }

        // Update hostCfg and containCfg based on EAC configuration



I am getting other fields ,and I can verify that from  running docker inspect command. On the deployed application.
But I am not able to set only the DISPLAY variable.
Can you please help me on setting the same.

Thanks and Regards,
Ashish


From: Mokhtar, Amr <amr.mokhtar at intel.com<mailto:amr.mokhtar at intel.com>>
Sent: Thursday, April 16, 2020 4:48 PM
To: Ashish Saxena <Ashish.Saxena at hsc.com<mailto:Ashish.Saxena at hsc.com>>
Cc: developer at mail.openness.org<mailto:developer at mail.openness.org>
Subject: RE: How to run a shell script from the edgenode code


CAUTION:This email originated from an external organization
Hi Ashish,
In order to get graphic support passed through to the docker, passing DISPLAY env variable alone is not enough. You need to share xauth volumes.
The best way to get around this is that after you deploy the docker using EVA, kill it and re-run it manually with the same name as was originally given by EVA.
When starting the docker manually, you should run it as we do with the client-sim -> https://github.com/open-ness/edgeapps/blob/master/applications/openvino/clientsim/run-docker.sh<https://ind01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fopen-ness%2Fedgeapps%2Fblob%2Fmaster%2Fapplications%2Fopenvino%2Fclientsim%2Frun-docker.sh&data=02%7C01%7C%7C5434a98dc92c4f7f658708d7e1f7d877%7Ca65543b9ae9349b580f00b85821adc50%7C1%7C0%7C637226326919780456&sdata=di9CICf%2FoBGjJkWIQsaILFvP%2BzUo3UJJCIQURN8xPq8%3D&reserved=0>

-Amr

From: Developer <developer-bounces at mail.openness.org<mailto:developer-bounces at mail.openness.org>> On Behalf Of Ashish Saxena via Developer
Sent: Thursday 16 April 2020 12:04
To: developer at mail.openness.org<mailto:developer at mail.openness.org>
Subject: [OpenNESS-dev] How to run a shell script from the edgenode code

Hi Openness Team,

I have deployed  Openness version 20.03 controller and node on my setup.
I am deploying one application on the edgenode , and want to give DISPLAY as environment variable to the application.
For this , I have modified the code of eva_deploy.go file as follows:
pkg/eva/eva_deploy.go_diff

func (s *DeploySrv) syncDeployContainer(ctx context.Context,
        dapp *metadata.DeployedApp) {
@@ -674,9 +687,41 @@ func (s *DeploySrv) syncDeployContainer(ctx context.Context,
                Memory:   int64(dapp.App.Memory) * 1024 * 1024,
                NanoCPUs: nanoCPUs,
        }
+          cmd := exec.Command("/opt/edgenode/echo_display.sh")
+
+               out, err := cmd.CombinedOutput()
+               if err != nil {
+                log.Errf("cmd.Run() failed with %s\n", err)
+               }
+               //fmt.Printf("combined out:\n%s\n", string(out))
+
+
+
+
+            display := string(out)
+
+            final_display2 := "DISPLAY="+display
+            final_display := strings.TrimSuffix(final_display2,"\n")
+            log.Infof("final display variable= %v\n", final_display)
+
+
        if s.cfg.UseCNI {
                infraCtrID, cniErr := cni.CreateInfrastructureContainer(ctx, dapp)
@@ -690,6 +735,7 @@ func (s *DeploySrv) syncDeployContainer(ctx context.Context,

        containerCfg := container.Config{
                Image: dapp.App.Id,
+               Env:   []string{final_display},
        }

        // Update hostCfg and containCfg based on EAC configuration


And the script  /opt/edgenode/echo_display.sh is as follows:
#!/bin/sh
echo $DISPLAY

The code is compiling fine and edgenode has been deployed successfully, but while deploying the application , I am not getting the DISPLAY string and edgenode logs for the same is :
mec-app-edgednssvr  | <134>Apr 16 10:31:27 edgednssvr[1]: [main] Heartbeat
appliance_1         | <131>Apr 16 09:57:01 appliance[81734]: [eva] cmd.Run() failed with fork/exec /opt/edgenode/echo_display.sh: no such file or directory
nts                 | NES: [INFO] done
eaa_1               | <134>Apr 16 10:23:27 eaa[6]: [eaa] Heartbeat
mec-app-edgednssvr  | <134>Apr 16 10:32:27 edgednssvr[1]: [main] Heartbeat
nts                 | NES: [INFO] DPDK port: 1 PCI address: 0000:60:00.1 MAC address: ac:1f:6b:6b:49:85
appliance_1         | <134>Apr 16 09:57:01 appliance[81734]: [eva] display variable=

It looks like the script is not visible while deploying the application , which is actually present at the path , and I have make sure that the script exists at that path.

How can I  run that shell script from the code to meet our objective?

Thanks and Regards,
Ashish

DISCLAIMER: This electronic message and all of its contents, contains information which is privileged, confidential or otherwise protected from disclosure. The information contained in this electronic mail transmission is intended for use only by the individual or entity to which it is addressed. If you are not the intended recipient or may have received this electronic mail transmission in error, please notify the sender immediately and delete / destroy all copies of this electronic mail transmission without disclosing, copying, distributing, forwarding, printing or retaining any part of it. Hughes Systique accepts no responsibility for loss or damage arising from the use of the information transmitted by this email including damage from virus.
DISCLAIMER: This electronic message and all of its contents, contains information which is privileged, confidential or otherwise protected from disclosure. The information contained in this electronic mail transmission is intended for use only by the individual or entity to which it is addressed. If you are not the intended recipient or may have received this electronic mail transmission in error, please notify the sender immediately and delete / destroy all copies of this electronic mail transmission without disclosing, copying, distributing, forwarding, printing or retaining any part of it. Hughes Systique accepts no responsibility for loss or damage arising from the use of the information transmitted by this email including damage from virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openness.org/pipermail/developer/attachments/20200416/1d5e15bf/attachment-0001.html>


More information about the Developer mailing list