%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZidd6ZdZd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'dd�Z)d�Z*d �Z+d!�Z,d"�Z-d#�Z.d$�Z/d%�Z0dS(&u�
Module for the management of upstart systems. The Upstart system only supports
service starting, stopping and restarting.

.. important::
    If you feel that Salt should be using this module to manage services on a
    minion, and it is using a different module (or gives an error similar to
    *'service.start' is not available*), see :ref:`here
    <module-provider-override>`.

Currently (as of Ubuntu 12.04) there is no tool available to disable
Upstart services (like update-rc.d). This[1] is the recommended way to
disable an Upstart service. So we assume that all Upstart services
that have not been disabled in this manner are enabled.

But this is broken because we do not check to see that the dependent
services are enabled. Otherwise we would have to do something like
parse the output of "initctl show-config" to determine if all service
dependencies are enabled to start on boot. For example, see the "start
on" condition for the lightdm service below[2]. And this would be too
hard. So we wait until the upstart developers have solved this
problem. :) This is to say that an Upstart service that is enabled may
not really be enabled.

Also, when an Upstart service is enabled, should the dependent
services be enabled too? Probably not. But there should be a notice
about this, at least.

[1] http://upstart.ubuntu.com/cookbook/#disabling-a-job-from-automatically-starting

[2] example upstart configuration file::

    lightdm
    emits login-session-start
    emits desktop-session-start
    emits desktop-shutdown
    start on ((((filesystem and runlevel [!06]) and started dbus) and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1 or stopped udev-fallback-graphics)) or runlevel PREVLEVEL=S)
    stop on runlevel [016]

.. warning::
    This module should not be used on Red Hat systems. For these,
    the :mod:`rh_service <salt.modules.rh_service>` module should be
    used, as it supports the hybrid upstart/sysvinit system used in
    RHEL/CentOS 6.
i(tabsolute_importtunicode_literalstprint_functionNureloadureload_uservicecC@s�tjjjt�rtdfStdd
kr3tStddkr�d	}tj	j
|�r�tjjj
|d
�}d|kr�tSq�ntdfS(u
    Only work on Ubuntu
    uQThe upstart execution module failed to load: this system was booted with systemd.uosuUbuntuuLinarou
elementary OSuMintuDebianuRaspbianu
/sbin/initctlu versionuupstartutThe upstart execution module failed to load:  the system must be Ubuntu-based, or Debian-based with upstart support.(uUbuntuuLinarou
elementary OSuMint(uDebianuRaspbian(tsalttutilstsystemdtbootedt__context__tFalset
__grains__t__virtualname__tostpathtisfiletmodulestcmdmodt
_run_quiet(tdebian_initctltinitctl_version((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt__virtual__Fs

cC@smi}x<dD]4}y||tj|�j<Wq
tk
r@q
Xq
Wt|�re|t|�j�StSdS(u�
    Figure out which utmp file to use when determining runlevel.
    Sometimes /var/run/utmp doesn't exist, /run/utmp is the new hotness.
    u
/var/run/utmpu	/run/utmpN(u
/var/run/utmpu	/run/utmp(Rtstattst_mtimet	ExceptiontlentsortedtpopR(tresulttutmp((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt
_find_utmpYs

cC@s�ystjjjd��X}xN|D]F}tjjj|�}|jd�r"|jd�dj�}q"q"WWdQXWnt	k
r�dSXyztjjjd��_}xU|D]M}tjjj|�}|jd�r�d	|kr�|jd
�d}q�q�WWdQXWnt	k
rnXy�t
d�}tjjjd��`}xV|D]N}tjjj|�}x0|j�j�D]}||krr|}PqrqrWqDWWdQXWnt	k
r�nX|S(u�
    Try to figure out the default runlevel.  It is kept in
    /etc/init/rc-sysinit.conf, but can be overridden with entries
    in /etc/inittab, or via the kernel command-line at boot
    u/etc/init/rc-sysinit.confuenv DEFAULT_RUNLEVELu=i����Nu2u/etc/inittabu#uinitdefaultu:iu0u1u3u4u5u6usuSu-susingleu
/proc/cmdline(u0u1u2u3u4u5u6usuSu-susingle(RRtfilestfopentstringutilst
to_unicodet
startswithtsplittstripRtset(tfp_tlinetrunlevelt
valid_stringstarg((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_default_runlevelks:
*

$
	

cC@s�dtkrtdSt�}t�}|r|tdddj|�gdt�}y|j�d}Wq|tk
rxq|Xn|td<|S(u%
    Return the current runlevel
    uupstart._runlevelucmd.runurunlevelu{0}tpython_shelli(RR*Rt__salt__tformatRR"t
IndexError(tretRtout((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt	_runlevel�s		%

cC@s"tjj|�tjj|�kS(N(RRtabspathtrealpath(tname((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_is_symlink�scC@stjdj|�tj�S(u�
    From "Writing Jobs" at
    http://upstart.ubuntu.com/getting-started.html:

    Jobs are defined in files placed in /etc/init, the name of the job
    is the filename under this directory without the .conf extension.
    u/etc/init/{0}.conf(RtaccessR-tR_OK(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_service_is_upstart�sc	C@s�dj|�dj|�g}xotjtjj|�D]U}tjjj	|��8}t
jdtjjj
|j��t
j�r�tSWdQXq7WtS(u�
    An Upstart service is assumed disabled if a manual stanza is
    placed in /etc/init/[name].override.
    NOTE: An Upstart service can also be disabled by placing "manual"
    in /etc/init/[name].conf.
    u/etc/init/{0}.confu/etc/init/{0}.overrideu
^\s*manualN(R-t	itertoolstifilterRRR
RRRRtretsearchRR treadt	MULTILINEtTrueR(R4Rt	file_nameR%((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_upstart_is_disabled�s	cC@st|�S(uX
    Assume that if an Upstart service is not disabled then it must be
    enabled.
    (RA(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_upstart_is_enabled�scC@s/dj|�}t|�o.tj|tj�S(u�
    A System-V style service will have a control script in
    /etc/init.d. We make sure to skip over symbolic links that point
    to Upstart's /lib/init/upstart-job, and anything that isn't an
    executable, like README or skeleton.
    u/etc/init.d/{0}(R-R8RR6tX_OK(R4tscript((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_service_is_sysv�scC@s#ttjdjt�|���S(u�
    A System-V style service is assumed disabled if there is no
    start-up link (starts with "S") to its script in /etc/init.d in
    the current runlevel.
    u/etc/rc{0}.d/S*{1}(tbooltglobR-R1(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_sysv_is_disabled�scC@st|�S(u^
    Assume that if a System-V style service is not disabled then it
    must be enabled.
    (RH(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_sysv_is_enabled�sc	c@s�t�}x;tjd�D]*}tjj|�}|j|�|VqWd}x�tjjj|�D]�\}}}tjj	||�}xct
j|d�D]O}|dkr�|d }ntjj||d �}||kr�q�n|Vq�WqcWdS(u�
    Detect all of the service names available to upstart via init configuration
    files and via classic sysv init scripts
    u
/etc/init.d/*u
/etc/init/u*.confu.i����N(
R$RGRRtbasenametaddRRtos_walktrelpathtfnmatchtfiltertjoin(	tfoundR&R4t	init_roottroottdirnamest	filenamesRMtfilename((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_iter_service_names�s	
	%
cC@s}t�}xgt�D]\}t|�rDt|�ro|j|�qoqt|�rt|�ro|j|�qoqqWt|�S(uw
    Return the enabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    (R$RWR8RBRKRERIR(R/R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytget_enableds
	cC@s}t�}xgt�D]\}t|�rDt|�ro|j|�qoqt|�rt|�ro|j|�qoqqWt|�S(uy
    Return the disabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_disabled
    (R$RWR8RARKRERHR(R/R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytget_disabled"s
	cC@s
|t�kS(u�
    Returns ``True`` if the specified service is available, otherwise returns
    ``False``.

    CLI Example:

    .. code-block:: bash

        salt '*' service.available sshd
    (tget_all(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt	available8scC@s
|t�kS(u�
    The inverse of service.available.
    Returns ``True`` if the specified service is not available, otherwise returns
    ``False``.

    CLI Example:

    .. code-block:: bash

        salt '*' service.missing sshd
    (RZ(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytmissingFscC@stt�t��S(uu
    Return all installed services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_all
    (RRXRY(((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyRZUs
cC@s$d|dg}td|dt�S(u�
    Start the specified service

    CLI Example:

    .. code-block:: bash

        salt '*' service.start <service name>
    userviceustartucmd.retcodeR+(R,R(R4tcmd((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytstartbs
cC@s$d|dg}td|dt�S(u~
    Stop the specified service

    CLI Example:

    .. code-block:: bash

        salt '*' service.stop <service name>
    userviceustopucmd.retcodeR+(R,R(R4R]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytstopps
cC@s$d|dg}td|dt�S(u�
    Restart the named service

    CLI Example:

    .. code-block:: bash

        salt '*' service.restart <service name>
    userviceurestartucmd.retcodeR+(R,R(R4R]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytrestart~s
cC@s$d|dg}td|dt�S(u�
    Do a full restart (stop/start) of the named service

    CLI Example:

    .. code-block:: bash

        salt '*' service.full_restart <service name>
    userviceu--full-restartucmd.retcodeR+(R,R(R4R]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytfull_restart�s
cC@s$d|dg}td|dt�S(u~
    Reload the named service

    CLI Example:

    .. code-block:: bash

        salt '*' service.reload <service name>
    userviceureloaducmd.retcodeR+(R,R(R4R]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytreload_�s
cC@s$d|dg}td|dt�S(u�
    Force-reload the named service

    CLI Example:

    .. code-block:: bash

        salt '*' service.force_reload <service name>
    userviceuforce-reloaducmd.retcodeR+(R,R(R4R]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytforce_reload�s
c
C@s�|rttd|��Sttjd|��}|rPtjt�|�}n	|g}i}x|D]w}d|dg}t|�r�dtd|dtdt	�k||<qfttd	|dtdt	d
t	��||<qfW|r�|S||S(u]
    Return the status for a service.
    If the name contains globbing, a dict mapping service name to True/False
    values is returned.

    .. versionchanged:: 2018.3.0
        The service name can now be a glob (e.g. ``salt*``)

    Args:
        name (str): The name of the service to check
        sig (str): Signature to use to find the service via ps

    Returns:
        bool: True if running, False otherwise
        dict: Maps service name to True if running, False otherwise

    CLI Example:

    .. code-block:: bash

        salt '*' service.status <service name> [service signature]
    u
status.pidu\*|\?|\[.+\]userviceustatusu
start/runningucmd.runR+tignore_retcodeucmd.retcodetquite(
RFR,R;R<RNRORZR8RR?(R4tsigtcontains_globbingtservicestresultstserviceR]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytstatus�s$	
cC@sd}tjjj|�|S(u�
    Debian uses update-rc.d to manage System-V style services.
    http://www.debian.org/doc/debian-policy/ch-opersys.html#s9.3.3
    uupdate-rc.d(RRRtcheck_or_die(t
executable((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_get_service_exec�scC@slt|�rt|�Sdj|�}tjjj|d��#}|jtjjjd��WdQXt|�S(u%
    Disable an Upstart service.
    u/etc/init/{0}.overrideuaumanual
N(	RAR-RRRRtwriteRtto_str(R4toverridetofile((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_upstart_disable�s
"cC@s+t|�rt|�Sdj|�}dj|�|g}x�tjtjj|�D]�}tjj	j
|d��m}tjddtjj
j|j��dtj�}|jd�|jtjj
j|��|j�WdQXqSWtj|tj�r!tjj|�dkr!tj|�nt|�S(u$
    Enable an Upstart service.
    u/etc/init/{0}.overrideu/etc/init/{0}.confur+u
^\s*manual\n?uiN(RBR-R9R:RRR
RRRRR;tsubRR R=R>tseekRoRpttruncateR6R7tgetsizetunlink(R4RqRR@R%tnew_text((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt_upstart_enable�s&
	

-cK@sFt|�rt|�St�}dj||�}td|dt�S(u�
    Enable the named service to start at boot

    CLI Example:

    .. code-block:: bash

        salt '*' service.enable <service name>
    u{0} -f {1} defaultsucmd.retcodeR+(R8RzRnR-R,R(R4tkwargsRmR]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytenables


	cK@sFt|�rt|�St�}|d|dg}td|dt�S(u�
    Disable the named service from starting on boot

    CLI Example:

    .. code-block:: bash

        salt '*' service.disable <service name>
    u-furemoveucmd.retcodeR+(R8RsRnR,R(R4R{RmR]((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytdisable+s


	cK@s0t|�rt|�St|�r,t|�SdS(u�
    Check to see if the named service is enabled to start on boot

    CLI Example:

    .. code-block:: bash

        salt '*' service.enabled <service name>
    N(R8RBRERItNone(R4R{((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytenabled<s



cC@s0t|�rt|�St|�r,t|�SdS(u�
    Check to see if the named service is disabled to start on boot

    CLI Example:

    .. code-block:: bash

        salt '*' service.disabled <service name>
    N(R8RARERHR~(R4((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pytdisabledNs



(1t__doc__t
__future__RRRRGRR;R9RNtsalt.modules.cmdmodRtsalt.utils.filestsalt.utils.pathtsalt.utils.systemdt__func_alias__R
RRR*R1R5R8RARBRERHRIRWRXRYR[R\RZR^R_R`RaRbRcR~RkRnRsRzR|R}RR�(((s@/usr/lib/python2.7/site-packages/salt/modules/upstart_service.pyt<module>.sX
			-															
						3	
					

Zerion Mini Shell 1.0