|
67 | 67 | # This will allow the service to set a registry mirror.
|
68 | 68 | # defaults to undef
|
69 | 69 | #
|
| 70 | +# [*command*] |
| 71 | +# Command to run on the container |
| 72 | +# |
70 | 73 |
|
71 | 74 | define docker::services(
|
72 | 75 | Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
|
|
86 | 89 | Variant[String,Array,Undef] $workdir = undef,
|
87 | 90 | Variant[String,Array,Undef] $host_socket = undef,
|
88 | 91 | Variant[String,Array,Undef] $registry_mirror = undef,
|
| 92 | + Variant[String,Array,Undef] $command = undef, |
89 | 93 | ){
|
90 | 94 |
|
91 | 95 | include docker::params
|
|
101 | 105 | }
|
102 | 106 | }
|
103 | 107 |
|
| 108 | + if $::osfamily == 'windows' { |
| 109 | + $exec_environment = 'PATH=C:/Program Files/Docker/' |
| 110 | + $exec_timeout = 3000 |
| 111 | + $exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/'] |
| 112 | + $exec_provider = 'powershell' |
| 113 | + } else { |
| 114 | + $exec_environment = 'HOME=/root' |
| 115 | + $exec_path = ['/bin', '/usr/bin'] |
| 116 | + $exec_timeout = 0 |
| 117 | + $exec_provider = undef |
| 118 | + } |
| 119 | + |
| 120 | + |
104 | 121 | if $create {
|
105 | 122 | $docker_service_create_flags = docker_service_flags({
|
106 | 123 | detach => $detach,
|
|
116 | 133 | image => $image,
|
117 | 134 | host_socket => $host_socket,
|
118 | 135 | registry_mirror => $registry_mirror,
|
| 136 | + command => $command, |
119 | 137 | })
|
120 | 138 |
|
121 | 139 | $exec_create = "${docker_command} create --name ${docker_service_create_flags}"
|
122 |
| - $unless_create = "docker service ls | grep -w ${service_name}" |
| 140 | + $unless_create = "docker service ps ${service_name}" |
123 | 141 |
|
124 | 142 | exec { "${title} docker service create":
|
125 | 143 | command => $exec_create,
|
126 |
| - environment => 'HOME=/root', |
127 |
| - path => ['/bin', '/usr/bin'], |
128 |
| - timeout => 0, |
| 144 | + environment => $exec_environment, |
| 145 | + path => $exec_path, |
| 146 | + timeout => $exec_timeout, |
| 147 | + provider => $exec_provider, |
129 | 148 | unless => $unless_create,
|
130 | 149 | }
|
131 | 150 | }
|
|
151 | 170 |
|
152 | 171 | exec { "${title} docker service update":
|
153 | 172 | command => $exec_update,
|
154 |
| - environment => 'HOME=/root', |
155 |
| - path => ['/bin', '/usr/bin'], |
156 |
| - timeout => 0, |
| 173 | + environment => $exec_environment, |
| 174 | + path => $exec_path, |
| 175 | + provider => $exec_provider, |
| 176 | + timeout => $exec_timeout, |
157 | 177 | }
|
158 | 178 | }
|
159 | 179 |
|
|
168 | 188 |
|
169 | 189 | exec { "${title} docker service scale":
|
170 | 190 | command => $exec_scale,
|
171 |
| - environment => 'HOME=/root', |
172 |
| - path => ['/bin', '/usr/bin'], |
173 |
| - timeout => 0, |
| 191 | + environment => $exec_environment, |
| 192 | + path => $exec_path, |
| 193 | + timeout => $exec_timeout, |
| 194 | + provider => $exec_provider, |
174 | 195 | }
|
175 | 196 | }
|
176 | 197 |
|
177 | 198 | if $ensure == 'absent' {
|
178 | 199 | exec { "${title} docker service remove":
|
179 |
| - command => "docker service rm ${service_name}", |
180 |
| - onlyif => "docker service ls | grep -w ${service_name}", |
181 |
| - path => ['/bin', '/usr/bin'], |
| 200 | + command => "docker service rm ${service_name}", |
| 201 | + onlyif => "docker service ps ${service_name}", |
| 202 | + path => $exec_path, |
| 203 | + provider => $exec_provider, |
| 204 | + timeout => $exec_timeout, |
182 | 205 | }
|
183 | 206 | }
|
184 | 207 | }
|
0 commit comments