%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/cron.pyo

�
���^c@@sdZddlmZmZmZddlZddlZddlm	Z	m
Z
ddlmZd�Z
dddddddddd�	Zdd�Zd	�Zd
ddddddeedd�
Zd
edd
�Zddd
ddeddd�Zdd
d�Zd
d�ZdS(uY
Management of cron, the Unix command scheduler
==============================================

Cron declarations require a number of parameters. The following are the
parameters used by Salt to define the various timing values for a cron job:

* ``minute``
* ``hour``
* ``daymonth``
* ``month``
* ``dayweek`` (0 to 6 are Sunday through Saturday, 7 can also be used for
  Sunday)

.. warning::

    Any timing arguments not specified take a value of ``*``. This means that
    setting ``hour`` to ``5``, while not defining the ``minute`` param, will
    result in Salt adding a job that will execute every minute between 5 and 6
    A.M.!

    Additionally, the default user for these states is ``root``. Therefore, if
    the cron job is for another user, it is necessary to specify that user with
    the ``user`` parameter.

A long time ago (before 2014.2), when making changes to an existing cron job,
the name declaration is the parameter used to uniquely identify the job,
so if an existing cron that looks like this:

.. code-block:: yaml

    date > /tmp/crontest:
      cron.present:
        - user: root
        - minute: 5

Is changed to this:

.. code-block:: yaml

    date > /tmp/crontest:
      cron.present:
        - user: root
        - minute: 7
        - hour: 2

Then the existing cron will be updated, but if the cron command is changed,
then a new cron job will be added to the user's crontab.

The current behavior is still relying on that mechanism, but you can also
specify an identifier to identify your crontabs:

.. code-block:: yaml

    date > /tmp/crontest:
      cron.present:
        - identifier: SUPERCRON
        - user: root
        - minute: 7
        - hour: 2

.. versionadded:: 2014.1.2

And, some months later, you modify it:

.. code-block:: yaml

    superscript > /tmp/crontest:
      cron.present:
        - identifier: SUPERCRON
        - user: root
        - minute: 3
        - hour: 4

.. versionadded:: 2014.1.2

The old **date > /tmp/crontest** will be replaced by
**superscript > /tmp/crontest**.

Additionally, Salt also supports running a cron every ``x minutes`` very similarly to the Unix
convention of using ``*/5`` to have a job run every five minutes. In Salt, this
looks like:

.. code-block:: yaml

    date > /tmp/crontest:
      cron.present:
        - user: root
        - minute: '*/5'

The job will now run every 5 minutes.

Additionally, the temporal parameters (minute, hour, etc.) can be randomized by
using ``random`` instead of using a specific value. For example, by using the
``random`` keyword in the ``minute`` parameter of a cron state, the same cron
job can be pushed to hundreds or thousands of hosts, and they would each use a
randomly-generated minute. This can be helpful when the cron job accesses a
network resource, and it is not desirable for all hosts to run the job
concurrently.

.. code-block:: yaml

    /path/to/cron/script:
      cron.present:
        - user: root
        - minute: random
        - hour: 2

.. versionadded:: 0.16.0

Since Salt assumes a value of ``*`` for unspecified temporal parameters, adding
a parameter to the state and setting it to ``random`` will change that value
from ``*`` to a randomized numeric value. However, if that field in the cron
entry on the minion already contains a numeric value, then using the ``random``
keyword will not modify it.

Added the opportunity to set a job with a special keyword like '@reboot' or
'@hourly'. Quotes must be used, otherwise PyYAML will strip the '@' sign.

.. code-block:: yaml

    /path/to/cron/script:
      cron.present:
        - user: root
        - special: '@hourly'

The script will be executed every reboot if cron daemon support this option.

.. code-block:: yaml

    /path/to/cron/otherscript:
      cron.absent:
        - user: root
        - special: '@daily'

This counter part definition will ensure than a job with a special keyword
is not set.
i(tabsolute_importtunicode_literalstprint_functionN(t
_needs_changet
_cron_matched(tsixcC@sdtkrtStdfSdS(Nu
cron.list_tabucron module could not be loaded(t__salt__tTruetFalse(((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt__virtual__�sc
C@s�|dk	r$tj|�j�}n|dk	rHtj|�j�}n|dk	rltj|�j�}n|dk	r�tj|�j�}n|dk	r�tj|�j�}n|	dk	r�tj|	�}	n|dk	r�|tk}n|dk	rtj|�}ntd|�}|
dkr�xp|dD]�}t|||	�r2tg|d|f|d|f|d|f|d|f|d|f|d|	f|d	|f|d
|f|d|ff	D]\}
}t|
|�^q��r�dSd
Sq2Wn�x�|dD]�}t|||	�rtg|d|
f|d|	f|d	|f|d
|f|d|ffD]\}
}t|
|�^qj�r�dSd
SqWdS(u
    Return the changes
    u
cron.list_tabucronsuminuteuhourudaymonthumonthudayweeku
identifierucmducommentu	commenteduupdateupresentuspecialuspecuabsentN(	tNoneRt	text_typetlowerRRRtanyR(tusertcmdtminutethourtdaymonthtmonthtdayweektcommentt	commentedt
identifiertspecialtlsttcrontxty((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt_check_cron�sN5



5cC@sf|d	krd}ntd|�}x:|dD].}||dkr0||dkrZdSdSq0WdS(
u(
    Return the environment changes
    uu
cron.list_tabuenvunameuvalueuupdateupresentuabsentN(R
R(RtnametvalueRtenv((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt_check_cron_env�s	cC@s�d}tddkr%d}d}nitddkrDd}d}nJtdd	krcd}d
}n+tddkr�d}d}nd}d
}|||fS(uG
    Returns the proper group owner and path to the cron directory
    urootuosuFreeBSDuwheelu/var/cron/tabsuOpenBSDucrontabu	os_familyuSolarisu/var/spool/cron/crontabsuMacOSu/usr/lib/cron/tabsu/var/spool/cron(t
__grains__(townertgrouptcrontab_dir((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt_get_cron_info�s 				urootu*cC@sQ|j�}|	tkr!|}	niid6dd6|d6td6}tdrt|d|d|d	|d
|d|d|d
|d|d|	d|
�
}d|d<|dkr�dj|�|d<nN|dkr�t|d<dj|�|d<n"|dkrdj|�|d<n|S|
dkrktdd|d|d	|d
|d|d|d|d
|d|d|	�
}
n1tdd|d|
d|d
|d|d|	�}
|
dkr�dj|�|d<|S|
dkr�dj||�|d<i||6|d<|S|
dkr*dj|�|d<i||6|d<|Sdj|||
�|d<t|d<|S( u�
    Verifies that the specified cron job is present for the specified user.
    It is recommended to use `identifier`. Otherwise the cron job is installed
    twice if you change the name.
    For more advanced information about what exactly can be set in the cron
    timing parameters, check your cron system's documentation. Most Unix-like
    systems' cron documentation can be found via the crontab man page:
    ``man 5 crontab``.

    name
        The command that should be executed by the cron job.

    user
        The name of the user whose crontab needs to be modified, defaults to
        the root user

    minute
        The information to be set into the minute section, this can be any
        string supported by your cron system's the minute field. Default is
        ``*``

    hour
        The information to be set in the hour section. Default is ``*``

    daymonth
        The information to be set in the day of month section. Default is ``*``

    month
        The information to be set in the month section. Default is ``*``

    dayweek
        The information to be set in the day of week section. Default is ``*``

    comment
        User comment to be added on line previous the cron job

    commented
        The cron job is set commented (prefixed with ``#DISABLED#``).
        Defaults to False.

        .. versionadded:: 2016.3.0

    identifier
        Custom-defined identifier for tracking the cron line for future crontab
        edits. This defaults to the state name

    special
        A special keyword to specify periodicity (eg. @reboot, @hourly...).
        Quotes must be used, otherwise PyYAML will strip the '@' sign.

        .. versionadded:: 2016.3.0
    uchangesuucommentunameuresultutestRRRRRRRRRRuabsentuCron {0} is set to be addedupresentuCron {0} already presentuupdateuCron {0} is set to be updateducron.set_jobRucron.set_specialunewuCron {0} added to {1}'s crontabuupdateduCron {0} updatedu6Cron {0} for user {1} failed to commit with error 
{2}N(tstripRRt__opts__RR
tformatR(RRRRRRRRRRRtrettstatustdata((s4/usr/lib/python2.7/site-packages/salt/states/cron.pytpresentsx?	


		

	
cK@s�|j�}|tkr!|}ni|d6td6id6dd6}tdr�t||d|�}d|d<|dkr�t|d<d	j|�|d<n.|d
ks�|dkr�dj|�|d<n|S|dkr�td
||d|�}ntd||d|d|�}|dkr4dj|�|d<|S|dkrkdj||�|d<i||6|d<|Sdj|||�|d<t|d<|S(ug
    Verifies that the specified cron job is absent for the specified user; only
    the name is matched when removing a cron job.

    name
        The command that should be absent in the user crontab.

    user
        The name of the user whose crontab needs to be modified, defaults to
        the root user

    identifier
        Custom-defined identifier for tracking the cron line for future crontab
        edits. This defaults to the state name

    special
        The special keyword used in the job (eg. @reboot, @hourly...).
        Quotes must be used, otherwise PyYAML will strip the '@' sign.
    unameuresultuchangesuucommentutestRuabsentuCron {0} is absentupresentuupdateuCron {0} is set to be removeducron.rm_jobucron.rm_specialRuCron {0} already absenturemovedu#Cron {0} removed from {1}'s crontabu5Cron {0} for user {1} failed to commit with error {2}N(R'RRR(RR
R)R(RRRRtkwargsR*R+R,((s4/usr/lib/python2.7/site-packages/salt/states/cron.pytabsent�s>	





uc	K@s+d}
ytd|�dd}Wn=tk
raiid6dj|�d6|d6td	6}|SXtjjj�}
tjjj|
d
��T}td|�}|j	d�s�d
j|�}n|j
tjjj|��WdQXiid6dd6|d6t
d	6}|}|rMtj|
�jdkrMdj|�|d<tj|
�|Stdr�tdd|
d|d|d|d|d|d|
dgd|d|d|dt|	�}|\|d	<|d<tj|
�|Std||t�\}}yktd d|
d|d|d|d|d|d|d|
dgdtd|d|d!t|	�
\}}}Wn;tk
r�}t|d	<i|d<d"j|�|d<|SX|r�||d<t|d	<tj|
�|SyStd#d|
d$|d%|d|d&|d|d|d|
dgdtd'|�}Wn;tk
rT}t|d	<i|d<d"j|�|d<|SXd}d(|dkr�td)||
�}|d*dkr�d+j|�|d<t
|d	<|d|d<qd,j||
|d-�|d<t|d	<i|d<n*|d	rd.j|�|d<i|d<ntj|
�|S(/u
    Provides file.managed-like functionality (templating, etc.) for a pre-made
    crontab file, to be assigned to a given user.

    name
        The source file to be used as the crontab. This source file can be
        hosted on either the salt master server, or on an HTTP or FTP server.
        For files hosted on the salt file server, if the file is located on
        the master in the directory named spam, and is called eggs, the source
        string is ``salt://spam/eggs``

        If the file is hosted on a HTTP or FTP server then the source_hash
        argument is also required

    source_hash
        This can be either a file which contains a source hash string for
        the source, or a source hash string. The source hash string is the
        hash algorithm followed by the hash of the file:
        ``md5=e138491e9d5b97023cea823fe17bac22``

    source_hash_name
        When ``source_hash`` refers to a hash file, Salt will try to find the
        correct hash by matching the filename/URI associated with that hash. By
        default, Salt will look for the filename being managed. When managing a
        file at path ``/tmp/foo.txt``, then the following line in a hash file
        would match:

        .. code-block:: text

            acbd18db4cc2f85cedef654fccc4a4d8    foo.txt

        However, sometimes a hash file will include multiple similar paths:

        .. code-block:: text

            37b51d194a7513e45b56f6524f2d51f2    ./dir1/foo.txt
            acbd18db4cc2f85cedef654fccc4a4d8    ./dir2/foo.txt
            73feffa4b7f6bb68e44cf984c85f6e88    ./dir3/foo.txt

        In cases like this, Salt may match the incorrect hash. This argument
        can be used to tell Salt which filename to match, to ensure that the
        correct hash is identified. For example:

        .. code-block:: yaml

            foo_crontab:
              cron.file:
                - name: https://mydomain.tld/dir2/foo.txt
                - source_hash: https://mydomain.tld/hashes
                - source_hash_name: ./dir2/foo.txt

        .. note::
            This argument must contain the full filename entry from the
            checksum file, as this argument is meant to disambiguate matches
            for multiple files that have the same basename. So, in the
            example above, simply using ``foo.txt`` would not match.

        .. versionadded:: 2016.3.5

    user
        The user to whom the crontab should be assigned. This defaults to
        root.

    template
        If this setting is applied then the named templating engine will be
        used to render the downloaded file. Currently, jinja and mako are
        supported.

    context
        Overrides default context variables passed to the template.

    replace
        If the crontab should be replaced, if False then this command will
        be ignored if a crontab exists for the specified user. Default is True.

    defaults
        Default context passed to the template.

    backup
        Overrides the default backup mode for the user's crontab.
    u0600u	user.infougroupsiuchangesu%Could not identify group for user {0}ucommentunameuresultuw+u
cron.raw_cronu
u{0}
Nuu/User {0} already has a crontab. No changes madeutestufile.check_managedRtsourcetsource_hashtsource_hash_nameRR$tmodetattrsttemplatetcontexttdefaultstsaltenvufile.source_listufile.get_managedtskip_verifyuUnable to manage file: {0}ufile.manage_filetsfnR*t
source_sumtbackupudiffucron.write_cron_file_verboseuretcodeu Crontab for user {0} was updatedu1Unable to update user {0} crontab {1}. Error: {2}ustderru,Crontab for user {0} is in the correct state(Rt	ExceptionR)Rtsalttutilstfilestmkstemptfopentendswithtwritetstringutilstto_strRtoststattst_sizetunlinkR(t__env__R
(RR1R2RR5R6treplaceR7R<R.R3R$R*t	cron_pathtfp_traw_cronR0tfcmR:R;Rtexctcron_ret((s4/usr/lib/python2.7/site-packages/salt/states/cron.pytfile�s�\


"




	


















cC@s�iid6dd6|d6td6}tdr�t||d|�}d|d<|dkrmd	j|�|d<nN|d
kr�t|d<dj|�|d<n"|dkr�d
j|�|d<n|Std||d|�}|d
kr�dj|�|d<|S|dkr2dj||�|d<i||6|d<|S|dkrfdj|�|d<i||6|d<|Sdj|||�|d<t|d<|S(uv
    Verifies that the specified environment variable is present in the crontab
    for the specified user.

    name
        The name of the environment variable to set in the user crontab

    user
        The name of the user whose crontab needs to be modified, defaults to
        the root user

    value
        The value to set for the given environment variable
    uchangesuucommentunameuresultutestRuabsentuCron env {0} is set to be addedupresentuCron env {0} already presentuupdateu!Cron env {0} is set to be updateducron.set_envunewu#Cron env {0} added to {1}'s crontabuupdateduCron env {0} updatedu:Cron env {0} for user {1} failed to commit with error 
{2}N(RR(R!R
R)RR(RRRR*R+R,((s4/usr/lib/python2.7/site-packages/salt/states/cron.pytenv_present�s>





cC@sC|j�}i|d6td6id6dd6}tdr�t||�}d|d<|dkr}t|d<dj|�|d<n.|d	ks�|d
kr�dj|�|d<n|Std||�}|dkr�d
j|�|d<|S|dkrdj||�|d<i||6|d<|Sdj|||�|d<t|d<|S(u4
    Verifies that the specified environment variable is absent from the crontab
    for the specified user

    name
        The name of the environment variable to remove from the user crontab

    user
        The name of the user whose crontab needs to be modified, defaults to
        the root user
    unameuresultuchangesuucommentutestuabsentuCron env {0} is absentupresentuupdateu!Cron env {0} is set to be removeducron.rm_envuCron env {0} already absenturemovedu'Cron env {0} removed from {1}'s crontabu9Cron env {0} for user {1} failed to commit with error {2}N(R'RR(R!R
R)RR(RRR*R+R,((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt
env_absent�s6





(t__doc__t
__future__RRRRGtsalt.utils.filesR>tsalt.modules.cronRRtsalt.extRR	R
RR!R&RR-R/RRSRTRU(((s4/usr/lib/python2.7/site-packages/salt/states/cron.pyt<module>�sR		0	x?�4

Zerion Mini Shell 1.0