File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change 9
9
config = yaml .safe_load (source )
10
10
11
11
# read to existing config file
12
- with open ("/etc/squid/squid.conf" , "r" ) as dest :
13
- file_content = dest .read ()
14
-
15
- # adapt the config file
12
+ with open ("/etc/squid/squid.conf" , "r+" ) as config_file :
13
+ file_content = config_file .read ()
16
14
file_content = re .sub (r"cache_dir ufs .*" , f"cache_dir ufs /var/cache/squid { str (config ['max_cache_size_mb' ])} 16 256" , file_content )
17
15
file_content = re .sub (r"access_log .*" , "access_log stdio:/proc/self/fd/1 squid" , file_content )
18
-
19
- # write to file
20
- with open ( "/etc/squid/squid.conf" , "w" ) as dest :
21
- dest . write ( file_content )
16
+ # writing back the content
17
+ config_file . seek ( 0 , 0 )
18
+ config_file . write ( file_content )
19
+ config_file . truncate ( )
22
20
23
21
# make sure "squid" is the user and group owner of the cache squid path
24
22
os .system ('chown -R squid:squid /var/cache/squid' )
You can’t perform that action at this time.
0 commit comments