Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running as a Windows Service #6372

Closed
2 tasks done
endocrimes opened this issue Sep 24, 2019 · 13 comments
Closed
2 tasks done

Support running as a Windows Service #6372

endocrimes opened this issue Sep 24, 2019 · 13 comments

Comments

@endocrimes
Copy link
Contributor

endocrimes commented Sep 24, 2019

Currently, Nomad supports running on Windows, but does not natively support running as a Windows Service, requiring tools like NSSM to be executable. Adding native support is valuable for many Nomad users and also to facilitate integration with our E2E suite.

The current blockers for native support are:

  • Support file logging in Nomad
  • Support some signal handling machinery (@angrycub to add more info)
@angrycub
Copy link
Contributor

I have current work on Service Control Manager wiring in #6220. This is a lift-and-shift from Consul's implementation.

@lmayorga1980
Copy link

@endocrimes can you share your nomad client service hcl file? I am having some issues on windows.

PS C:\nomad> Get-eventlog application -after (get-date).addhours(-1)

   Index Time          EntryType   Source                 InstanceID Message
   ----- ----          ---------   ------                 ---------- -------
     463 Oct 01 16:12  Warning     nssm                   2147484682 Service Nomad ran for less than 1500 millisecon...
     462 Oct 01 16:12  Information nssm                   1073742838 Service Nomad action for exit code 1 is Restart...
     461 Oct 01 16:12  Information nssm                   1073742851 Killing PID 2692 in process tree of PID 2692 be...
     460 Oct 01 16:12  Information nssm                   1073742847 Killing process tree of process 2692 for servic...
     459 Oct 01 16:12  Information nssm                   1073742837 Program C:\nomad\nomad.exe for service Nomad ex...
     458 Oct 01 16:12  Information nssm                   1073742832 Started C:\nomad\nomad.exe agent "-config C:\no...
     457 Oct 01 16:11  Warning     nssm                   2147484682 Service Nomad ran for less than 1500 millisecon...
     456 Oct 01 16:11  Information nssm                   1073742838 Service Nomad action for exit code 1 is Restart...
     455 Oct 01 16:11  Information nssm                   1073742851 Killing PID 3484 in process tree of PID 3484 be...
     454 Oct 01 16:11  Information nssm                   1073742847 Killing process tree of process 3484 for servic...
     453 Oct 01 16:11  Information nssm                   1073742837 Program C:\nomad\nomad.exe for service Nomad ex...
     452 Oct 01 16:11  Information nssm                   1073742832 Started C:\nomad\nomad.exe agent "-config C:\no...
     451 Oct 01 16:11  Warning     nssm                   2147484682 Service Nomad ran for less than 1500 millisecon...
     450 Oct 01 16:11  Information nssm                   1073742838 Service Nomad action for exit code 1 is Restart...
     449 Oct 01 16:11  Information nssm                   1073742851 Killing PID 3932 in process tree of PID 3932 be...
     448 Oct 01 16:11  Information nssm                   1073742847 Killing process tree of process 3932 for servic...
     447 Oct 01 16:11  Information nssm                   1073742837 Program C:\nomad\nomad.exe for service Nomad ex...

windows.hcl

# Increase log verbosity
log_level = "DEBUG"

# Setup data dir
data_dir = "C:\\nomad\\data_dir"

# Give the agent a unique name. Defaults to hostname
name = "{{ansible_hostname}}"

# Enable the client
client {
    enabled = true

    # For demo assume we are talking to server1. For production,
    # this should be like "nomad.service.consul:4647" and a system
    # like Consul used for service discovery.
    servers = ["{{nomad_server}}:4647"]

  options = {
    "driver.raw_exec.enable" = "1"
  }
}

# Modify our port to avoid a collision with server1
ports {
    http = 5656
}

@endocrimes
Copy link
Contributor Author

@lmayorga1980 I don't personally have an NSSM setup to hand, @angrycub might though

@lmayorga1980
Copy link

Having a standard config for windows under the docs would be nice.

@angrycub
Copy link
Contributor

angrycub commented Oct 1, 2019

As we bring native service integration to Nomad, we will definitely improve the documentation around Windows and Windows configurations.

Because Nomad logs to stdout and stderr, you would need to redirect those in order to inspect the logging. This is another improvement planned as part of this work effort. However, in the meantime, you can add redirection to your NSSM configuration via the GUI or with the following commands:

nssm set Nomad AppStdout C:\Nomad\logs\nomad.log
nssm set Nomad AppStderr C:\Nomad\logs\nomad.log

Screen Shot 2019-10-01 at 3 48 22 PM

Set the paths and service name to appropriate values for your environment. Once set, restart your nomad service. You should then be able to inspect the logs for any specific errors.

@lmayorga1980
Copy link

I will definitely try that approach. Seems like the agent works from cmd.exe manually but the service process is killed for some reason.

@lmayorga1980
Copy link

@angrycub ,

Thank you 👍 , sharing my sample configuration for nomad on windows.

windows.hcl

# Increase log verbosity
log_level = "DEBUG"

# Setup data dir
data_dir = "C:\\nomad\\data_dir"

# Give the agent a unique name. Defaults to hostname
name = "{{ansible_hostname}}"

# Enable the client
client {
    enabled = true

    # For demo assume we are talking to server1. For production,
    # this should be like "nomad.service.consul:4647" and a system
    # like Consul used for service discovery.
    servers = ["{{nomad_server}}:4647"]

  options = {
    "driver.raw_exec.enable" = "1"
  }
}

# Modify our port to avoid a collision with server1
ports {
    http = 5656
}

ansible definition

    - name: Install the Nomad service with a list of parameters
      win_nssm:
        name: Nomad
        display_name: Hashicorp Nomad
        application: C:\nomad\nomad.exe
        stderr_file: c:\nomad\logs\stderr.log
        stdout_file: c:\nomad\logs\stdout.log
        arguments:
          - agent
          - -config=C:\nomad\config\windows.hcl

@tgross
Copy link
Member

tgross commented Nov 14, 2019

Closed by #6220

@tgross tgross closed this as completed Nov 14, 2019
@lmayorga1980
Copy link

@endocrimes 👍

@basickarl
Copy link

Seriously guys: https://nomadproject.io/guides/install/windows-service/ That should be updated. I tried doing what it said there and it just did not work. Will be implementing my own NSSM wrapper for Nomad.

@tgross
Copy link
Member

tgross commented Feb 13, 2020

Hi @basickarl that's the approach we use for our Windows e2e test suite, so if you're running into problems I'd suggest opening a new GitHub issue explaining the problems you're having in more detail.

@angrycub
Copy link
Contributor

It's also important to note that the Service Control Manager integration was added in 0.10.2.

agent: Added support for running under Windows Service Manager [GH-6220]

Versions before that will need to use NSSM to wrap the service.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants