ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
193 stars 152 forks source link

win_nssm: Configure NSSM to preserve log files on service restart/crash #536

Open drfuzzyness opened 9 months ago

drfuzzyness commented 9 months ago
SUMMARY

It would be helpful if the community.windows.win_nssm module can expose NSSM's AppStdoutCreationDisposition and AppStderrCreationDisposition properties so that logs can be preserved when a service restarts. See "File Rotation Tab" on the NSSM usage page for a small amount of extra information.

ISSUE TYPE
COMPONENT NAME

community.windows.win_nssm

ADDITIONAL INFORMATION

This would pass an integer (2 or 4 are known valid options) directly to NSSM's service configuration. AppStdoutCreationDisposition and AppStderrCreationDisposition can be set independently, but follow similar logic. They should default to the current behavior of setting the -value to 2 (replace log files on restart).

Current behavior: https://github.com/ansible-collections/community.windows/blob/03e3af7baf85c2b14e558d3b9f1659712a3c6891/plugins/modules/win_nssm.ps1#L494-L495

Proposed configuration example:

tasks:
  - name: My Service
    community.windows.win_nssm:
      name: MyNssmService
      display_name: My NSSM Service
      application: C:\MyFolder\MyExecutable.exe
      app_directory: C:\MyFolder\
      arguments: --silent
      stdout_file: C:\MyFolder\Logs\stdout.log
      stderr_file: C:\MyFolder\Logs\stderr.log
      app_rotate_online: 1
      app_stdout_creation_disposition: 2 # replace file on every service restart
      app_stderr_creation_disposition: 4 # append to file instead of deleting file
      state: restarted
      app_environment:
        PORT: 3001
jamesdoran commented 6 months ago

+1 for this suggestion please. I'm using nssm to install hashicorp vault agent which requires redirection of stdout and stderr to get logging. If the service crashes and restarts, the previous logs are lost which makes debugging very hard.