From 7c72afa5663aae240c38dab9518a9ad67956a8ee Mon Sep 17 00:00:00 2001 From: liuzc Date: Mon, 20 Apr 2015 10:48:40 +0800 Subject: [PATCH] 1)Adding: add script template for nginx configure to be restored and restarted --- agent/CMakeLists.txt | 2 +- agent/qconf_const.h | 2 +- agent/qconf_script.cc | 3 ++- agent/script/nginx_template.sh | 23 +++++++++++++++++++++++ agent/version | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 agent/script/nginx_template.sh diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index 888c15d..647b418 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -94,11 +94,11 @@ ENDIF(WIN32) install(DIRECTORY bin DESTINATION .) install(DIRECTORY conf DESTINATION .) +install(DIRECTORY script DESTINATION .) install(DIRECTORY DESTINATION cmd) install(DIRECTORY DESTINATION dumps) install(DIRECTORY DESTINATION monitor) install(DIRECTORY DESTINATION result) -install(DIRECTORY DESTINATION script) install(DIRECTORY DESTINATION lock) install(FILES lockfile DESTINATION lock) install(DIRECTORY DESTINATION doc) diff --git a/agent/qconf_const.h b/agent/qconf_const.h index 9a1bc5c..5c72190 100644 --- a/agent/qconf_const.h +++ b/agent/qconf_const.h @@ -4,7 +4,7 @@ #include "qconf_common.h" // agent version -#define QCONF_AGENT_VERSION "1.0.0" +#define QCONF_AGENT_VERSION "1.0.2" #define QCONF_AGENT_NAME "qconf_agent" diff --git a/agent/qconf_script.cc b/agent/qconf_script.cc index f19aada..2c93e1c 100644 --- a/agent/qconf_script.cc +++ b/agent/qconf_script.cc @@ -129,7 +129,8 @@ int find_script(const string &path, string &script) return QCONF_ERR_SCRIPT_DIR_NOT_INIT; } //find exist script file - string script_path(_qconf_script_dir), tmp_path(path), file_path; + string script_path(_qconf_script_dir), tmp_path, file_path; + tmp_path = (path[0] == '/') ? path.substr(1) : path; replace(tmp_path.begin(), tmp_path.end(), '/', QCONF_SCRIPT_SEPARATOR); script_path.append(tmp_path); size_t index = script_path.size(); diff --git a/agent/script/nginx_template.sh b/agent/script/nginx_template.sh new file mode 100644 index 0000000..2d477fc --- /dev/null +++ b/agent/script/nginx_template.sh @@ -0,0 +1,23 @@ +NODE_ADD=0 +NODE_CHANGE=1 +NODE_DEL=2 + +if [ "$qconf_event" != "$NODE_DEL" ]; then + value=`./qconf get_conf $qconf_path` + +# TODO: Nginx directory, You may change this to your own directory + nginx=/usr/local/nginx + nginx_conf_path=$nginx/conf/nginx.conf + + old_conf_value=`cat $nginx_conf_path` + + #if value is modified, then change the file + if [ "$value" != "$old_conf_value" ]; then + cp $nginx_conf_path ${nginx_conf_path}.bak + echo $value > ${nginx_conf_path}.tmp + mv ${nginx_conf_path}.tmp $nginx_conf_path + +# TODO: Restart nginx, You may change this to your own command of nginx starting + service nginx restart + fi +fi diff --git a/agent/version b/agent/version index 16098e3..6dbeee9 100644 --- a/agent/version +++ b/agent/version @@ -1 +1 @@ -qconf-agent: 1.0.0 +qconf-agent: 1.0.2