Your IP : 3.15.186.27


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_service.cpython-36.pyc

3

�<�e�)�@s�ddlmZddlZddljZddlTddlZddlZddlZ	ddl
mZe	jj
�Ze�ZGdd�d�ZGdd	�d	�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dej�ZdS)�)�base�N)�*)�commandsc@seZdZddd�ZdS)�ServiceNcCs||_||_||_||_dS)N)�enable�start�cfg_file�runlevel)�selfrrr	r
�r�$/usr/lib/python3.6/plugin_service.py�__init__szService.__init__)NNNN)�__name__�
__module__�__qualname__rrrrr
r
src@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�InitHandlercCs(tjdg�\}}|dkr$|j�dSdS)Nr
rr���)�cmd�execute�split)r�retcode�outrrr
�runlevel_getszInitHandler.runlevel_getcCstjddg�dS)NZtelinit�q)rr)rrrr
�
daemon_reloadszInitHandler.daemon_reloadcCsdS)Nr)r�namer	rrr
�cfg_installszInitHandler.cfg_installcCsdS)Nr)rrr	rrr
�
cfg_uninstallszInitHandler.cfg_uninstallcCsdS)Nr)rrr	rrr
�
cfg_verify"szInitHandler.cfg_verifyN)rrrrrrrrrrrr
rs
rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�SysVBasicHandlercCstjd|dg�dS)N�servicer)rr)rrrrr
r'szSysVBasicHandler.startcCstjd|dg�dS)Nr!�stop)rr)rrrrr
r"*szSysVBasicHandler.stopcCs
t��dS)N)�NotImplementedError)rrr
rrr
r-szSysVBasicHandler.enablecCs
t��dS)N)r#)rrr
rrr
�disable0szSysVBasicHandler.disablecCs"tjd|dgdgd�\}}|dkS)Nr!�statusr)�	no_errors)rr)rrrrrrr
�
is_running3szSysVBasicHandler.is_runningcCs
t��dS)N)r#)rrr
rrr
�
is_enabled7szSysVBasicHandler.is_enabledN)	rrrrr"rr$r'r(rrrr
r &sr c@s$eZdZdd�Zdd�Zdd�ZdS)�SysVHandlercCstjdd||dg�dS)N�	chkconfigz--level�on)rr)rrr
rrr
r;szSysVHandler.enablecCstjdd||dg�dS)Nr*z--level�off)rr)rrr
rrr
r$>szSysVHandler.disablecCsBtjdd|g�\}}|dkr>|jdt|��ddd�dkSdS)Nr*z--listrz%s:r�r+)rrr�str)rrr
rrrrr
r(AszSysVHandler.is_enabledN)rrrrr$r(rrrr
r):sr)c@s$eZdZdd�Zdd�Zdd�ZdS)�
SysVRCHandlercCstjdd||dg�dS)Nzsysv-rc-confz--levelr+)rr)rrr
rrr
rFszSysVRCHandler.enablecCstjdd||dg�dS)Nzsysv-rc-confz--levelr,)rr)rrr
rrr
r$IszSysVRCHandler.disablecCsBtjdd|g�\}}|dkr>|jdt|��ddd�dkSdS)Nzsysv-rc-confz--listrz%s:rr-r+)rrrr.)rrr
rrrrr
r(LszSysVRCHandler.is_enabledN)rrrrr$r(rrrr
r/Esr/c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�
OpenRCHandlercCs&tjddg�\}}|dkr"|j�SdS)Nz	rc-statusz-rr)rr�strip)rrrrrr
rQszOpenRCHandler.runlevel_getcCstjd|dg�dS)Nz
rc-servicer)rr)rrrrr
rUszOpenRCHandler.startcCstjd|dg�dS)Nz
rc-servicer")rr)rrrrr
r"XszOpenRCHandler.stopcCstjdd||g�dS)Nz	rc-update�add)rr)rrr
rrr
r[szOpenRCHandler.enablecCstjdd||g�dS)Nz	rc-update�del)rr)rrr
rrr
r$^szOpenRCHandler.disablecCs"tjd|dgdgd�\}}|dkS)Nz
rc-servicer%r)r&)rr)rrrrrrr
r'aszOpenRCHandler.is_runningcCs2tjdd|g�\}}ttjdtj|�d|��S)Nz	rc-updateZshowz\b)rr�bool�re�search�escape)rrr
rrrrr
r(eszOpenRCHandler.is_enabledN)
rrrrrr"rr$r'r(rrrr
r0Psr0c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�SystemdHandlercCsdS)N�r)rrrr
rkszSystemdHandler.runlevel_getcCstjdd|g�dS)N�	systemctlZrestart)rr)rrrrr
rnszSystemdHandler.startcCstjdd|g�dS)Nr:r")rr)rrrrr
r"qszSystemdHandler.stopcCstjdd|g�dS)Nr:r)rr)rrr
rrr
rtszSystemdHandler.enablecCstjdd|g�dS)Nr:r$)rr)rrr
rrr
r$wszSystemdHandler.disablecCs"tjdd|gdgd�\}}|dkS)Nr:z	is-activer)r&)rr)rrrrrrr
r'zszSystemdHandler.is_runningcCs>tjdd|gdgd�\}}|j�}|dkr.dS|dkr:dSdS)	Nr:z
is-enabledr)r&ZenabledTZdisabledF)rrr1)rrr
rrr%rrr
r(~szSystemdHandler.is_enabledcCs�tjd||f�tjj|�s0tjd|�dStj|}ytj|tj	�Wn2t
k
r~}ztjd||f�dSd}~XnXtj||�|j
�dS)NzCinstalling service configuration overlay file '%s' for service '%s'z)Unable to find service configuration '%s'z#Unable to create directory '%s': %s)�log�info�os�path�exists�error�consts�SERVICE_SYSTEMD_CFG_PATH�makedirsZDEF_SERVICE_CFG_DIR_MODE�OSErrorr�copyr)rrr	�dirpath�errr
r�s
zSystemdHandler.cfg_installcCsntjd||f�tj|}d|tjj|�f}tj|�|j	�ytj
|�Wnttfk
rhYnXdS)NzEuninstalling service configuration overlay file '%s' for service '%s'z%s/%s)
r;r<rArBr=r>�basenamer�unlinkr�rmdir�FileNotFoundErrorrD)rrr	rFr>rrr
r�s

zSystemdHandler.cfg_uninstallcCs�|dkrdSdtj|tjj|�f}tjj|�sHtjd||f�dStjj|�sjtjd||f�dStj	|�}tj	|�}||kS)Nz%s/%sz.Unable to find service '%s' configuration '%s'Fz0Service '%s' configuration not installed in '%s')
rArBr=r>rHr?r;r@rZ	sha256sum)rrr	r>Z
sha256sum1Z
sha256sum2rrr
r�s

zSystemdHandler.cfg_verifyN)
rrrrrr"rr$r'r(rrrrrrr
r8isr8csneZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
jfdd�Z�ZS)�
ServicePlugina1
	`service`::
	
	Plug-in for handling sysvinit, sysv-rc, openrc and systemd services.
	+
	The syntax is as follows:
	+
	[subs="+quotes,+macros"]
	----
	[service]
	service.__service_name__=__commands__[,file:__file__]
	----
	+
	Supported service-handling `_commands_` are `start`, `stop`, `enable`
	and `disable`. The optional `file:__file__` directive installs an overlay
	configuration file `__file__`. Multiple commands must be comma (`,`)
	or semicolon (`;`) separated. If the directives conflict, the last
	one is used.
	+
	The service plugin supports configuration overlays only for systemd.
	In other init systems, this directive is ignored. The configuration
	overlay files are copied to `/etc/systemd/system/__service_name__.service.d/`
	directories. Upon profile unloading, the directory is removed if it is empty.
	+
	With systemd, the `start` command is implemented by `restart` in order
	to allow loading of the service configuration file overlay.
	+
	NOTE: With non-systemd init systems, the plug-in operates on the
	current runlevel only.
	+
	.Start and enable the `sendmail` service with an overlay file
	====
	----
	[service]
	service.sendmail=start,enable,file:${i:PROFILE_DIR}/tuned-sendmail.conf
	----
	The internal variable `${i:PROFILE_DIR}` points to the directory
	from which the profile is loaded.
	====
	cs&tt|�j||�d|_|j�|_dS)NT)�superrLrZ_has_dynamic_options�_detect_init_system�
_init_handler)r�args�kwargs)�	__class__rr
r�szServicePlugin.__init__cCstj|dgd�\}}|dkS)Nr)r&)rr)rZcommandrrrrr
�
_check_cmd�szServicePlugin._check_cmdcCs�|jddg�rtjd�t�S|jdg�r:tjd�t�S|jddg�rXtjd�t�S|jd	dg�rvtjd
�t�Stjd��dS)Nr:r%zdetected systemdr*zdetected generic sysvinitzupdate-rc.dz-hzdetected sysv-rcz	rc-updatezdetected openrcz8Unable to detect your init system, disabling the plugin.)	rSr;�debugr8r)r/r0�
exceptionsZNotSupportedPluginException)rrrr
rN�s



z!ServicePlugin._detect_init_systemcCs�tjd|�}t�}x~|D]v}|dkr,d|_q|dkr<d|_q|dkrLd|_q|dkr\d|_q|dd�d	kr||dd�|_qtjd
||f�qW|S)Nz
\s*[,;]\s*rTr$Frr"�zfile:z*service '%s': invalid service option: '%s')r5rrrrr	r;r@)rr�val�lr!�irrr
�_parse_service_options�s
z$ServicePlugin._parse_service_optionscs6d|_d|_tj�fdd�|jj�D���_i|_dS)NFTcsTg|]L\}}|dd�dkrt|�dkr|dd��j|dd��jj|��f�qS)N�zservice.)�lenrZZ
_variables�expand)�.0Zoption�value)rrr
�
<listcomp>sz0ServicePlugin._instance_init.<locals>.<listcomp>)Z_has_dynamic_tuningZ_has_static_tuning�collections�OrderedDictZoptions�items�	_services�_services_original)r�instancer)rr
�_instance_inits
zServicePlugin._instance_initcCsdS)Nr)rrfrrr
�_instance_cleanup	szServicePlugin._instance_cleanupcCsT|r|jj|�n|dk	r&|jj|�|r:|jj||�n|dk	rP|jj||�dS)N)rOrr"rr$)rrrrr
rrr
�_process_serviceszServicePlugin._process_servicecCs�|jj�}|dkr tjd�dSx�|jj�D]�}|jj|d|�}|jj|d�}t|||dj	|�|j
|d<|dj	r�|jj|d|dj	�|j|d|dj
|dj|�q,WdS)NzCannot detect runlevelrr)rOrr;r@rdrcr(r'rr	rerrirr)rrfr
r!r(r'rrr
�_instance_apply_statics


z$ServicePlugin._instance_apply_staticc
CsH|jj�}|dkr&tjtjd�dSd}�x|jj�D�]}|jj|d|dj	�}|r~tj
tjd|d|dj	f�nR|dk	r�tjtjd|d|dj	f�d}n"tj
tjd|d|dj	f�|jj
|d|�}|jj|d�}	|jd	|d|dj|	|�dk�rd}|jd
|d|dj||�dkr8d}q8W|S)Nzcannot detect runlevelFTrrz'service '%s' configuration '%s' matchesz'service '%s' configuration '%s' differszservice '%s' configuration '%s'z
%s runningz
%s enabled)rOrr;r@rAZSTR_VERIFY_PROFILE_FAILrdrcrr	r<ZSTR_VERIFY_PROFILE_OKZ STR_VERIFY_PROFILE_VALUE_MISSINGr(r'Z
_verify_valuerr)
rrfZignore_missingZdevicesr
�retr!Zret_cfg_verifyr(r'rrr
�_instance_verify_static$s(
$""$"z%ServicePlugin._instance_verify_staticcCsLxFt|jj��D]4\}}|jr.|jj||j�|j||j|j|j	�qWdS)N)
�listrercr	rOrrirrr
)rrfZrollbackrr_rrr
�_instance_unapply_static<sz&ServicePlugin._instance_unapply_static)rrr�__doc__rrSrNrZrgrhrirjrlrAZ
ROLLBACK_SOFTrn�
__classcell__rr)rRr
rL�s(	
rL)r9rraZtuned.constsrAZ
decoratorsr=r5Z
tuned.logsZtunedZtuned.utils.commandsrZlogs�getr;rrrr r)r/r0r8ZPluginrLrrrr
�<module>s"

B

?>