autotest/autotest — pull request #666 by rbbratta (2013-06-14 06:59:06+00:00)
Title: service_lib: create utility classes to start/stop service for both

sytemd and sys_v by autodetecting the current init proccess at PID 1

All these examples work on both systemd and sys_v_init.

```python
service_lib.auto_init_service_manager()
service_lib.get_service_manager().stop("iptables", ignore_status=True)

units = service_lib.get_service_manager().list().stdout
for s in services_to_disable:
if re.search(r"\s" + s, units):
logging.info("disabling %s", s)
service_lib.get_service_manager().disable(s)
service_lib.get_service_manager().stop(s)

lldpad = SpecificServiceManager("lldpad", service_lib.auto_create_specific_service_command_generator())
lldpad.stop()
lldpad.start()
```

The classes are split into two responsibilities, one classes generates all the
correct command lists by re-arranging the order of arguments to fit systemctl
or service, `service lldpad stop` versus `systemctl lldpad.service stop`

The other classes take these command generators and bind them to a
specific service name:
`lldpad.start()` or create a generic systemd or sys_v service object and
take a service name as an argument:
`service_lib.get_service_manager().stop("iptables", ignore_status=True)`

The module uses lazy initialization, in that it will detect systemd or
sys_v_init once when first accessed and will cache that value and not re-detect
`init` again.

This module mainly uses closures which are turned into staticmethods.
Test cases included.

Signed-off-by: Ross Brattain