T
T
Twelfth Doctor2017-09-27 19:30:14
Python
Twelfth Doctor, 2017-09-27 19:30:14

What is the correct approach to edit configs?

Hello. I am writing a small program that would allow me to manage websites (editing, deleting, linking and unlinking aliases). The question arose about how best to edit configuration files. Now everything is done like this: the database stores information about each site (error pages linked to the site, aliases and the main domain, encoding, index files, etc.). When the data changes, I retrieve the data from the database and form the old string, then I read the config into a string and replace it, clear the file and write it back.
I was told that this is a bad approach. I also had an idea: when editing, generate a new config each time, but then you have to pull a lot of information from the database (information about all host aliases, error pages, etc.) and write it all into the config.
Which option seems to you the most correct?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pfg21, 2017-09-27
@verdex

there is a database with sites, from the database your program generates a set of configs of the format % program_name% -% site_name% to the /etc/nginx/sites-enabled folder
after changing the site to the database, the corresponding config is regenerated and nginx -s reload is launched
plus the reload_all command when all configs of the %prog_name% -* format are deleted and all configs from the database are regenerated.
the algorithm of the program with the structure of the base will become more complicated, but a bunch of probable errors will disappear.

S
sim3x, 2017-09-27
@sim3x

Go in with your hands and edit in vim
If there are a lot of servers, use ansible
Never make critical systems more complicated

C
chupasaurus, 2017-09-27
@chupasaurus

I will reveal about the IaaS Ansible way.
A repository with config templates and a playbook for deployment Let the
data to be inserted into the templates be updated by the same application that wrote to the database, into separate files by vhosts (ideally, it also pushes updates to another repository), which the playbook will receive at the beginning synchronize module (ideally, update the local data repository).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question