Move all service drivers under services/ package
Change-Id: I4e7d46b4a289508dbf35be4cef954bd73806efe7
This commit is contained in:
parent
4b49c49307
commit
44b2593266
|
@ -17,7 +17,7 @@ from os_faults.ansible import executor
|
||||||
from os_faults.api import cloud_management
|
from os_faults.api import cloud_management
|
||||||
from os_faults.api import node_collection
|
from os_faults.api import node_collection
|
||||||
from os_faults.api import node_discover
|
from os_faults.api import node_discover
|
||||||
from os_faults.drivers import service
|
from os_faults.drivers.services import process
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class DevStackNode(node_collection.NodeCollection):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class ServiceInScreen(service.ServiceAsProcess):
|
class ServiceInScreen(process.ServiceAsProcess):
|
||||||
"""Service in Screen
|
"""Service in Screen
|
||||||
|
|
||||||
This driver controls service that is started in a window of
|
This driver controls service that is started in a window of
|
||||||
|
@ -63,7 +63,7 @@ class ServiceInScreen(service.ServiceAsProcess):
|
||||||
'properties': {
|
'properties': {
|
||||||
'window_name': {'type': 'string'},
|
'window_name': {'type': 'string'},
|
||||||
'grep': {'type': 'string'},
|
'grep': {'type': 'string'},
|
||||||
'port': service.PORT_SCHEMA,
|
'port': process.PORT_SCHEMA,
|
||||||
},
|
},
|
||||||
'required': ['grep', 'window_name'],
|
'required': ['grep', 'window_name'],
|
||||||
'additionalProperties': False,
|
'additionalProperties': False,
|
||||||
|
|
|
@ -18,7 +18,6 @@ from os_faults.ansible import executor
|
||||||
from os_faults.api import cloud_management
|
from os_faults.api import cloud_management
|
||||||
from os_faults.api import node_collection
|
from os_faults.api import node_collection
|
||||||
from os_faults.api import node_discover
|
from os_faults.api import node_discover
|
||||||
from os_faults.drivers import service
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -43,125 +42,6 @@ class FuelNodeCollection(node_collection.NodeCollection):
|
||||||
self.cloud_management.execute_on_cloud(self.hosts, task)
|
self.cloud_management.execute_on_cloud(self.hosts, task)
|
||||||
|
|
||||||
|
|
||||||
class PcsService(service.ServiceAsProcess):
|
|
||||||
"""Service as a resource in Pacemaker
|
|
||||||
|
|
||||||
Service that can be controled by `pcs resource` CLI tool.
|
|
||||||
|
|
||||||
**Example configuration:**
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
driver: pcs_service
|
|
||||||
args:
|
|
||||||
pcs_service: app
|
|
||||||
grep: my_app
|
|
||||||
port: ['tcp', 4242]
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
|
|
||||||
- **pcs_service** - name of a service
|
|
||||||
- **grep** - regexp for grep to find process PID
|
|
||||||
- **port** - tuple with two values - potocol, port number (optional)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
NAME = 'pcs_service'
|
|
||||||
DESCRIPTION = 'Service in pacemaker'
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
'type': 'object',
|
|
||||||
'properties': {
|
|
||||||
'pcs_service': {'type': 'string'},
|
|
||||||
'grep': {'type': 'string'},
|
|
||||||
'port': service.PORT_SCHEMA,
|
|
||||||
},
|
|
||||||
'required': ['grep', 'pcs_service'],
|
|
||||||
'additionalProperties': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(PcsService, self).__init__(*args, **kwargs)
|
|
||||||
self.pcs_service = self.config['pcs_service']
|
|
||||||
|
|
||||||
self.restart_cmd = 'pcs resource restart {} $(hostname)'.format(
|
|
||||||
self.pcs_service)
|
|
||||||
self.terminate_cmd = 'pcs resource ban {} $(hostname)'.format(
|
|
||||||
self.pcs_service)
|
|
||||||
self.start_cmd = 'pcs resource clear {} $(hostname)'.format(
|
|
||||||
self.pcs_service)
|
|
||||||
|
|
||||||
|
|
||||||
class PcsOrLinuxService(service.ServiceAsProcess):
|
|
||||||
"""Service as a resource in Pacemaker or Linux service
|
|
||||||
|
|
||||||
Service that can be controled by `pcs resource` CLI tool or
|
|
||||||
linux `service` tool. This is a hybrid driver that tries to find
|
|
||||||
service in Pacemaker and uses linux `service` if it is not found
|
|
||||||
there.
|
|
||||||
|
|
||||||
**Example configuration:**
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
driver: pcs_or_linux_service
|
|
||||||
args:
|
|
||||||
pcs_service: p_app
|
|
||||||
linux_service: app
|
|
||||||
grep: my_app
|
|
||||||
port: ['tcp', 4242]
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
|
|
||||||
- **pcs_service** - name of a service in Pacemaker
|
|
||||||
- **linux_service** - name of a service in init.d
|
|
||||||
- **grep** - regexp for grep to find process PID
|
|
||||||
- **port** - tuple with two values - potocol, port number (optional)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
NAME = 'pcs_or_linux_service'
|
|
||||||
DESCRIPTION = 'Service in pacemaker or init.d'
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
'type': 'object',
|
|
||||||
'properties': {
|
|
||||||
'pcs_service': {'type': 'string'},
|
|
||||||
'linux_service': {'type': 'string'},
|
|
||||||
'grep': {'type': 'string'},
|
|
||||||
'port': service.PORT_SCHEMA,
|
|
||||||
},
|
|
||||||
'required': ['grep', 'pcs_service', 'linux_service'],
|
|
||||||
'additionalProperties': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(PcsOrLinuxService, self).__init__(*args, **kwargs)
|
|
||||||
self.pcs_service = self.config.get('pcs_service')
|
|
||||||
self.linux_service = self.config.get('linux_service')
|
|
||||||
|
|
||||||
self.restart_cmd = (
|
|
||||||
'if pcs resource show {pcs_service}; '
|
|
||||||
'then pcs resource restart {pcs_service} $(hostname); '
|
|
||||||
'else service {linux_service} restart; fi').format(
|
|
||||||
linux_service=self.linux_service,
|
|
||||||
pcs_service=self.pcs_service)
|
|
||||||
self.terminate_cmd = (
|
|
||||||
'if pcs resource show {pcs_service}; '
|
|
||||||
'then pcs resource ban {pcs_service} $(hostname); '
|
|
||||||
'else service {linux_service} stop; fi').format(
|
|
||||||
linux_service=self.linux_service,
|
|
||||||
pcs_service=self.pcs_service)
|
|
||||||
self.start_cmd = (
|
|
||||||
'if pcs resource show {pcs_service}; '
|
|
||||||
'then pcs resource clear {pcs_service} $(hostname); '
|
|
||||||
'else service {linux_service} start; fi').format(
|
|
||||||
linux_service=self.linux_service,
|
|
||||||
pcs_service=self.pcs_service)
|
|
||||||
|
|
||||||
|
|
||||||
class FuelManagement(cloud_management.CloudManagement,
|
class FuelManagement(cloud_management.CloudManagement,
|
||||||
node_discover.NodeDiscover):
|
node_discover.NodeDiscover):
|
||||||
"""Fuel driver.
|
"""Fuel driver.
|
||||||
|
|
|
@ -19,7 +19,6 @@ from os_faults.ansible import executor
|
||||||
from os_faults.api import cloud_management
|
from os_faults.api import cloud_management
|
||||||
from os_faults.api import node_collection
|
from os_faults.api import node_collection
|
||||||
from os_faults.api import node_discover
|
from os_faults.api import node_discover
|
||||||
from os_faults.drivers import service
|
|
||||||
from os_faults import error
|
from os_faults import error
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -34,59 +33,6 @@ class TCPCloudNodeCollection(node_collection.NodeCollection):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
SALT_CALL = 'salt-call --local --retcode-passthrough '
|
|
||||||
SALT_RESTART = SALT_CALL + 'service.restart {service}'
|
|
||||||
SALT_TERMINATE = SALT_CALL + 'service.stop {service}'
|
|
||||||
SALT_START = SALT_CALL + 'service.start {service}'
|
|
||||||
|
|
||||||
|
|
||||||
class SaltService(service.ServiceAsProcess):
|
|
||||||
"""Salt service
|
|
||||||
|
|
||||||
Service that can be controlled by `salt service.*` commands.
|
|
||||||
|
|
||||||
**Example configuration:**
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
driver: salt_service
|
|
||||||
args:
|
|
||||||
salt_service: app
|
|
||||||
grep: my_app
|
|
||||||
port: ['tcp', 4242]
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
|
|
||||||
- **salt_service** - name of a service
|
|
||||||
- **grep** - regexp for grep to find process PID
|
|
||||||
- **port** - tuple with two values - protocol, port number (optional)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
NAME = 'salt_service'
|
|
||||||
DESCRIPTION = 'Service in salt'
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
'type': 'object',
|
|
||||||
'properties': {
|
|
||||||
'salt_service': {'type': 'string'},
|
|
||||||
'grep': {'type': 'string'},
|
|
||||||
'port': service.PORT_SCHEMA,
|
|
||||||
},
|
|
||||||
'required': ['grep', 'salt_service'],
|
|
||||||
'additionalProperties': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(SaltService, self).__init__(*args, **kwargs)
|
|
||||||
self.salt_service = self.config['salt_service']
|
|
||||||
|
|
||||||
self.restart_cmd = SALT_RESTART.format(service=self.salt_service)
|
|
||||||
self.terminate_cmd = SALT_TERMINATE.format(service=self.salt_service)
|
|
||||||
self.start_cmd = SALT_START.format(service=self.salt_service)
|
|
||||||
|
|
||||||
|
|
||||||
class TCPCloudManagement(cloud_management.CloudManagement,
|
class TCPCloudManagement(cloud_management.CloudManagement,
|
||||||
node_discover.NodeDiscover):
|
node_discover.NodeDiscover):
|
||||||
"""TCPCloud driver.
|
"""TCPCloud driver.
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from os_faults.drivers.services import process
|
||||||
|
|
||||||
|
|
||||||
|
class LinuxService(process.ServiceAsProcess):
|
||||||
|
"""Linux service
|
||||||
|
|
||||||
|
Service that is defined in init.d and can be controlled by `service`
|
||||||
|
CLI tool.
|
||||||
|
|
||||||
|
**Example configuration:**
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
driver: linux_service
|
||||||
|
args:
|
||||||
|
linux_service: app
|
||||||
|
grep: my_app
|
||||||
|
port: ['tcp', 4242]
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
- **linux_service** - name of a service
|
||||||
|
- **grep** - regexp for grep to find process PID
|
||||||
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
|
||||||
|
"""
|
||||||
|
NAME = 'linux_service'
|
||||||
|
DESCRIPTION = 'Service in init.d'
|
||||||
|
CONFIG_SCHEMA = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'linux_service': {'type': 'string'},
|
||||||
|
'grep': {'type': 'string'},
|
||||||
|
'port': process.PORT_SCHEMA,
|
||||||
|
},
|
||||||
|
'required': ['grep', 'linux_service'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(LinuxService, self).__init__(*args, **kwargs)
|
||||||
|
self.linux_service = self.config['linux_service']
|
||||||
|
|
||||||
|
self.restart_cmd = 'service {} restart'.format(self.linux_service)
|
||||||
|
self.terminate_cmd = 'service {} stop'.format(self.linux_service)
|
||||||
|
self.start_cmd = 'service {} start'.format(self.linux_service)
|
|
@ -0,0 +1,135 @@
|
||||||
|
# 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
|
||||||
|
|
||||||
|
from os_faults.drivers.services import process
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class PcsService(process.ServiceAsProcess):
|
||||||
|
"""Service as a resource in Pacemaker
|
||||||
|
|
||||||
|
Service that can be controlled by `pcs resource` CLI tool.
|
||||||
|
|
||||||
|
**Example configuration:**
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
driver: pcs_service
|
||||||
|
args:
|
||||||
|
pcs_service: app
|
||||||
|
grep: my_app
|
||||||
|
port: ['tcp', 4242]
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
- **pcs_service** - name of a service
|
||||||
|
- **grep** - regexp for grep to find process PID
|
||||||
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
"""
|
||||||
|
|
||||||
|
NAME = 'pcs_service'
|
||||||
|
DESCRIPTION = 'Service in pacemaker'
|
||||||
|
CONFIG_SCHEMA = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'pcs_service': {'type': 'string'},
|
||||||
|
'grep': {'type': 'string'},
|
||||||
|
'port': process.PORT_SCHEMA,
|
||||||
|
},
|
||||||
|
'required': ['grep', 'pcs_service'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(PcsService, self).__init__(*args, **kwargs)
|
||||||
|
self.pcs_service = self.config['pcs_service']
|
||||||
|
|
||||||
|
self.restart_cmd = 'pcs resource restart {} $(hostname)'.format(
|
||||||
|
self.pcs_service)
|
||||||
|
self.terminate_cmd = 'pcs resource ban {} $(hostname)'.format(
|
||||||
|
self.pcs_service)
|
||||||
|
self.start_cmd = 'pcs resource clear {} $(hostname)'.format(
|
||||||
|
self.pcs_service)
|
||||||
|
|
||||||
|
|
||||||
|
class PcsOrLinuxService(process.ServiceAsProcess):
|
||||||
|
"""Service as a resource in Pacemaker or Linux service
|
||||||
|
|
||||||
|
Service that can be controlled by `pcs resource` CLI tool or
|
||||||
|
linux `service` tool. This is a hybrid driver that tries to find
|
||||||
|
service in Pacemaker and uses linux `service` if it is not found
|
||||||
|
there.
|
||||||
|
|
||||||
|
**Example configuration:**
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
driver: pcs_or_linux_service
|
||||||
|
args:
|
||||||
|
pcs_service: p_app
|
||||||
|
linux_service: app
|
||||||
|
grep: my_app
|
||||||
|
port: ['tcp', 4242]
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
- **pcs_service** - name of a service in Pacemaker
|
||||||
|
- **linux_service** - name of a service in init.d
|
||||||
|
- **grep** - regexp for grep to find process PID
|
||||||
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
"""
|
||||||
|
|
||||||
|
NAME = 'pcs_or_linux_service'
|
||||||
|
DESCRIPTION = 'Service in pacemaker or init.d'
|
||||||
|
CONFIG_SCHEMA = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'pcs_service': {'type': 'string'},
|
||||||
|
'linux_service': {'type': 'string'},
|
||||||
|
'grep': {'type': 'string'},
|
||||||
|
'port': process.PORT_SCHEMA,
|
||||||
|
},
|
||||||
|
'required': ['grep', 'pcs_service', 'linux_service'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(PcsOrLinuxService, self).__init__(*args, **kwargs)
|
||||||
|
self.pcs_service = self.config.get('pcs_service')
|
||||||
|
self.linux_service = self.config.get('linux_service')
|
||||||
|
|
||||||
|
self.restart_cmd = (
|
||||||
|
'if pcs resource show {pcs_service}; '
|
||||||
|
'then pcs resource restart {pcs_service} $(hostname); '
|
||||||
|
'else service {linux_service} restart; fi').format(
|
||||||
|
linux_service=self.linux_service,
|
||||||
|
pcs_service=self.pcs_service)
|
||||||
|
self.terminate_cmd = (
|
||||||
|
'if pcs resource show {pcs_service}; '
|
||||||
|
'then pcs resource ban {pcs_service} $(hostname); '
|
||||||
|
'else service {linux_service} stop; fi').format(
|
||||||
|
linux_service=self.linux_service,
|
||||||
|
pcs_service=self.pcs_service)
|
||||||
|
self.start_cmd = (
|
||||||
|
'if pcs resource show {pcs_service}; '
|
||||||
|
'then pcs resource clear {pcs_service} $(hostname); '
|
||||||
|
'else service {linux_service} start; fi').format(
|
||||||
|
linux_service=self.linux_service,
|
||||||
|
pcs_service=self.pcs_service)
|
|
@ -60,7 +60,7 @@ class ServiceAsProcess(service.Service):
|
||||||
- **restart_cmd** - command to restart service (optional)
|
- **restart_cmd** - command to restart service (optional)
|
||||||
- **terminate_cmd** - command to terminate service (optional)
|
- **terminate_cmd** - command to terminate service (optional)
|
||||||
- **start_cmd** - command to start service (optional)
|
- **start_cmd** - command to start service (optional)
|
||||||
- **port** - tuple with two values - potocol, port number (optional)
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -162,102 +162,3 @@ class ServiceAsProcess(service.Service):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self._run_task(nodes, task, message)
|
self._run_task(nodes, task, message)
|
||||||
|
|
||||||
|
|
||||||
class LinuxService(ServiceAsProcess):
|
|
||||||
"""Linux service
|
|
||||||
|
|
||||||
Service that is defined in init.d and can be controled by `service`
|
|
||||||
CLI tool.
|
|
||||||
|
|
||||||
**Example configuration:**
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
driver: linux_service
|
|
||||||
args:
|
|
||||||
linux_service: app
|
|
||||||
grep: my_app
|
|
||||||
port: ['tcp', 4242]
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
|
|
||||||
- **linux_service** - name of a service
|
|
||||||
- **grep** - regexp for grep to find process PID
|
|
||||||
- **port** - tuple with two values - potocol, port number (optional)
|
|
||||||
|
|
||||||
"""
|
|
||||||
NAME = 'linux_service'
|
|
||||||
DESCRIPTION = 'Service in init.d'
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
'type': 'object',
|
|
||||||
'properties': {
|
|
||||||
'linux_service': {'type': 'string'},
|
|
||||||
'grep': {'type': 'string'},
|
|
||||||
'port': PORT_SCHEMA,
|
|
||||||
},
|
|
||||||
'required': ['grep', 'linux_service'],
|
|
||||||
'additionalProperties': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(LinuxService, self).__init__(*args, **kwargs)
|
|
||||||
self.linux_service = self.config['linux_service']
|
|
||||||
|
|
||||||
self.restart_cmd = 'service {} restart'.format(self.linux_service)
|
|
||||||
self.terminate_cmd = 'service {} stop'.format(self.linux_service)
|
|
||||||
self.start_cmd = 'service {} start'.format(self.linux_service)
|
|
||||||
|
|
||||||
|
|
||||||
class SystemdService(ServiceAsProcess):
|
|
||||||
"""Systemd service.
|
|
||||||
|
|
||||||
Service as Systemd unit and can be controlled by `systemctl` CLI tool.
|
|
||||||
|
|
||||||
**Example configuration:**
|
|
||||||
|
|
||||||
.. code-block:: yaml
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
driver: systemd_service
|
|
||||||
args:
|
|
||||||
systemd_service: app
|
|
||||||
grep: my_app
|
|
||||||
port: ['tcp', 4242]
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
|
|
||||||
- **systemd_service** - name of a service in systemd
|
|
||||||
- **grep** - regexp for grep to find process PID
|
|
||||||
- **port** - tuple with two values - protocol, port number (optional)
|
|
||||||
|
|
||||||
"""
|
|
||||||
NAME = 'systemd_service'
|
|
||||||
DESCRIPTION = 'Service in Systemd'
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
'type': 'object',
|
|
||||||
'properties': {
|
|
||||||
'systemd_service': {'type': 'string'},
|
|
||||||
'grep': {'type': 'string'},
|
|
||||||
'port': PORT_SCHEMA,
|
|
||||||
'start_cmd': {'type': 'string'},
|
|
||||||
'terminate_cmd': {'type': 'string'},
|
|
||||||
'restart_cmd': {'type': 'string'},
|
|
||||||
},
|
|
||||||
'required': ['grep', 'systemd_service'],
|
|
||||||
'additionalProperties': False,
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(SystemdService, self).__init__(*args, **kwargs)
|
|
||||||
self.systemd_service = self.config['systemd_service']
|
|
||||||
|
|
||||||
self.restart_cmd = 'sudo systemctl restart {}'.format(
|
|
||||||
self.systemd_service)
|
|
||||||
self.terminate_cmd = 'sudo systemctl stop {}'.format(
|
|
||||||
self.systemd_service)
|
|
||||||
self.start_cmd = 'sudo systemctl start {}'.format(
|
|
||||||
self.systemd_service)
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from os_faults.drivers.services import process
|
||||||
|
|
||||||
|
SALT_CALL = 'salt-call --local --retcode-passthrough '
|
||||||
|
SALT_RESTART = SALT_CALL + 'service.restart {service}'
|
||||||
|
SALT_TERMINATE = SALT_CALL + 'service.stop {service}'
|
||||||
|
SALT_START = SALT_CALL + 'service.start {service}'
|
||||||
|
|
||||||
|
|
||||||
|
class SaltService(process.ServiceAsProcess):
|
||||||
|
"""Salt service
|
||||||
|
|
||||||
|
Service that can be controlled by `salt service.*` commands.
|
||||||
|
|
||||||
|
**Example configuration:**
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
driver: salt_service
|
||||||
|
args:
|
||||||
|
salt_service: app
|
||||||
|
grep: my_app
|
||||||
|
port: ['tcp', 4242]
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
- **salt_service** - name of a service
|
||||||
|
- **grep** - regexp for grep to find process PID
|
||||||
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
NAME = 'salt_service'
|
||||||
|
DESCRIPTION = 'Service in salt'
|
||||||
|
CONFIG_SCHEMA = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'salt_service': {'type': 'string'},
|
||||||
|
'grep': {'type': 'string'},
|
||||||
|
'port': process.PORT_SCHEMA,
|
||||||
|
},
|
||||||
|
'required': ['grep', 'salt_service'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(SaltService, self).__init__(*args, **kwargs)
|
||||||
|
self.salt_service = self.config['salt_service']
|
||||||
|
|
||||||
|
self.restart_cmd = SALT_RESTART.format(service=self.salt_service)
|
||||||
|
self.terminate_cmd = SALT_TERMINATE.format(service=self.salt_service)
|
||||||
|
self.start_cmd = SALT_START.format(service=self.salt_service)
|
|
@ -0,0 +1,66 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from os_faults.drivers.services import process
|
||||||
|
|
||||||
|
|
||||||
|
class SystemdService(process.ServiceAsProcess):
|
||||||
|
"""Systemd service.
|
||||||
|
|
||||||
|
Service as Systemd unit and can be controlled by `systemctl` CLI tool.
|
||||||
|
|
||||||
|
**Example configuration:**
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
driver: systemd_service
|
||||||
|
args:
|
||||||
|
systemd_service: app
|
||||||
|
grep: my_app
|
||||||
|
port: ['tcp', 4242]
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
|
||||||
|
- **systemd_service** - name of a service in systemd
|
||||||
|
- **grep** - regexp for grep to find process PID
|
||||||
|
- **port** - tuple with two values - protocol, port number (optional)
|
||||||
|
|
||||||
|
"""
|
||||||
|
NAME = 'systemd_service'
|
||||||
|
DESCRIPTION = 'Service in Systemd'
|
||||||
|
CONFIG_SCHEMA = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'systemd_service': {'type': 'string'},
|
||||||
|
'grep': {'type': 'string'},
|
||||||
|
'port': process.PORT_SCHEMA,
|
||||||
|
'start_cmd': {'type': 'string'},
|
||||||
|
'terminate_cmd': {'type': 'string'},
|
||||||
|
'restart_cmd': {'type': 'string'},
|
||||||
|
},
|
||||||
|
'required': ['grep', 'systemd_service'],
|
||||||
|
'additionalProperties': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(SystemdService, self).__init__(*args, **kwargs)
|
||||||
|
self.systemd_service = self.config['systemd_service']
|
||||||
|
|
||||||
|
self.restart_cmd = 'sudo systemctl restart {}'.format(
|
||||||
|
self.systemd_service)
|
||||||
|
self.terminate_cmd = 'sudo systemctl stop {}'.format(
|
||||||
|
self.systemd_service)
|
||||||
|
self.start_cmd = 'sudo systemctl start {}'.format(
|
||||||
|
self.systemd_service)
|
Loading…
Reference in New Issue