Skip to content

Commit

Permalink
INDY-1467: add migration to update clients connections limit in indy.…
Browse files Browse the repository at this point in the history
…env.

Signed-off-by: Sergey Shilov <sergey.shilov@dsr-company.com>
  • Loading branch information
Sergey Shilov committed Jul 13, 2018
1 parent 4d0614e commit d5ac846
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions data/migrations/deb/1_4_500_to_1_4_501.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python3.5

from indy_common.migration.helper import update_indy_env

from stp_core.common.log import getlogger

logger = getlogger()

CLIENT_CONNECTIONS_LIMIT_KEY = "CLIENT_CONNECTIONS_LIMIT"
CLIENT_CONNECTIONS_LIMIT_VAL = 10000


logger.info("Going to update clients connections limit.")
update_indy_env(CLIENT_CONNECTIONS_LIMIT_KEY, CLIENT_CONNECTIONS_LIMIT_VAL)
logger.info("Done.")
Empty file.
41 changes: 41 additions & 0 deletions indy_common/migration/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import shutil

from stp_core.common.log import getlogger

logger = getlogger()

ENV_FILE_PATH = "/etc/indy/indy.env"


def update_indy_env(key, val):
key_found = False

ENV_FILE_PATH_TMP = ENV_FILE_PATH + "_tmp"
logger.info("Make a copy '{}' of an original env file '{}'."
.format(ENV_FILE_PATH_TMP, ENV_FILE_PATH))
# Make a copy to inherit r/w/own flags.
shutil.copy(ENV_FILE_PATH, ENV_FILE_PATH_TMP)

new_line = "{}={}\n".format(key, val)

with open(ENV_FILE_PATH, "r") as old_env_file:
with open(ENV_FILE_PATH_TMP, "w") as new_env_file:
for line in old_env_file.readlines():
_key = line.split('=')[0].strip()
if key == _key:
key_found = True
line = new_line
logger.info("Write '{}' line to '{}'.".format(line.strip(), ENV_FILE_PATH_TMP))
new_env_file.write(line)

if not key_found:
logger.info("Key '{}' is not found in '{}', append line."
.format(key, ENV_FILE_PATH))
with open(ENV_FILE_PATH, "a") as env_file:
env_file.write("\n" + new_line)
logger.info("Remove unnecessary '{}'.".format(ENV_FILE_PATH_TMP))
os.remove(ENV_FILE_PATH_TMP)
else:
logger.info("Rename '{}' to '{}'.".format(ENV_FILE_PATH_TMP, ENV_FILE_PATH))
shutil.move(ENV_FILE_PATH_TMP, ENV_FILE_PATH)

0 comments on commit d5ac846

Please sign in to comment.