-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INDY-1467: add migration to update clients connections limit in indy.…
…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
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |