%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/restartcheck.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlZddlmZdZeZyddlZeZWnek
r�nXdddd	d
ddd
ddddddddddddddgZd�Zd�Zd�Zd�Zd �Zd!�Zd"�Zd#�Zd$�Z d%�Z!d&�Z"dddd'�Z$dS((u�
checkrestart functionality for Debian and Red Hat Based systems

Identifies services (processes) that are linked against deleted files (for example after downloading an updated
binary of a shared library).

Based on checkrestart script from debian-goodies (written  by Matt Zimmerman for the Debian GNU/Linux distribution,
https://packages.debian.org/debian-goodies) and psdel by Sam Morris.

:codeauthor: Jiri Kotlin <jiri.kotlin@ultimum.io>
i(tabsolute_importtunicode_literalstprint_functionN(tsixu	NILinuxRTu
^/var/log/u^/var/local/log/u
^/var/run/u^/var/local/run/u^/tmp/u
^/dev/shm/u^/run/u^/drmu
^/var/tmp/u^/var/local/tmp/u
^/dev/zerou
^/dev/pts/u^/usr/lib/locale/u^/home/u^.*icon-theme.cacheu^/var/cache/fontconfig/u^/var/lib/nagios3/spool/u%^/var/lib/nagios3/spool/checkresults/u^/var/lib/postgresql/u^/var/lib/vdr/u^/[aio]u^/SYSVcC@stS(u`
    Only run this module if the psutil python module is installed (package python-psutil).
    (t
HAS_PSUTIL(((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt__virtual__VscC@sst}|jd�rt}ntjd�j|�r?t}ntjdjt��}|j|�rot}n|S(u�
    Filters file path against unwanted directories and decides whether file is marked as deleted.

    Returns:
        True if file is desired deleted file, else False.

    Args:
        path: A string - path to file
    u
 (deleted)u\(path inode=[0-9]+\)$u|(	tFalsetendswithtTruetretcompiletsearchtjoint	LIST_DIRStmatch(tpathtrettregex((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_valid_deleted_file]s
			c
c@s�g}x�tj�D]�}y�|jdddg�}yetjjjdj|d���=}dtj	|d�d}t
j|�}|j�}WdQXWnt
tfk
r�tVnXtjd�}x�|D]�}tjjj|�}|j|�}	|	sq�n|	jd	�}
|
sq�nt|
�}|s7q�n|d|d|
d
d!f}||kr�|j|�|Vq�q�Wy4x-|D]%}
||
}
t
j|
�}g}t
jj|�r�|j|�n}t
jj|�rH|dkrHx\tjjj|d
t�D]<\}}}x*|D]"}|jt
jj||��qWqWnx^|D]V}t|�}|smqOn|d|d|f}||krO|j|�|VqOqOWq�WWnt
k
r�nXWqtjk
r�qXqWdS(u�
    Iterates over /proc/PID/maps and /proc/PID/fd links and returns list of desired deleted files.

    Returns:
        List of deleted files to analyze, False on failure.

    tattrsupidunameu/proc/{0}/mapsu/proc/u/fd/Nua^[\da-f]+-[\da-f]+ [r-][w-][x-][sp-] [\da-f]+ [\da-f]{2}:[\da-f]{2} (\d+) *(.+)( \(deleted\))?\n$iii����u/tfollowlinks( tpsutiltprocess_itertas_dicttsalttutilstfilestfopentformatRt	text_typetostlistdirt	readlinestOSErrortIOErrorRR	R
tstringutilst
to_unicodeRtgroupRtappendtreadlinkRtisfiletisdirtos_walkRRt
NoSuchProcess(t
deleted_filestproctpinfotmapstdirpathRtmaplinestmaplinetlinetmatchedRtvalidtvaltlinkR't	filenamestroott
dummy_dirsRtnametfilename((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_deleted_filesssd%	



+
'


c
C@s�|s*||}|r&|jd�n|Sd}|r?d}n|rk|djt|��7}|d7}n|r|djt|��7}xC|D];}||d7}x$||dD]}	||	d	7}q�Wq�W|r�|d
7}|d	j|�7}n|r|d7}|d	j|�7}qn|r�|djt|��7}xF|D];}||d7}x$||dD]}	||	d	7}qhWqEWn|S(
u
    Formats the output of the restartcheck module.

    Returns:
        String - formatted output.

    Args:
        kernel_restart: indicates that newer kernel is instaled
        packages: list of packages that should be restarted
        verbose: enables extensive output
        restartable: list of restartable packages
        nonrestartable: list of non-restartable packages
        restartservicecommands: list of commands to restart services
        restartinitcommands: list of commands to restart init.d scripts

    uSystem restart required.uuSystem restart required.

u:Found {0} processes using old versions of upgraded files.
uThese are the packages:
umOf these, {0} seem to contain systemd service definitions or init scripts which can be used to restart them:
u:
u	processesu
u"

These are the systemd services:
u

These are the initd scripts:
uU

These processes {0} do not seem to have an associated init script to restart them:
(R&RtlenR(
tkernel_restarttpackagestverbosetrestartabletnonrestartabletrestartservicecommandstrestartinitcommandsRtpackagetprogram((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_format_output�s@
	
	


	
c	C@sAtdd�}g}g}x!|j�D]}|j|�q)Wy|d}Wntk
rk|d}nX|jd�}tdd|�}xC|j�D]5}|jd�r�|jd�}|j|�Pq�q�Wtdd	kr=|djd
d�}|dd|d}|dd
|d}|j	||g�n|S(u�
    Last installed kernel name, for Debian based systems.

    Returns:
            List with possible names of last installed kernel
            as they are probably interpreted in output of `uname -a` command.
    ucmd.runu#dpkg --get-selections linux-image-*i����iu			installuapt-cache policy u
  Installed: uosuUbuntuu.iu
-generic #u
-lowlatency #(
t__salt__t
splitlinesR&t
IndexErrortrstript
startswithtstript
__grains__trsplittextend(	tkernel_get_selectionstkernelstkernel_versionsR3tkerneltkernel_get_versiontkernel_vtkernel_ubuntu_generictkernel_ubuntu_lowlatency((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_kernel_versions_debian�s,

cC@s�tdd�}g}g}x0|j�D]"}d|kr)|j|�q)q)W|djdd�d}|jd�}|j|�|S(u�
    Name of the last installed kernel, for Red Hat based systems.

    Returns:
            List with name of last installed kernel as it is interpreted in output of `uname -a` command.
    ucmd.runurpm -q --last kernelukernel-iu i(RIRJR&tsplitRN(tkernel_get_lastRSRTR3RU((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_kernel_versions_redhats
cC@sd}d�}tjd�dkr�dtjd�kr�d}d}d}td	d
j||��td	dj|��||�}q�|d�}n`dtjd�kr�tjjtjd
��j	d�}n$tjjtjd��j	d�}|dkr
gS|gS(u�
    Last installed kernel name, for Debian based systems.

    Returns:
            List with possible names of last installed kernel
            as they are probably interpreted in output of `uname -a` command.
    cS@sNd}tddj|��}tj||�}|dkrAdS|jd�S(uS
        Get kernel version from a binary image or None if detection fails
        u[0-9]+\.[0-9]+\.[0-9]+-rt\S+ucmd.runustrings {0}iN(RIRR	RtNoneR%(tkbintkvregextkernel_stringst	re_result((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_get_kver_from_bin8sulsb_distrib_idunilrtuarmucpuarchu/boot/linux_runmode.itbu/var/volatile/tmp/uImage.gzu/var/volatile/tmp/uImageucmd.runu-dumpimage -i {0} -T flat_dt -p0 kernel -o {1}u
gunzip -f {0}u/boot/runmode/bzImageu/boot/uImageuuImage-u
/boot/bzImageubzImage-N(
R^ROtgetRIRRRtbasenameR'RN(tkverRctitb_pathtcompressed_kerneltuncompressed_kernel((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_kernel_versions_nilrt.s 		

'$cC@sI|d}|tttj�d��|krEtjjd��ndS(u�
    Name of the last installed kernel, for Red Hat based systems.

    Returns:
            List with name of last installed kernel as it is interpreted in output of `uname -a` command.
    i`�i�uTimeout expired.N(tinttroundttimeRt
exceptionstTimeoutError(t
start_timettimeoutttimeout_milisec((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_check_timeout\s
&cC@s�d}tjj|�}tjj|dj|��}tjj|dj|��}tjj|�sztjj|�r~tStd|�j�}t	t
tjj|���}||kr�tSt
tddj|�dd��S(	u
    Detect whether a file changed in an NILinuxRT system using md5sum and timestamp
    files from a state directory.

    Returns:
             - False if md5sum/timestamp state files don't exist
             - True/False depending if ``base_filename`` got modified/touched
    u /var/lib/salt/restartcheck_stateu
{0}.timestampu
{0}.md5sumu	file.readucmd.retcodeumd5sum -cs {0}toutput_logleveluquiet(RRReRRtexistsRRIRLtstrRktgetmtimeRtbool(t
full_filepathtrs_state_dirt
base_filenamettimestamp_filetmd5sum_filetprev_timestampt
cur_timestamp((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_file_changed_nilrths	&cC@s#|dk	rtdj|��StS(ug
    Once a NILRT kernel module is inserted, it can't be rmmod so systems need
    rebooting (some modules explicitly ask for reboots even on first install),
    hence this functionality of determining if the module state got modified by
    testing if depmod was run.

    Returns:
             - True/False depending if modules.dep got modified/touched
    u/lib/modules/{0}/modules.depN(R^R�RR(t
kernelversion((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_kernel_modules_changed_nilrt�s
cC@s&d}tjj|�r"t|�StS(uZ
    Besides the normal Linux kernel driver interfaces, NILinuxRT-supported hardware features an
    extensible, plugin-based device enumeration and configuration interface named "System API".
    When an installed package is extending the API it is very hard to know all repercurssions and
    actions to be taken, so reboot making sure all drivers are reloaded, hardware reinitialized,
    daemons restarted, etc.

    Returns:
             - True/False depending on if nisysapi.ini got modified/touched
             - False if nisysapi.ini does not exist to avoid triggering unnecessary reboots
    u%/usr/local/natinst/share/nisysapi.ini(RRRuR�R(t
nisysapi_path((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt_sysapi_changed_nilrt�s
c+K@s�tjjj|�}tttj�d��}t}|jdt�}|jdd�}t	j
d�dkr�d}d}	d	}
t�}nrt	j
d�d
kr�d}d}	d
}
t�}n?t	j
d�t
kr�d}d}
t�}nitd6dd6Stdd�}xj|D]b}
t||�|
|krt	j
d�dkrot|
�rvt�rvt}Pqvqyt}PqqWi}i}g}|r�t|t�s�|g}q�nddg}|r�t|t�s�|g}q�ng}|r
t|t�s|g}qng}xUtd�D]F}t||�td|�}d|kr!t|d�||<q!q!Wi}xt�D]}|tkr�itd6dd6St||�|d|d|d}}}||ks{||kr�q{nytjdj|��}Wn!tk
r)|j|�q{nXy||}Wn:tk
rttd |�}|sg|}n|||<nXxb|D]Z}t||�||kr||||kr||r�||kr�|j|�|}q�q|q|W|r{||kr{d!tj|�d"|d#tj|�d$}||krTigd%6gd&6|gd'6|d(6||<q�|||d'kr�||d'j|�q�q{q{W|r�|r�d)Sx�|D]�}t||�||}tj |d*td+tj!�}x�trbt||�|j"j#�}|s
Pn|d, } | j$d-�rO| j%d.�rO||d%j| d/�ntj&j'|
�rR| j$|	�rR| j%d0�rR| j(d1�d,krRt}!ytjj)j*| �}"Wnt+k
r�q�nXt,|	�}#xJ|"j-�D]<}tjj.j/|�}|j(d2�dkr�t}!q�q�q�W|"j0�|!sR||d&j| |#�qRnt1j"j2�q�W|j"j0�q�Wx�|D]�}t||�||d&r{||d%r{td3||d(�}|r+tj&j'd-||d(�r||d%j||d(�q(||d&j||d(�q+q{q{Wg}$g}%g}&g}'x�|D]�}t||�||d%r�|$j|�|&j3g||d%D]}(d4|(d5^q��nW||d&r�|$j|�|'j3g||d&D]}(d6|(^q��n
|%j|�||d(|krN|j4||d(�qNqNWx/|D]'})t||�|'j3d6|)g�q=Wt5||||$|%|'|&�}*|*S(7u�
    Analyzes files openeded by running processes and seeks for packages which need to be restarted.

    Args:
        ignorelist: string or list of packages to be ignored
        blacklist: string or list of file paths to be ignored
        excludepid: string or list of process IDs to be ignored
        verbose: boolean, enables extensive output
        timeout: int, timeout in minute

    Returns:
        Dict on error: { 'result': False, 'comment': '<reason>' }
        String with checkrestart output if some package seems to need to be restarted or
        if no packages need restarting.

    .. versionadded:: 2015.8.3

    CLI Example:
    .. code-block:: bash

        salt '*' restartcheck.restartcheck
    i�uverboseutimeoutiu	os_familyuDebianudpkg-query --listfiles u/lib/systemd/system/u/bin/systemduRedHatu
repoquery -l u/usr/lib/systemd/system/u/usr/bin/systemctluopkg files uuresultuGOnly available on Debian, Red Hat and NI Linux Real-Time based systems.ucommentucmd.runuuname -au	NILinuxRTuscreenusystemduservice.get_runninguservice.showuExecMainPIDu;Could not get list of processes. (Do you have root access?)iiiu
/proc/{0}/exeu	pkg.owneru	u u (file: u)uinitscriptsusystemdserviceu	processesuprocess_nameu)No packages seem to need to be restarted.tshelltstdouti����u/etc/init.d/u.shiu.serviceu.wantsuType=oneshotuservice.availableuservice u restartusystemctl restart (6RRtargstclean_kwargsRkRlRmRtpopRORdRZR]tNILRT_FAMILY_NAMERjRRIRsR�R�t
isinstancetlistR=RR'RR!R&tKeyErrorRRt
subprocesstPopentPIPER�treadlineRMRRRutfindRRR"R>R R#R$tclosetsystflushRQtremoveRH(+t
ignorelistt	blacklistt
excludepidtkwargsRpR?RARqt
cmd_pkg_querytsystemd_foldertsystemdRTtkernel_currentRUR@trunning_servicestrestart_servicestservicetservice_showtowners_cachetdeleted_fileR;tpidRR'tpackagenametrunning_serviceRGRFtcmdtpathsR3tptht
is_oneshottservicefiletsysfold_lenRBRCRERDtstrestart_serviceR((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pytrestartcheck�s 



 


	


0


	

0
	


 '


3
/


(%t__doc__t
__future__RRRRR	R�R�Rmtsalt.exceptionsRtsalt.utils.argstsalt.utils.filestsalt.utils.pathtsalt.extRR�RRRRtImportErrorR
RRR=RHRZR]RjRsR�R�R�R^R�(((s=/usr/lib/python2.7/site-packages/salt/modules/restartcheck.pyt<module>sh

				F	:	&		.				

Zerion Mini Shell 1.0