HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/runit.cpython-310.pyc
o

�N�gyD�@spdZddlZddlZddlZddlZddlZddlZddlm	Z	e�
e�ZddiZ
gd�ZdZeD]Zej�e�r=eZnq1gZdadZd	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)rcCs@t�d�dkrtddkrtd�datStjj�d�rtSdS)	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�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/runit.py�__virtual__SsrcCststd��tj�t|�S)z]
    Return SERVICE_DIR+name if possible

    name
        the service's name to work on
    �!Could not find service directory.)�SERVICE_DIRrrr�join��namerrr�
_service_pathcsrcC�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�cmdrrr�startp�
rcCr)z�
    Stop service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.stop <service name>
    zsv stop rrrrrr�stop�r r!cCr)z�
    Reload service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.reload <service name>
    z
sv reload rrrrrrr�r cCr)z�
    Restart service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.restart <service name>
    zsv restart rrrrrr�restart�r r"cCst|�dS)z�
    Calls runit.restart()

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.full_restart <service name>
    N)r"rrrr�full_restart�s
r#cCsd|r
ttd|��St|�}tj�|�sdSd|��}ztd|�}|�d�WSty1YdSw)z�
    Return ``True`` if service is running

    name
        the service's name

    sig
        signature to identify with ps

    CLI Example:

    .. code-block:: bash

        salt '*' runit.status <service name>
    z
status.pidF�
sv status zcmd.run_stdoutzrun: )�boolrrrr�exists�
startswith�	Exception)r�sig�svc_pathr�outrrr�status�s
�r,cCs<tj�|d�}tj�|�rtj�|�rt�|tj�rdSdS)z�
    Return ``True`` if directory <svc_path> is really a service:
    file <svc_path>/run exists and is executable

    svc_path
        the (absolute) directory to check for compatibility
    �runTF)rrrr&�access�X_OK)r*Zrun_filerrr�_is_svc�s
�
��r0cCstj�tj�t|�d��S)a0
    Return ``True`` if service <name> is autostarted by sv
    (file $service_folder/down does not exist)
    NB: return ``False`` if the service is not enabled.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.status_autostart <service name>
    �down)rrr&rrrrrr�status_autostartsr2�*cCsFtstd��t�}t�tj�t|��D]}t|�s|�|�qt	|�S)a9
    Return list of broken path(s) in SERVICE_DIR that match ``name``

    A path is broken if it is a broken symlink or can not be a runit service

    name
        a glob for service name. default is '*'

    CLI Example:

    .. code-block:: bash

        salt '*' runit.get_svc_broken_path <service name>
    r)
rr�set�globrrrr0�add�sorted)r�ret�elrrr�get_svc_broken_paths
�r:cCstS)zB
    Return list of paths that may contain available services
    )�AVAIL_SVR_DIRSrrrr�get_svc_avail_path,sr<cCs&tj�|�r|tvrt�|�dSdS)z�
    Add a path that may contain available services.
    Return ``True`` if added (or already present), ``False`` on error.

    path
        directory to add to AVAIL_SVR_DIRS
    TF)rrr&r;�append)rrrrr
3s

r
cCs�tstd��t�}t�tj�t|��D] }t|�r3tj�|�r(|�	t�
|��n|�	|�t�d|�q|dkr<t
|�St�}tD]}t�tj�||��D]}t|�r^|�	|�t�d|�qMqA|dkrm|�|�}t
|�S|�|�}t
|�S)ae
    Return a list of paths to services with ``name`` that have the specified ``status``

    name
        a glob for service name. default is '*'

    status
        None       : all services (no filter, default choice)
        'DISABLED' : available service(s) that is not enabled
        'ENABLED'  : enabled service (whether started on boot or not)
    rzfound enabled service path: %s�ENABLEDz found available service path: %s�DISABLED)rrr4r5rrrr0�islinkr6�readlink�log�tracer7r;�
difference�union)rr,Zenar9Zava�dr8rrr�
_get_svc_pathBs2
�
��

�rGcCstdd�t||�D��S)aQ
    Return list of services that have the specified service ``status``

    name
        a glob for service name. default is '*'

    status
        None       : all services (no filter, default choice)
        'DISABLED' : available service that is not enabled
        'ENABLED'  : enabled service (whether started on boot or not)
    css�|]	}tj�|�VqdS�N)rr�basename)�.0r9rrr�	<genexpr>�s�z _get_svc_list.<locals>.<genexpr>)r7rG)rr,rrr�
_get_svc_listysrLcCs�i}tD]=}t�tj�|d��D]0}tj�|�sqt�|�}tj�|�s+tj�||�}tj�|�}||vr9g||<||�	|�qq|S)zU
    Returns the list of service's name that are aliased and their alias path(s)
    r3)
r;r5rrrr@rA�isabsrIr=)r8rFr9ZpsvcZnsvcrrr�
get_svc_alias�s
�
rNcCs|t|�vS)z�
    Returns ``True`` if the specified service is available, otherwise returns
    ``False``.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.available <service name>
    �rLrrrr�	available�srPcCs|t|�vS)a

    The inverse of runit.available.
    Returns ``True`` if the specified service is not available, otherwise returns
    ``False``.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.missing <service name>
    rOrrrr�missing�srQcCst�S)z}
    Return a list of all available services

    CLI Example:

    .. code-block:: bash

        salt '*' runit.get_all
    rOrrrr�get_all�s
rRcC�
tdd�S)z�
    Return a list of all enabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    r>�r,rOrrrr�get_enabled��

rUcCrS)z�
    Return a list of all disabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_disabled
    r?rTrOrrrr�get_disabled�rVrWcCs|t|d�vS)z�
    Return ``True`` if the named service is enabled, ``False`` otherwise

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.enabled <service name>
    r>rOrrrr�enabled��rXcCs|t|d�vS)z�
    Return ``True`` if the named service is disabled, ``False``  otherwise

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.disabled <service name>
    r>rOrrrr�disabled�rYrZcCs�i}d|d<d|d<d|d<d|d<d|d<d|d	<t|�|d
<|d
s&|St|�|d<|d|d<t|�|d<t|�|d<t|�d|d<|drVtj�|dd�|d	<|S)
z�
    Show properties of one or more units/jobs or the manager

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.show <service name>
    FrXTrZZrunningNZservice_pathZ	autostartZcommand_pathrPrr-)rPrXr,r2rGrrr)rr8rrr�shows$
r[Fc
Ks�t|�sdSt�}||vrt�d�dSt|�d}tj�|d�}t|�rFtj�	|�rDzt�
|�WdStyCt�d|�YdSwdS|sqt�d|�tj�	|�sqzt
jj�|d���Wntypt�d	|�YdSwz
t�|t|��Wnty�t�d
|�|s�t�
|�YdSwdt|���}d}d}|dkr�|d
kr�t�d�|d7}td|�}	|	d}|dkr�|d
ks�|s�tj�	|�r�zt�
|�Wnty�t�d|�d}Ynw|dkr�t�
tj�t|�|g��dSdS)a'
    Start service ``name`` at boot.
    Returns ``True`` if operation is successful

    name
        the service's name

    start : False
        If ``True``, start the service once enabled.

    CLI Example:

    .. code-block:: bash

        salt '*' service.enable <name> [start=True]
    Fz1This service is aliased, enable its alias insteadrr1zUnable to remove file %sTzneed a temporary file %s�w�Unable to create file %szUnable to create symlink %sr$��
g�?zcmd.run_all�retcodezUnable to remove temp file %s)rPrNrB�errorrGrrrrXr&�unlink�OSErrorrCrr
�files�fopen�close�symlinkr�time�sleepr)
rr�kwargs�alias�svc_realpath�	down_filerZ
retcode_svZcount_sv�callrrr�enable.sn
���
�
��rocKs~t|�sdSt|�d}tj�|d�}|r||�tj�|�s=z
tjj�	|d��
�WdSty<t�
d|�YdSwdS)a
    Don't start service ``name`` at boot
    Returns ``True`` if operation is successful

    name
        the service's name

    stop
        if True, also stops the service

    CLI Example:

    .. code-block:: bash

        salt '*' service.disable <name> [stop=True]
    Frr1r\r]T)rXrGrrrr&rr
rdrerfrcrBra)rr!rjrlrmrrr�disable�s��rpcCszt|�sdSt|�}tj�|�st�d|�dSt|�s$t�d|�dSzt�|�WdSt	y<t�d|�YdSw)a
    Remove the service <name> from system.
    Returns ``True`` if operation is successful.
    The service will be also stopped.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.remove <name>
    Fz %s is not a symlink: not removedzFailed to stop service %szUnable to remove symlink %sT)
rXrrrr@rBrar!�removerc)rr*rrrrq�s ��rqrH)r3)r3N)F)1�__doc__r5�loggingrrhZsalt.utils.filesrZsalt.utils.pathZsalt.exceptionsr�	getLogger�__name__rBZ__func_alias__ZVALID_SERVICE_DIRSrZservice_dirrr&r;rZ__virtual_aliases__rrrr!rr"r#r,r0r2r:r<r
rGrLrNrPrQrRrUrWrXrZr[rorprqrrrr�<module>s^/
�

%


7



&
a)