Debian Codegraph @

ansible_collections/community/windows/plugins/modules/win_nssm.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2015, Heyo
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r'''
8 ---
9 module: win_nssm
10 short_description: Install a service using NSSM
11 description:
12 - Install a Windows service using the NSSM wrapper.
13 - NSSM is a service helper which doesn't suck. See U(https://nssm.cc/) for more information.
14 requirements:
15 - "nssm >= 2.24.0 # (install via M(chocolatey.chocolatey.win_chocolatey)) C(win_chocolatey: name=nssm)"
16 options:
17 name:
18 description:
19 - Name of the service to operate on.
20 type: str
21 required: true
22 state:
23 description:
24 - State of the service on the system.
25 type: str
26 choices: [ absent, present, started, stopped, restarted ]
27 default: present
28 application:
29 description:
30 - The application binary to run as a service
31 - Required when I(state) is C(present), C(started), C(stopped), or C(restarted).
32 type: path
33 executable:
34 description:
35 - The location of the NSSM utility (in case it is not located in your PATH).
36 type: path
37 default: nssm.exe
38 description:
39 description:
40 - The description to set for the service.
41 type: str
42 display_name:
43 description:
44 - The display name to set for the service.
45 type: str
46 working_directory:
47 description:
48 - The working directory to run the service executable from (defaults to the directory containing the application binary)
49 type: path
50 aliases: [ app_directory, chdir ]
51 stdout_file:
52 description:
53 - Path to receive output.
54 type: path
55 stderr_file:
56 description:
57 - Path to receive error output.
58 type: path
59 arguments:
60 description:
61 - Parameters to be passed to the application when it starts.
62 - This can be either a simple string or a list.
63 aliases: [ app_parameters_free_form ]
64 type: str
65 dependencies:
66 description:
67 - Service dependencies that has to be started to trigger startup, separated by comma.
68 type: list
69 elements: str
70 username:
71 description:
72 - User to be used for service startup.
73 - Group managed service accounts must end with C($).
74 - Before C(1.8.0), this parameter was just C(user).
75 type: str
76 aliases:
77 - user
78 password:
79 description:
80 - Password to be used for service startup.
81 - This is not required for the well known service accounts and group managed service accounts.
82 type: str
83 start_mode:
84 description:
85 - If C(auto) is selected, the service will start at bootup.
86 - C(delayed) causes a delayed but automatic start after boot.
87 - C(manual) means that the service will start only when another service needs it.
88 - C(disabled) means that the service will stay off, regardless if it is needed or not.
89 type: str
90 choices: [ auto, delayed, disabled, manual ]
91 default: auto
92 app_environment:
93 description:
94 - Key/Value pairs which will be added to the environment of the service application.
95 type: dict
96 version_added: 1.2.0
97 app_rotate_bytes:
98 description:
99 - NSSM will not rotate any file which is smaller than the configured number of bytes.
100 type: int
101 default: 104858
102 app_rotate_online:
103 description:
104 - If set to 1, nssm can rotate files which grow to the configured file size limit while the service is running.
105 type: int
106 choices:
107 - 0
108 - 1
109 default: 0
110 app_stop_method_console:
111 description:
112 - Time to wait after sending Control-C.
113 type: int
114 app_stop_method_skip:
115 description:
116 - To disable service shutdown methods, set to the sum of one or more of the numbers
117 - 1 - Don't send Control-C to the console.
118 - 2 - Don't send WM_CLOSE to windows.
119 - 4 - Don't send WM_QUIT to threads.
120 - 8 - Don't call TerminateProcess().
121 type: int
122 choices:
123 - 1
124 - 2
125 - 3
126 - 4
127 - 5
128 - 6
129 - 7
130 - 8
131 - 9
132 - 10
133 - 11
134 - 12
135 - 13
136 - 14
137 - 15
138 seealso:
139 - module: ansible.windows.win_service
140 notes:
141 - The service will NOT be started after its creation when C(state=present).
142 - Once the service is created, you can use the M(ansible.windows.win_service) module to start it or configure
143 some additionals properties, such as its startup type, dependencies, service account, and so on.
144 author:
145 - Adam Keech (@smadam813)
146 - George Frank (@georgefrank)
147 - Hans-Joachim Kliemeck (@h0nIg)
148 - Michael Wild (@themiwi)
149 - Kevin Subileau (@ksubileau)
150 - Shachaf Goldstein (@Shachaf92)
151 '''
152
153 EXAMPLES = r'''
154 - name: Install the foo service
155 community.windows.win_nssm:
156 name: foo
157 application: C:\windows\foo.exe
158
159 # This will yield the following command: C:\windows\foo.exe bar "true"
160 - name: Install the Consul service with a list of parameters
161 community.windows.win_nssm:
162 name: Consul
163 application: C:\consul\consul.exe
164 arguments:
165 - agent
166 - -config-dir=C:\consul\config
167
168 # This is strictly equivalent to the previous example
169 - name: Install the Consul service with an arbitrary string of parameters
170 community.windows.win_nssm:
171 name: Consul
172 application: C:\consul\consul.exe
173 arguments: agent -config-dir=C:\consul\config
174
175
176 # Install the foo service, and then configure and start it with win_service
177 - name: Install the foo service, redirecting stdout and stderr to the same file
178 community.windows.win_nssm:
179 name: foo
180 application: C:\windows\foo.exe
181 stdout_file: C:\windows\foo.log
182 stderr_file: C:\windows\foo.log
183
184 - name: Configure and start the foo service using win_service
185 ansible.windows.win_service:
186 name: foo
187 dependencies: [adf, tcpip]
188 username: foouser
189 password: secret
190 start_mode: manual
191 state: started
192
193 - name: Install a script based service and define custom environment variables
194 community.windows.win_nssm:
195 name: <ServiceName>
196 application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
197 arguments:
198 - <path-to-script>
199 - <script arg>
200 app_environment:
201 AUTH_TOKEN: <token value>
202 SERVER_URL: https://example.com
203 PATH: "<path-prepends>;{{ ansible_env.PATH }};<path-appends>"
204
205 - name: Remove the foo service
206 community.windows.win_nssm:
207 name: foo
208 state: absent
209 '''