aws-greengrass / aws-greengrass-nucleus

The Greengrass nucleus component provides functionality for device side orchestration of deployments and lifecycle management for execution of Greengrass components and applications. This includes features such as starting, stopping, and monitoring execution of components and apps, interprocess communication server for communication between components, component installation and configuration management.
Apache License 2.0
109 stars 44 forks source link

(Greengrass windows installer): Unable to set up Nucleus as a system service #1274

Closed KissBalazs closed 2 years ago

KissBalazs commented 2 years ago

Describe the bug I am trying to install AWS Greengrass on a (my own) windows machine, but it fails with the following output (after correctly configuring aws credentials and downloading the official packages).

To Reproduce

C:\...> java "-Droot=C:\greengrass\v2" "-Dlog.store=FILE" -jar .\GreengrassCore\lib\Greengrass.jar --aws-region eu-west-1 --thing-name Greengrass-balazs --thing-group-name GreengrassGroup --component-default-user ggc_user --provision true --setup-system-service true --deploy-dev-tools true

Expected behavior To successfully set up Nucleus.

Actual behavior This is the output I get:

C:\...> java "-Droot=C:\greengrass\v2" "-Dlog.store=FILE" -jar .\GreengrassCore\lib\Greengrass.jar --aws-region eu-west-1 --thing-name Greengrass-balazs --thing-group-name GreengrassGroup --component-default-user ggc_user --provision true --setup-system-service true --deploy-dev-tools true
Provisioning AWS IoT resources for the device with IoT Thing Name: [Greengrass-balazs]...
Found IoT policy "GreengrassV2IoTThingPolicy", reusing it
Creating keys and certificate...
Attaching policy to certificate...
Creating IoT Thing "Greengrass-balazs"...
Attaching certificate to IoT thing...
Successfully provisioned AWS IoT resources for the device with IoT Thing Name: [Greengrass-balazs]!
Adding IoT Thing [Greengrass-balazs] into Thing Group: [GreengrassGroup]...
IoT Thing Group "GreengrassGroup" already existed, reusing it
Successfully added Thing into Thing Group: [GreengrassGroup]
Setting up resources for aws.greengrass.TokenExchangeService ...
Attaching TES role policy to IoT thing...
No managed IAM policy found, looking for user defined policy...
IAM policy named "GreengrassV2TokenExchangeRoleAccess" already exists. Please attach it to the IAM role if not already
Configuring Nucleus with provisioned resource details...
Root CA file found at "C:\greengrass\v2\rootCA.pem". Contents will be preserved.
Downloading Root CA from "https://www.amazontrust.com/repository/AmazonRootCA1.pem"
Created device configuration
Successfully configured Nucleus with provisioned resource details!
Thing group exists, it could have existing deployment and devices, hence NOT creating deployment for Greengrass first party dev tools, please manually create a deployment if you wish to
Default user creation is only supported on Linux platforms, Greengrass will not make a user for you. Ensure that the user exists and password is stored. Continuing...
Unable to set up Nucleus as a system service

Environment

Additional context This is a fresh install, on a new machine. I would like to run it on my local environment for testing.

I've tried to follow the troubleshooting guide but it seems outdated?

The service won't start so there is no instance of it:

C:\Users\bk73027\Projects> Get-Service -Name "greengrass"
>>
Get-Service : Cannot find any service with service name 'greengrass'.
At line:1 char:1
+ Get-Service -Name "greengrass"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (greengrass:String) [Get-Service], S
   erviceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Comm
   ands.GetServiceCommand

And on the next step, I couldn't really understand what this is supposed to do :( :

C:\Users\bk73027\Projects> Set-Service -Name "greengrass" -Status stopped -StartupType enabled
>>
Set-Service : Cannot bind parameter 'StartupType'. Cannot convert value "enabled" to type "System.ServiceProcess.ServiceStartMode". Error: "Unable to match the identifier name enabled to a valid enumerator
name. Specify one of the following enumerator names and try again:
Boot, System, Automatic, Manual, Disabled"
At line:1 char:61
+ Set-Service -Name "greengrass" -Status stopped -StartupType enabled
+                                                             ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Service], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetServiceCommand
KissBalazs commented 2 years ago

In the logs, I can see the following in C:\greengrass\v2\logs~greengrass.log:

2022-08-03T11:54:49.086Z [INFO] (main) com.aws.greengrass.util.platforms.Platform: Getting platform instance com.aws.greengrass.util.platforms.windows.WindowsPlatform.. {}
2022-08-03T11:54:49.187Z [WARN] (Serialized listener processor) com.aws.greengrass.lifecyclemanager.KernelAlternatives: C:\greengrass\v2\alts\current. {}
2022-08-03T11:54:49.188Z [WARN] (Serialized listener processor) com.aws.greengrass.lifecyclemanager.KernelAlternatives: C:\greengrass\v2\alts\current. {}
2022-08-03T11:54:49.192Z [INFO] (main) com.aws.greengrass.lifecyclemanager.Kernel: No ongoing deployment detected. Proceed as default. {}
2022-08-03T11:54:49.252Z [INFO] (main) com.aws.greengrass.config.Configuration: config-loading. Read configuration from a file path. {path=C:\greengrass\v2\config\config.tlog}
2022-08-03T11:54:49.297Z [INFO] (main) com.aws.greengrass.lifecyclemanager.Kernel: effective-config-dump-complete. {file=C:\greengrass\v2\config\effectiveConfig.yaml}
2022-08-03T11:54:49.385Z [INFO] (main) com.aws.greengrass.deployment.DeviceConfiguration: Copy Nucleus artifacts to component store. {destination=C:\greengrass\v2\packages\artifacts-unarchived\aws.greengrass.Nucleus\2.7.0\aws.greengrass.nucleus, source=C:\Users\bk73027\Projects\GreengrassCore}
2022-08-03T11:54:49.460Z [ERROR] (main) com.aws.greengrass.deployment.DeviceConfiguration: Unable to set up Nucleus from build recipe file. {}
java.io.IOException: Failed to setup initial launch directory. Expecting loader script at: C:\greengrass\v2\alts\current\distro\bin\loader.cmd
    at com.aws.greengrass.lifecyclemanager.KernelAlternatives.relinkInitLaunchDir(KernelAlternatives.java:206)
    at com.aws.greengrass.deployment.DeviceConfiguration.initializeComponentStore(DeviceConfiguration.java:357)
    at com.aws.greengrass.deployment.DeviceConfiguration.initializeNucleusFromRecipe(DeviceConfiguration.java:388)
    at com.aws.greengrass.lifecyclemanager.Kernel.parseArgs(Kernel.java:645)
    at com.aws.greengrass.easysetup.GreengrassSetup.performSetup(GreengrassSetup.java:296)
    at com.aws.greengrass.easysetup.GreengrassSetup.main(GreengrassSetup.java:269)

2022-08-03T11:55:06.421Z [INFO] (main) com.aws.greengrass.lifecyclemanager.Kernel: effective-config-dump-complete. {file=C:\greengrass\v2\config\effectiveConfig.yaml}
2022-08-03T11:55:06.425Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: Waiting for services to shutdown. {}
2022-08-03T11:55:06.431Z [WARN] (main) com.aws.greengrass.lifecyclemanager.KernelAlternatives: C:\greengrass\v2\alts\current. {}
2022-08-03T11:55:06.433Z [ERROR] (main) com.aws.greengrass.util.orchestration.WinswUtils: winsw-setup. Failed to set up Windows service. {}
java.nio.file.FileAlreadyExistsException: C:\greengrass\v2\alts\current
    at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:87)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
    at java.base/sun.nio.fs.WindowsFileSystemProvider.createSymbolicLink(WindowsFileSystemProvider.java:585)
    at java.base/java.nio.file.Files.createSymbolicLink(Files.java:1059)
    at com.aws.greengrass.lifecyclemanager.KernelAlternatives.setupLinkToDirectory(KernelAlternatives.java:345)
    at com.aws.greengrass.lifecyclemanager.KernelAlternatives.setupInitLaunchDirIfAbsent(KernelAlternatives.java:178)
    at com.aws.greengrass.util.orchestration.WinswUtils.setupSystemService(WinswUtils.java:38)
    at com.aws.greengrass.easysetup.GreengrassSetup.performSetup(GreengrassSetup.java:328)
    at com.aws.greengrass.easysetup.GreengrassSetup.main(GreengrassSetup.java:269)

2022-08-03T11:55:06.433Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: system-shutdown. {main=null}
2022-08-03T11:55:06.443Z [INFO] (main) com.aws.greengrass.lifecyclemanager.Kernel: effective-config-dump-complete. {file=C:\greengrass\v2\config\effectiveConfig.yaml}
2022-08-03T11:55:06.444Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: Waiting for services to shutdown. {}
2022-08-03T11:55:06.444Z [INFO] (Serialized listener processor) com.aws.greengrass.lifecyclemanager.KernelLifecycle: executor-service-shutdown-initiated. {}
2022-08-03T11:55:06.445Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: Waiting for executors to shutdown. {}
2022-08-03T11:55:06.445Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: executor-service-shutdown-complete. {executor-terminated=true, scheduled-executor-terminated=true}
2022-08-03T11:55:06.445Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: context-shutdown-initiated. {}
2022-08-03T11:55:06.446Z [INFO] (main) com.aws.greengrass.lifecyclemanager.KernelLifecycle: 
KissBalazs commented 2 years ago

Following up the last comment, I have placed the script there:

C:\Users\bk73027\Projects> cat C:\greengrass\v2\alts\current\distro\bin\loader.cmd
@REM -------------------------------
@REM Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@REM SPDX-License-Identifier: Apache-2.0
@REM -------------------------------
@echo off
SETLOCAL EnableDelayedExpansion
 etc...

But it still writes the same error upon installing :(

MikeDombo commented 2 years ago

Hello,

The error from the log you provided is that that installation directory is not empty. Please completely delete c:/greengrass then retry.

KissBalazs commented 2 years ago

Thank you for the help. After deleting the folder, and starting everything again, it worked.

I think the problem might have been that I did not start the installation from my home folder, but from a different directory first.