File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/runit.cpython-310.pyc
o
�N�gyD � @ sp d Z ddlZddlZddlZddlZddlZddlZddlm Z e�
e�ZddiZ
g d�ZdZeD ]Zej�e�r=eZ nq1g ZdadZd d
� Zdd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zd@dd�Zdd� Zdd� ZdAdd�Z dd � Z!d!d"� Z"dBd#d$�Z#dBd%d&�Z$d'd(� Z%d)d*� Z&d+d,� Z'd-d.� Z(d/d0� Z)d1d2� Z*d3d4� Z+d5d6� Z,d7d8� Z-dCd:d;�Z.dCd<d=�Z/d>d?� Z0dS )Da�
runit service module
(http://smarden.org/runit)
This module is compatible with the :mod:`service <salt.states.service>` states,
so it can be used to maintain services using the ``provider`` argument:
.. code-block:: yaml
myservice:
service:
- running
- provider: runit
Provides virtual `service` module on systems using runit as init.
Service management rules (`sv` command):
service $n is ENABLED if file SERVICE_DIR/$n/run exists
service $n is AVAILABLE if ENABLED or if file AVAIL_SVR_DIR/$n/run exists
service $n is DISABLED if AVAILABLE but not ENABLED
SERVICE_DIR/$n is normally a symlink to a AVAIL_SVR_DIR/$n folder
Service auto-start/stop mechanism:
`sv` (auto)starts/stops service as soon as SERVICE_DIR/<service> is
created/deleted, both on service creation or a boot time.
autostart feature is disabled if file SERVICE_DIR/<n>/down exists. This
does not affect the current's service status (if already running) nor
manual service management.
Service's alias:
Service `sva` is an alias of service `svc` when `AVAIL_SVR_DIR/sva` symlinks
to folder `AVAIL_SVR_DIR/svc`. `svc` can't be enabled if it is already
enabled through an alias already enabled, since `sv` files are stored in
folder `SERVICE_DIR/svc/`.
XBPS package management uses a service's alias to provides service
alternative(s), such as chrony and openntpd both aliased to ntpd.
� N)�CommandExecutionError�reload_�reload)z/servicez/var/servicez/etc/service�runit)r c C s@ t �d�dkrt d dkrtd� datS tjj�d�rtS dS ) z�
Virtual service only on systems using runit as init process (PID 1).
Otherwise, use this module with the provider mechanism.
�initr �osZVoidz/etc/svZservice�sv)Fz'Runit not available. Please install sv)Z
__grains__�get�add_svc_avail_path�__virtualname__�salt�utils�path�which� r r �F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/runit.py�__virtual__S s r c C s t std��tj�t | �S )z]
Return SERVICE_DIR+name if possible
name
the service's name to work on
�!Could not find service directory.)�SERVICE_DIRr r r �join��namer r r �
_service_pathc s r c C � dt | �� �}td |� S )z�
Start service
name
the service's name
CLI Example:
.. code-block:: bash
salt '*' runit.start <service name>
z sv start �cmd.retcode�r �__salt__�r �cmdr r r �startp �
r c C r )z�
Stop service
name
the service's name
CLI Example:
.. code-block:: bash
salt '*' runit.stop <service name>
zsv stop r r r r r r �stop� r r! c C r )z�
Reload service
name
the service's name
CLI Example:
.. code-block:: bash
salt '*' runit.reload <service name>
z
sv reload r r r r r r r � r c C r )z�
Restart service
name
the service's name
CLI Example:
.. code-block:: bash
salt '*' runit.restart <service name>
zsv restart r r r r r r �restart� r r"