File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,14 +169,25 @@ class SystemdService(SysvService):
169169
170170 def _has_systemd_suffix (self ):
171171 """
172- Check if service name has a known systemd unit suffix
172+ Check if the service name has a known systemd unit suffix
173173 """
174174 unit_suffix = self .name .split ("." )[- 1 ]
175175 return unit_suffix in self .suffix_list
176176
177177 @property
178178 def exists (self ):
179- cmd = self .run_test ('systemctl list-unit-files | grep -q "^%s"' , self .name )
179+ # systemctl offers “list-units” and “list-unit-files” to list unit
180+ # files. Unfortunately, neither command provides a complete list of
181+ # unit files. Therefore, both commands are queried one after the
182+ # other.
183+ cmd = self .run_test (
184+ r'systemctl list-units --all | grep -q "^[[:space:]]*%s"' , self .name
185+ )
186+ if cmd .rc == 0 :
187+ return True
188+ cmd = self .run_test (
189+ r'systemctl list-unit-files | grep -q "^[[:space:]]*%s"' , self .name
190+ )
180191 return cmd .rc == 0
181192
182193 @property
You can’t perform that action at this time.
0 commit comments