Server IP : 104.244.120.118  /  Your IP : 216.73.216.198
Web Server : Apache
System : Linux ded5817.inmotionhosting.com 5.14.0-741.22.1.el9_9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov 12 14:34:46 UTC 2026 x86_64
User : persoanlinjuryla ( 1006)
PHP Version : 8.5.13
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF
Directory (0755) :  /../../opt/dedrads/python/../python/../python/../python/../__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //../../opt/dedrads/python/../python/../python/../python/../__pycache__/first_setup.cpython-313.pyc
�

�i�j�J���SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKr"SS5rSr
\S:Xa\
"5 gg)a$
script to resolve known issues with new vps/dedi
and improve thier default configurations
it is to be ran with -c on provision to alert of issues via STR/stdout
-c is fast, but without flag does all the stuff that is slow (~30s)
will not send STRs unless the -s flag is used
Author: MathewL
�Nc��\rSrSrSrSrSSjrSrSrSSjr	Sr
S	rS
rSr
SrS
rSrSrSrSrSSjrSrSrg)�
FirstSetup�c��SUlSUlUR5 UR5 UR	5 [
R"5Ulg)N�)�str_msg�run_log�get_args�is_a_vps�
get_mem_total�socket�gethostname�	host_name��selfs �/opt/dedrads/first_setup.py�__init__�FirstSetup.__init__s>���������
�
���
�
�������+�+�-���c�<�[R"5nURSSSSSS9 URSSSSS	S9 URS
SSSSS9 URS
SSSSS9 URSSSSSS9 URSSSSSS9 UR5Ulg)z
argz
�-sz
--send-str�
store_trueFz2Silence most output, sends STR to T2S for errors.
)�action�default�helpz-nz--no-ea4z(Skips installing missing apache modules
z-v�	--verbosezEnables verbose output with -s
z-cz--checkz1Performs the new server checks instead of tweaks
�-az--allzDoes both server tweaks
�-dz
--dns-clusterzChecks dns clustering
N)�argparse�ArgumentParser�add_argument�
parse_args�args)r�parsers  rr
�FirstSetup.get_argss����(�(�*���������G�	�	
�	�������=�	�	
�	�������4�	�	
�	�������F�	�	
�	�������-�	�	
�	�������+�	�	
��%�%�'��	rc��U(aUnO[R"U5nURSUS35 [R"U[R
SUSS9nWRnURS	US3SS
9 U$![a5nSUSUS3nURU5 URU5 SnAN\SnAff=f)z1
runs subprocess, builds log var, returns stdout
zEXEC: �
TF)�stdout�text�shell�checkzError on cmd:
z	
Output:
NzOUT: ��end)	�shlex�join�log�sp�run�PIPE�	Exception�log_strr()r�cmdr*�	input_str�ret�e�	error_str�results        r�run_cmd�FirstSetup.run_cmdPs�����I��
�
�3��I����6�)��B�'�(�	$��&�&��B�G�G�$�e�5��C��������5����#���.��
��
�	$�)�)��K��s�"�E�I��H�H�Y���L�L��#�#��	$�s�&A?�?
B>�	+B9�9B>c	��UR(aSnOSn[R"SSUSUR3SURSURS3S9 g
![R
anUR
S	U35 S
nAg
S
nAff=f)z
create an STR ticket
�VPSzDedicated Serverzstr@imhadmin.netzNew z with errors: z0Errors encountered during first_setup.py:
Host: r')�dest�subject�bodyzFailed to create STR ticket - N)�is_vps�rads�make_ticketrr�TicketErrorr0)r�
server_string�excs   r�make_str�FirstSetup.make_stres����;�;�!�M�.�M�
	=����'��}�o�^�D�N�N�;K�L���~�~���������
�����	=��H�H�5�c�U�;�<�<��	=�s�AA�B�.B�Bc��UR(a<URR(a!URS5 UR	5 UR(d1URR(a[
R"S5 [UR=(d S5 [
R"S5 g)z8
finishes program and handles final output (str/stdout)
z
creating str
rzfirst_setup complete.N)rr#�send_strr0rI�sys�exit�printrs r�final_output�FirstSetup.final_outputysh���<�<�D�I�I�.�.��H�H�%�&��M�M�O��|�|��	�	� 2� 2��H�H�Q�K�
�d�l�l�5�5�6�����rc��U(dSnURR(aURR(a
[USS9 U=RU-
slU(aYSnU=RU-
slURR(aURR(a[USS9 ggg)z
logging function
r'rr,�----------
N)r#rL�verboserOr	)r�liner-�bars    rr0�FirstSetup.log�s�����D��y�y�!�!�T�Y�Y�%6�%6��$�B���������!�C��L�L�C��L��9�9�%�%����):�):��c�r�"�*;�rc�X�U=RS-
slU=RU-
slg)NrS)r)r�msgs  rr5�FirstSetup.log_str�s������'�������rc��URS5 [R"S5 URS5 URS5 URS5 g)z
runs after user provisioning
)zpackage-cleanup�-yz--cleandupesz /var/lib/rsyslog/imjournal.state)�	systemctl�restart�rsyslog)z/scripts/fixquotas)r]r^zsystemd-logindN)r<�os�removers r�refresh_services�FirstSetup.refresh_services�sE��	
���>�?�
�	�	�4�5����8�9����,�-����?�@rc�v�URS5nURS5(aURS5 gg)N)�durz/var/cpanel/clusterz4	zBError: DNS clustering is not set up, /var/cpanel/cluster is empty
)r<�
startswithr5)r�outputs  r�check_clustering�FirstSetup.check_clustering�s8�����A�B�����U�#�#��L�L�1�
�$rc	�6�URSSSUR45nU(dURS5 SnURR(aSnOSnSU3nURS	5n[R"S
SSUS
4[R[R[RS9nURU5upgUR5(aURSU35 SSS5 SnSn	URS5nSU;aAURSRUSRU5SRU	555 gURU	5 URU5 URSSS9 g!,(df   N�=f)z�
checks a few things so the customer wont have to contact us for them
makes an str if issues are found and the -s flag is used (vps auto prov)
otherwise the errors go to stdout (dedi manual prov)
intended to run after user provisioning.
�digz+shortz@nsz'Error: A record for hostname not found
�15z-dsrz/opt/dedrads/first_setup.py �utf-8�at�now�+�minutes)�stdinr(�stderrz5Failed to schedule DNS cluster check with atd. Error:N)�whmapi1�set_tweaksettingz&key=mycnf_auto_adjust_maxallowedpacketzvalue=0)z&/usr/local/cpanel/bin/checkallsslcertsz
--allow-retryr)z/usr/local/cpanel/cpkeycltzUpdate succeededzsError: New server with invalid cPanel license.
stdout:
{}Run these commands after fixing cPanel the license:
{}
{}
� z"service cpanel restart &>/dev/nullT�r*)r<rr5r#�dns_cluster�encoder1�Popenr3�DEVNULL�communicate�poll�formatr/)
rrg�delay�flags�p_cmd�proc�_rs�	tweak_cmd�ssl_cmds
          r�check_things�FirstSetup.check_things�sp�����u�h��t�~�~�F�G����L�L�C�D����9�9� � ��E��E�.�u�g�6�����W�%��
�X�X�
�5�#�u�i�0��'�'��:�:��7�7�	
���(�(��/�I�A��y�y�{�{�����#�H�&��
�
�	�
�����=�>���V�+��L�L��"�6���H�H�Y�'��H�H�W�%��		
�
�L�L��!��L�L��#�
�L�L�=�T�L�J�W
�
�s�6=F
�

Fc��[RRS5(aURS5 UR(a"URS5 URSSS9 g	URS5 URS5 g	)
z�
These operations are kinda slow (30 seonds or so)
So they are best to be ran before the customer pays
They also do not require a valid cpanel license
�"/usr/sbin/yum-complete-transaction)r�r\)�yumr\�installzperl-File-Slurpz	perl-YAMLzperl-YAML-Syckzperl-Template-Toolkitzfyes y | cpan -i Switch LWP::Protocol::https IO::Scalar Date::Parse Text::Template CDB_File &>/dev/nullTrw)�cpanz-izJSON::XS)�kcarectlz-uN)r`�path�existsr<rCrs r�tune_system�FirstSetup.tune_system�sv���7�7�>�>�>�?�?��L�L�E�F��;�;��L�L��

�
�L�L�+��
�

�
�L�L�3�4��L�L�+�,rc��UR(agUR/SQ5 URS5 URSS/5 URSS/5 g)z8Sets swappiness to 0 and clears swap if dedicated serverN)�sysctlz-wzvm.swappiness=0zSwap is now clearing
�swapoffr�swapon)rCr<r0rs r�set_swappiness�FirstSetup.set_swappinesssH���;�;�����8�9����)�*����i��&�'����h��%�&rc�@�URR(agSn[RR	U5(dURSR
U5SS9 SnSnUHnSUS	3nS
US3nURXTXS9 M! URS
SU45 g)z!
Installs missing Apache modules
Nz(/etc/cpanel/ea4/profiles/custom/imh.jsonz>missing ea4 profile, skipping apache module install. path:
{}
Tr,)zea-apache24-mod_headerszea-apache24-mod_envzea-apache24-mod_suexeczea-apache24-mod_versionzea-apache24-mod_proxy_fcgizea-apache24-mod_remoteipz"ea-apache24",z	\s*("|')?z("|')?,z      "z",)�afterz!/usr/local/bin/ea_install_profilez	--install)	r#�no_ea4r`r��isfiler0r~�conf_setr<)r�ea_file�ea4_tupr��value�searchs      r�tune_ea4�FirstSetup.tune_ea4s����9�9����<���w�w�~�~�g�&�&��H�H�9�9?�����
�
�
��!���E�#�E�7�'�4�F���w�b�+�E��M�M�&��M�>��	
���
0�+�w�G�	
rc�f�SnSn[[R"URS-S-55nUS:�aSnOUS:aSnUS-nS	nUR	S
SUS3US
S9 UR	SSUS3US
S9 UR	SSUS3US
S9 UR	SSUS3US
S9 UR
(acUR
S5 Sn[R"S5 UR
S5 Sn[USSS9n	U	RU5 SSS5 OUR
S5 URS/5 URSS/5 URS /5 URS!S"S#9 g![[4anUR
US35 SnAN�SnAff=f!,(df   N�=f)$z'Does math to figure out Apache settings��i������
�z/etc/cpanel/ea4/ea4.confz+(^\s*"minspareservers"\s*:\s*"?)\d+("?)[^$]z\g<1>z\g<2>,F)�fallbackz+(^\s*"maxspareservers"\s*:\s*"?)\d+("?)[^$]z'(^\s*"serverlimit"\s*:\s*"?)\d+("?)[^$]z&(^\s*"maxclients"\s*:\s*"?)\d+("?)[^$]z"Setting FPM default pool settings
z3pm_process_idle_timeout : 30
pm_max_requests : 128
z/var/cpanel/ApachePHPFPMr'NzSetting Apache global config
z2/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml�wrm��encodingz0Skipping FPM default pool settings on Dedicated
z/scripts/rebuildhttpdconfz/scripts/php_fpm_configz	--rebuildz"/scripts/restartsrv_apache_php_fpmz&/scripts/restartsrv_apache &>/dev/nullTrw)�int�math�floor�	mem_totalr�rCr0r`�makedirs�OSError�FileExistsError�open�writer<)
r�	min_spare�	max_spare�server_limit�max_workers�	conf_file�
fpm_configr9r��fhs
          r�tune_apache_php�FirstSetup.tune_apache_php=s����	��	��4�:�:�d�n�n�u�&<�q�&@�A�B���#���L�
�B�
��L�#�R�'��/�	��
�
�:��Y�K�v�&���		�	
�	
�
�
�:��Y�K�v�&���		�	
�	
�
�
�6��\�N�&�)���		�	
�	
�
�
�5��[�M��(���		�	
��;�;��H�H�:�;�
Q�J�
#����6�7�
�H�H�5�6�G�D��d�C�'�2�b�����$�3�2�
�H�H�H�I����1�2�3����/��=�>����:�;�<����=�T��J���_�-�
#����A�3�b��"�"��
#��3�2�s$�	E1�=F"�1F�F�F�"
F0c���SnSnSnSnSnSnUHnURXq:�a
XsnXrnM O SUS3nSUS	3nS
nURSXX5 URSUU5 UR/S
Q5 g)zx
sets innodb buffer pool size and instances
maxes out at 4GB of innodb buffer pool
every 1GB gets another pool instance
r��))i@Br��)i��-r�i)i��jr�i)i���r�i)i���r�ir�zinnodb_buffer_pool_size=zM
zinnodb_buffer_pool_instances=r'z/etc/my.cnfz$^\s*innodb_buffer_pool_size\s*=[^$]*z)^\s*innodb_buffer_pool_instances\s*=[^$]*)�service�mysqlr^N)r�r�r<)	r�mem_gate�
pool_count�	pool_size�	mem_tiers�buffer_pool�pool_instances�tierr�s	         r�
tune_mysql�FirstSetup.tune_mysqls������
��	�
�	������D��~�~���.�"�o��!%�!1����1��
�S�A��8��8H��K��!�	��
�
�3�[�	
�	
�
�
�8���	
�
	
���4�5rc��SnURUSS9n[U5nU(d&URSSS9 [R"S5 X lg)zV
Gets total memory
switched to free because /proc/meminfo may not be kb in the future
z)free |sed -e 1d -e 3d | awk '{print $2}' Trwz!Failed to check available memory
r,r�N)r<r�r0rMrNr�)rr6r�s   rr�FirstSetup.get_mem_total�sH��
>���L�L��D�L�1�	��	�N�	���H�H�9�t�H�D��H�H�Q�K�"�rc
��SnSn[RRU5n	SU	S3n
[U
SSS9n[USS9nUR	5nX,;a)URSUSUS	3S
S9 SSS5 SSS5 gUR
S
5nUGH"n
U(a9U(d2[R"XM5(aS
nURSUS	35 U(dUS:wdU(a�U(a�U(dU(d�[R"X5(dUS:Xa�US:Xa6URSUSUS	3S
S9 U
US	3nURU5 US
-
nM�URSUSUS	3S
S9 [R"XU
5nURU5 US
-
nGMURU
5 GM% SSS5 U(d�U(a�U(d9URSRU5S
S9 US
-
nURUS	35 OCURS5 [R"U
5 URSX#USS9 SSS5 gSSS5 U(d7URSRXX45S
S9 [R"U
5 g[R"X�5 g!,(df   N�=f!,(df   Nt=f)z#
configuration management function
rz/tmp/z.tmpr�rmr�zSetting already set in file z:
r'Tr,Nr�zafter line found: �APPENDz
appending z after z"doing traditional search/replace:
z -> z)appending to end of file as fallback:
{}
z,doing recurisve conf_set for after fallback
F)r�r�zSWarning: Failed to replace (fallback False):
search:{}
replace:{}
file:{}
after:{}
)r`r��basenamer��readr0�
splitlines�rer�r��subr~rar��shutil�move)r�_search�_replace�_filer��multipler��after_found�
replace_count�base_fn�tmp_fn�tmp_fh�og_fh�og_line�new_lines               rr��FirstSetup.conf_set�s������
��'�'�"�"�5�)����	��&��
�&�#��
0�F��e�g�.�%��
�
����$��H�H�6�u�g�S��
�"�M� ����/�1�
0��(�(��.��$�G��[�R�Y�Y�u�5N�5N�&'�����#5�e�W�B�!?�@�"'�7�h�+>� %�+�%�]��Y�Y�w�8�8�G�x�<O�"�h�.� �H�H�",�X�J�g�e�W�B� G�$(�%��+2��8�*�B�'?�H�"�L�L��2�)�Q�.�M�$����A�&�i�t�H�:�R�9� $�!��
$&�6�6�'�W�#E�����X�.�%��*�
� ��L�L��)�A %�/�V!�X���H�H�E�L�L�$��!�	��"�Q�&�M��L�L�H�:�R��1��H�H�L�M��I�I�f�%��M�M� �(���"���y1�
0�
0�z��H�H�*�*0�&��5�+��
�	
�
�I�I�f������F�"�S/�.��1�
0�s1�K�.J/�.K�?D:J/�9BK�/
J=	�9K�
Kc�j�[RRS5(aSUlgSUlg)Nz/proc/vz/veinfoTF)r`r�r�rCrs rr�FirstSetup.is_a_vpss$��
�7�7�>�>�+�,�,��D�K��D�Kr)r#rrCr�r	rN)F)rFT)�__name__�
__module__�__qualname__�__firstlineno__rr
r<rIrPr0r5rbrhr�r�r�r�r�r�rr�r�__static_attributes__�rrrrso��.�/(�b�*=�(�
#��A��?K�B#-�J'�
�@@K�D#6�J#�LP�T#�l rrc��[5nURR(aqUR5 UR	5 UR5 UR
5 UR5 UR5 UR5 O�URR(aAUR
5 UR5 UR5 UR5 O\URR(aUR5 O0UR5 UR	5 UR5 UR5 g)z�if -c is used, the first section runs this is intended to be ran after
the customers user is added without -c is meant to be ran before the
customer is provisioned (clonevps /ready dedi)N)rr#�allr�r�r�rbr�r�r�r+rxrhrP)�setups r�mainr�s���
�L�E��z�z�~�~�
����
����
����
��� �
����
����
����	���	�	�
��� �
����
����
����	���	�	�
��� �	����
����
����	���r�__main__)�__doc__r.�
subprocessr1r`rMr�r�r�rr
rDrr�r�r�rr�<module>r�sP���
��	�
�	��
��
��u �u �p�<�z���F�r