%PDF- %PDF-
Direktori : /usr/lib/python2.7/site-packages/salt/states/ |
Current File : //usr/lib/python2.7/site-packages/salt/states/cron.pyo |
� ���^c @@ s d Z d d l m Z m Z m Z d d l Z d d l Z d d l m Z m Z d d l m Z d � Z d d d d d d d d d d � Z d d � Z d � Z d d d d d d d e e d d � Z d e d d � Z d d d d d e d d d � Z d d d � Z d d � Z d S( 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 ( t absolute_importt unicode_literalst print_functionN( t _needs_changet _cron_matched( t sixc C@ s d t k r t St d f Sd S( Nu cron.list_tabu cron module could not be loaded( t __salt__t Truet False( ( ( s4 /usr/lib/python2.7/site-packages/salt/states/cron.pyt __virtual__� s c C@ s� | d k r$ t j | � j � } n | d k rH t j | � j � } n | d k rl t j | � j � } n | d k r� t j | � j � } n | d k r� t j | � j � } n | d k r� t j | � } n | d k r� | t k } n | d k rt j | � } n t d | � } | d k r�xp| d D]� } t | | | � r2t g | d | f | d | f | d | f | d | f | d | f | d | f | d | f | d | f | d | f f D] \ } } t | | � ^ q�� r�d Sd Sq2Wn� x� | d D]� } t | | | � rt g | d | f | d | f | d | f | d | f | d | f f D] \ } } t | | � ^ qj� r�d Sd SqWd S( u Return the changes u cron.list_tabu cronsu minuteu houru daymonthu monthu dayweeku identifieru cmdu commentu commentedu updateu presentu specialu specu absentN( t NoneR t text_typet lowerR R R t anyR ( t usert cmdt minutet hourt daymontht montht dayweekt commentt commentedt identifiert specialt lstt cront xt y( ( s4 /usr/lib/python2.7/site-packages/salt/states/cron.pyt _check_cron� sN 5 5c C@ sf | d k r d } n t d | � } x: | d D]. } | | d k r0 | | d k rZ d Sd Sq0 Wd S( u( Return the environment changes u u cron.list_tabu envu nameu valueu updateu presentu absentN( R R ( R t namet valueR t env( ( s4 /usr/lib/python2.7/site-packages/salt/states/cron.pyt _check_cron_env� s c C@ s� d } t d d k r% d } d } ni t d d k rD d } d } nJ t d d k rc d } d } n+ t d d k r� d } d } n d } d } | | | f S( uG Returns the proper group owner and path to the cron directory u rootu osu FreeBSDu wheelu /var/cron/tabsu OpenBSDu crontabu os_familyu Solarisu /var/spool/cron/crontabsu MacOSu /usr/lib/cron/tabsu /var/spool/cron( t __grains__( t ownert groupt crontab_dir( ( s4 /usr/lib/python2.7/site-packages/salt/states/cron.pyt _get_cron_info� s u rootu *c C@ sQ | j � } | t k r! | } n i i d 6d d 6| d 6t d 6} t d rt | d | d | d | d | d | d | d | d | d | d | � } d | d <| d k r� d j | � | d <nN | d k r� t | d <d j | � | d <n"