Unable to use greengrass-cli

0

Hi,
I am trying to use local deployment with greengrass-cli.
I added aws.greengrass.Cli component in my deployment with my two other components and deployed it to my CoreDevice. Result came back COMPLETED.

When I typed "greengrass-cli help", bash came back with "Command not found".
I tried "greengrass-cli help" at two different directories. Both gave me "Command not found".

  1. pi@raspberrypi:/greengrass/v2/bin $
  2. pi@raspberrypi:/greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin $

pi@raspberrypi:/greengrass/v2/bin $ has a symbolic link of greengrass-cli as shown below. The linked directory has "greengrass-cli".

pi@raspberrypi:/greengrass/v2/bin $ ls -la
lrwxrwxrwx 1 root root 139 Feb 11 13:50 greengrass-cli -> /greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin/greengrass-cli

pi@raspberrypi:/greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin $ ls -la
-rwxr-xr-x 1 root root 711 Feb 11 13:50 greengrass-cli

I attached a log file of greengrass.log. The log for com.aws.greengrass.cli ends at line 424 with newState=RUNNING.

What am I doing wrong? Could you help me on this?

jx2900
asked 3 years ago921 views
5 Answers
1

Please run the CLI as root and set your JAVA_HOME to /usr/lib/jvm/java-8-openjdk-armhf/jre/

AWS
EXPERT
answered 3 years ago
0

You won't be able to simply run greengrass-cli since that won't be in your PATH environment variable. You should instead specify the path to the executable such as <gg-root>/bin/greengrass-cli help . You can choose to add the Greengrass binary directory into your PATH, but Greengrass doesn't do that for you.

Cheers,
Michael Dombrowski

AWS
EXPERT
answered 3 years ago
0

Hi Michael,
I have already tried both of your suggestions as I mentioned in my first message.
(1) <gg-root>/bin/greengrass-cli help <--------Didn't worked
My gg-root is /greengrass/v2, so I did this, /greengrass/v2/bin/greengrass-cli help
(2) Executable file <-----Didn't work
I moved into the directory of the executable file and tried
I even tried sudo greengrass-cli help at both (1) and (2) and didn't work.

I even tried as below as suggested in aws's document. I tried --ggcRootPath option. (Please see the below.)

Any solution?

----I tried them all ------------------------------------
pi@raspberrypi:~ $ greengrass-cli --ggcRootPath /greengrass/v2 help
-bash: greengrass-cli: command not found

pi@raspberrypi:~ $ greengrass-cli --ggcRootPath /greengrass/v2/bin help
-bash: greengrass-cli: command not found

pi@raspberrypi:~ $ ls -la /greengrass/v2/bin
lrwxrwxrwx 1 root root 139 Feb 11 16:30 greengrass-cli -> /greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin/greengrass-cli

pi@raspberrypi:~ $ greengrass-cli --ggcRootPath /greengrass/v2/bin
-bash: greengrass-cli: command not found

pi@raspberrypi:~ $ greengrass-cli --ggcRootPath /greengrass/v2
-bash: greengrass-cli: command not found

pi@raspberrypi:/greengrass/v2/bin $ greengrass-cli
-bash: greengrass-cli: command not found

pi@raspberrypi:/greengrass/v2/bin $ greengrass-cli help
-bash: greengrass-cli: command not found

pi@raspberrypi:/greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin $ greengrass-cli
-bash: greengrass-cli: command not found

pi@raspberrypi:/greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin $ greengrass-cli help
-bash: greengrass-cli: command not found

-----------------And I see that it is executable by other user---------------------
pi@raspberrypi:/greengrass/v2/packages/artifacts-unarchived/aws.greengrass.Cli/2.0.4/aws.greengrass.cli.client/cliclient-2.0.0-SNAPSHOT/bin $ ls -laA
total 4
-rwxr-xr-x 1 root root 711 Feb 11 16:29 greengrass-cli

Edited by: jx2900 on Feb 11, 2021 12:40 AM

I added /greengrass/v2/bin to PATH.
This seems that greengrass-cli execution file is responding.

pi@raspberrypi:/ $ echo $PATH
/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/greengrass/v2:/greengrass/v2/bin

pi@raspberrypi:/ $ greengrass-cli help
/greengrass/v2/bin/greengrass-cli: line 28: /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java/bin/java: Not a directory

But the greengrass-cli addes "/bin/java" again. This caused "Not d directory" error.
So I commented out two lines in greengrass-cli. Now, greengrass-cli is responding as it supposed to respond. But is there any way to prevent this from keeping happening. Why did it add "/java/bin" again?

-----------Commented out-----------Now working-----------
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=which java
#else

JAVACMD="$JAVA_HOME/bin/java"

fi

----My JAVA_HOME is---------I didn't specify

pi@raspberrypi:/ $ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java

jx2900
answered 3 years ago
0

I see. That works. Thank you again, Michael,

jx2900
answered 3 years ago
0

Hope that below helps other people who are new to greengrass-cli like me.

  1. I added /greengrass/v2/bin to PATH.
    1-1. root@raspberrypi:/# PATH=$PATH:/greengrass/v2/bin <----this is gone when you reboot raspi.
    OR
    1-2. I added below in /etc/profile just above "export PATH" and just below fi. I did this as root.
    PATH=$PATH:/greengrass/v2/bin

  2. I deleted /java/bin from JAVA_HOME in /etc/environment.

    • In my case, greengrass-cli added /java/bin to JAVA_HOME.
      When greengrass-cli command is called, greengrass-cli tried to call java
      from /usr/lib/jvm/java-8-openjdk-armhf/jre/java/bin/java/bin.
      It duplicated "/java/bin" and caused error.

This solved my problem as Michael told me as long as I run greengrass-cli as root user.

Edited by: jx2900 on Feb 11, 2021 6:19 PM

jx2900
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions