|
24 | 24 |
|
25 | 25 | include ::systemd
|
26 | 26 |
|
27 |
| - validate_re($ensure, [ '^present$', '^absent$' ], |
28 |
| - "systemd::unit::${name}::ensure is invalid and does not match the regex.") |
| 27 | + if is_string($ensure) { |
| 28 | + validate_re($ensure, [ '^present$', '^absent$' ], |
| 29 | + "systemd::unit::${name}::ensure does not match the regex.") |
| 30 | + } else { |
| 31 | + fail("systemd::unit::${name}::ensure is not a string.") |
| 32 | + } |
29 | 33 |
|
30 | 34 | validate_absolute_path($systemd_path)
|
31 | 35 |
|
32 |
| - if $unit_after != undef { |
33 |
| - validate_string($unit_after) |
| 36 | + if $unit_after != undef and is_string($unit_after) == false { |
| 37 | + fail("systemd::${name}::unit::unit_after is not a string") |
34 | 38 | }
|
35 |
| - if $unit_before != undef { |
36 |
| - validate_string($unit_before) |
| 39 | + if $unit_before != undef and is_string($unit_before) == false { |
| 40 | + fail("systemd::${name}::unit::unit_before is not a string") |
37 | 41 | }
|
38 |
| - if $unit_description != undef { |
39 |
| - validate_string($unit_description) |
| 42 | + if $unit_description != undef and is_string($unit_description) == false { |
| 43 | + fail("systemd::${name}::unit::unit_description is not a string") |
40 | 44 | }
|
41 |
| - if $environment != undef { |
42 |
| - validate_string($environment) |
| 45 | + if $environment != undef and is_string($environment) == false { |
| 46 | + fail("systemd::${name}::unit::environment is not a string") |
43 | 47 | }
|
44 |
| - if $group != undef { |
45 |
| - validate_string($group) |
| 48 | + if $group != undef and is_string($group) == false { |
| 49 | + fail("systemd::${name}::unit::group is not a string") |
46 | 50 | }
|
47 |
| - if $user != undef { |
48 |
| - validate_string($user) |
| 51 | + if $user != undef and is_string($user) == false { |
| 52 | + fail("systemd::${name}::unit::user is not a string") |
49 | 53 | }
|
50 |
| - if $workingdirectory != undef { |
51 |
| - validate_string($workingdirectory) |
| 54 | + if $service_restart != undef and is_string($service_restart) == false { |
| 55 | + fail("systemd::${name}::unit::restart is not a string") |
52 | 56 | }
|
53 |
| - validate_re($service_type, [ '^simple$', '^forking$', '^oneshot$', '^dbus$', '^notify$', '^idle$' ], |
54 |
| - "systemd::unit::${name}::ensure is invalid and does not match the regex.") |
55 |
| - if $service_timeoutstartsec != undef { |
56 |
| - if is_string($service_timeoutstartsec) { |
57 |
| - $service_timeoutstartsec_real = 0 + $service_timeoutstartsec # str2integer |
58 |
| - } else { |
59 |
| - $service_timeoutstartsec_real = $service_timeoutstartsec |
60 |
| - validate_integer($service_timeoutstartsec_real) |
61 |
| - } |
| 57 | + if $service_execstart != undef and is_string($service_execstart) == false { |
| 58 | + fail("systemd::${name}::unit::service_execstart is not a string") |
62 | 59 | }
|
63 |
| - if $service_restart != undef { |
64 |
| - validate_string($service_restart) |
| 60 | + if $service_execstop != undef and is_string($service_execstop) == false { |
| 61 | + fail("systemd::${name}::unit::service_execstop is not a string") |
65 | 62 | }
|
66 |
| - if $service_restartsec != undef { |
67 |
| - validate_string($service_restartsec) |
| 63 | + if $install_wantedby != undef and is_string($install_wantedby) == false { |
| 64 | + fail("systemd::${name}::unit::install_wantedby is not a string") |
68 | 65 | }
|
69 |
| - if $service_execstartpre != undef { |
70 |
| - validate_array($service_execstartpre) |
| 66 | + if $workingdirectory != undef and is_string($workingdirectory) == false { |
| 67 | + fail("systemd::${name}::unit::workingdirectory is not a string") |
71 | 68 | }
|
72 |
| - if $service_execstart != undef { |
73 |
| - validate_string($service_execstart) |
| 69 | + |
| 70 | + if $service_execstartpre != undef and is_array($service_execstartpre) == false { |
| 71 | + fail("systemd::${name}::unit::service_execstartpre is not an Array") |
74 | 72 | }
|
75 |
| - if $service_execstop != undef { |
76 |
| - validate_string($service_execstop) |
| 73 | + |
| 74 | + if is_string($service_type) { |
| 75 | + validate_re($service_type, [ '^simple$', '^forking$', '^oneshot$', '^dbus$', '^notify$', '^idle$' ], |
| 76 | + "systemd::unit::${name}::ensure does not match the regex.") |
| 77 | + } else { |
| 78 | + fail("systemd::unit::${name}::ensure is not a string.") |
77 | 79 | }
|
78 |
| - if $install_wantedby != undef { |
79 |
| - validate_string($install_wantedby) |
| 80 | + |
| 81 | + if $service_timeoutstartsec != undef { |
| 82 | + if is_string($service_timeoutstartsec) { |
| 83 | + validate_re($service_timeoutstartsec, [ '^infinity$', '(([0-9]+h(our)?)?([0-9]+m(in)?)?([0-9]+s(ec)?([0-9]+ms)?)?)' ], |
| 84 | + "systemd::unit::${name}::service_timeoutstartsec must match either '^infinity$' or '(([0-9]+h(our)?)?([0-9]+m(in)?)?([0-9]+s(ec)?([0-9]+ms)?)?)'") |
| 85 | + $service_timeoutstartsec_real = $service_timeoutstartsec |
| 86 | + } elsif is_integer($service_timeoutstartsec) { |
| 87 | + validate_integer($service_timeoutstartsec, undef, 0) |
| 88 | + $service_timeoutstartsec_real = $service_timeoutstartsec |
| 89 | + } else { |
| 90 | + fail("system::unit::${name}::service_timeoutstartsec is not a string nor an integer") |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + if $service_restartsec != undef { |
| 95 | + if is_string($service_restartsec) { |
| 96 | + validate_re($service_restartsec, [ '^infinity$', '(([0-9]+h(our)?)?([0-9]+m(in)?)?([0-9]+s(ec)?([0-9]+ms)?)?)' ], |
| 97 | + "systemd::unit::${name}::service_restartsec must match either '^infinity$' or '(([0-9]+h(our)?)?([0-9]+m(in)?)?([0-9]+s(ec)?([0-9]+ms)?)?)'") |
| 98 | + $service_restartsec_real = $service_restartsec |
| 99 | + } elsif is_integer($service_restartsec) { |
| 100 | + validate_integer($service_restartsec, undef, 0) |
| 101 | + $service_restartsec_real = $service_restartsec |
| 102 | + } else { |
| 103 | + fail("system::unit::${name}::service_timeoutstartsec is not a string nor an integer") |
| 104 | + } |
80 | 105 | }
|
81 | 106 |
|
82 | 107 | file { "${name}_file":
|
|
0 commit comments