monasca-agent/monasca_setup/service/detection.py
Stefano Canepa a8a2bb845b Removed dependency on supervisor
To support python3 in the near future this was done:

* Removed dependency on supervisor.
* Added template configuration for systemd target that includes all
  services.
* Added templates configuration for systemd service for every single
  service.
* Changed monasca_setup to use the new templates.

In the meanwhile code was formated to cope with pep8 settings and some
other small changes were done to comply with pycodestyle and
pydocstring.

Task: 4126
Story: 2000975

Depends-On: https://review.openstack.org/#/c/566475/

Change-Id: I0d0c4ea41a830581d6b9f247fad6a2dda1f96cbe
2018-06-27 11:28:43 +02:00

45 lines
1.4 KiB
Python

# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import platform
import sys
from monasca_setup.service import linux
LOG = logging.getLogger(__name__)
def detect_init(*args, **kwargs):
"""Create a service object if possible.
Detect if systemd is present on the system and if so return the service
object.
:return: a systemd service object for this system.
"""
detected_os = platform.system()
if has_systemd():
return linux.Systemd(*args, **kwargs)
LOG.error("{0} is not currently supported by the Monasca Agent"
.format(detected_os))
sys.exit(1)
def has_systemd():
"""Detect if Linux init is systemd."""
with open('/proc/1/comm', 'r') as init_proc:
init = init_proc.readline().strip()
return init == 'systemd'