#! /bin/sh # Author: Mindaugas Mardosas, Nerijus Sapola # Company: Kolmisoft # Year: 2012 # About: MOR Billing platform settings reading/writing framework . /usr/src/m2/framework/bash_functions.sh settings_config_file="/etc/m2/system.conf" M2_CRONS_FOR_ALL_SERVERS="m2_date_limit_report m2_system_stats_report m2_keep_server_loadstats_alive" M2_CRONS_FOR_MAIN_DB="m2_fraud_protection m2_active_calls_data m2_background_tasks m2_delete_old_calls m2_delete_old_rates m2_invoices m2_remove_temporary_tables m2_rates_effective_from_cache_control" M2_CRONS_FOR_GUI="m2_daily_actions m2_hourly_actions m2_monthly_actions m2_minute_actions m2_invoices_report" M2_CRONS_FOR_ES="keep_elasticsearch_alive m2_check_elasticsearch_status m2_elasticsearch_restart m2_es_sync_control" M2_CRONS_FOR_FS="m2_terminator_check" M2_CRONS_FOR_RADIUS="core_failed_queries_import" read_mor_binlog_setting() { # Author: Mindaugas Mardosas, Nerijus Sapola # Year: 2012 # About: This function checks if binlog is configured by administrator to be enabled on this system # # Returns: # 0 - NO, MySQL binlog should not be enabled on this server # 1 - YES, MySQL binlog has to be enabled on this server # # Also returns a global variable BINLOG_SETTING which can be used later in scripts to check if MySQL binlog has to enabled if [ -f $settings_config_file ] && [ `awk -F"#" '{print \$1}' $settings_config_file | grep BINLOG | wc -l` == 1 ]; then BINLOG_SETTING=`awk -F"#" '{print \$1}' $settings_config_file | grep "BINLOG=1" | wc -l` else mkdir -p /etc/m2 get_answer "MySQL binlog setting is not present on this server. Should MySQL binlog be enabled on this server (Should be enabled if you are going to build MySQL replication or client modifies his DB himself)?" "y" if [ "$answer" == "y" ]; then echo "BINLOG=1" >> $settings_config_file BINLOG_SETTING=1 else echo "BINLOG=0" >> $settings_config_file BINLOG_SETTING=0 fi fi return $BINLOG_SETTING } read_mor_replication_settings() { # Author: Mindaugas Mardosas, Nerijus Sapola # Year: 2012 # About: This function reads replication settings # # Reads: # REPLICATION_M - {0 - disabled; 1 - enabled} # REPLICATION_S - {0 - disabled; 1 - enabled} # Returns: # DB_MASTER_MASTER - {"yes", "no" } # DB_SLAVE - {"yes", "no" } # REPLICATION_PRESENT - { "yes", "no" } if [ -f $settings_config_file ] && [ `awk -F"#" '{print \$1}' $settings_config_file | grep "REPLICATION_M\|REPLICATION_S" | wc -l` == "2" ]; then REPLICATION_M=`awk -F"#" '{print $1}' $settings_config_file | grep REPLICATION_M | awk -F"=" '{print $2}'` REPLICATION_S=`awk -F"#" '{print $1}' $settings_config_file | grep REPLICATION_S | awk -F"=" '{print $2}'` elif [ -f $settings_config_file ] && [ `awk -F"#" '{print \$1}' $settings_config_file | grep "REPLICATION_M\|REPLICATION_S" | wc -l` == "0" ]; then # asking user for correct configuration mkdir -p /etc/m2 get_answer "Is this server participating in DB replication?" "n" if [ "$answer" == "y" ]; then get_answer "Is it Master<>Master replication" "y" if [ "$answer" == "y" ]; then REPLICATION_M=1 REPLICATION_S=1 echo -e "REPLICATION_M=1\nREPLICATION_S=1" >> $settings_config_file else get_answer "Is it Master server" "y" if [ "$answer" == "y" ]; then REPLICATION_M=1 REPLICATION_S=0 echo -e "REPLICATION_M=1\nREPLICATION_S=0" >> $settings_config_file else echo "According previous answers this server is Slave" REPLICATION_M=0 REPLICATION_S=1 echo -e "REPLICATION_M=0\nREPLICATION_S=1" >> $settings_config_file fi fi else REPLICATION_M=0 REPLICATION_S=0 echo -e "REPLICATION_M=0\nREPLICATION_S=0" >> $settings_config_file fi fi #===================DB_MASTER_MASTER if [ "$REPLICATION_M" == "1" ] && [ "$REPLICATION_S" == "1" ]; then DB_MASTER_MASTER="yes" else DB_MASTER_MASTER="no" fi #===================REPLICATION_PRESENT if [ "$REPLICATION_M" == "1" ] || [ "$REPLICATION_S" == "1" ]; then REPLICATION_PRESENT="yes" else REPLICATION_PRESENT="no" fi #===================DB_SLAVE if [ "$REPLICATION_S" == "1" ]; then DB_SLAVE="yes" else DB_SLAVE="no" fi } read_mor_gui_settings() { # Author: Nerijus Sapola # Year: 2012 # About: This function reads GUI settings # # Returns: # GUI_PRESENT - {0 - GUI should not be running on server; 1 - GUI should be running on server} if [ -f $settings_config_file ] && [ `awk -F"#" '{print $1}' $settings_config_file | grep "GUI_PRESENT" | wc -l` == "1" ]; then GUI_PRESENT=`awk -F"#" '{print $1}' $settings_config_file | grep GUI_PRESENT | awk -F"=" '{print $2}'` fi return $GUI_PRESENT } read_mor_asterisk_settings() { # Author: Nerijus Sapola # Year: 2012 # About: This function reads Asterisk settings # # Returns: # ASTERISK_PRESENT - {0 - Asterisk should not be running on server; 1 - Asterisk should be running on server} if [ -f $settings_config_file ] && [ `awk -F"#" '{print $1}' $settings_config_file | grep "ASTERISK_PRESENT" | wc -l` == "1" ]; then ASTERISK_PRESENT=`awk -F"#" '{print $1}' $settings_config_file | grep ASTERISK_PRESENT | awk -F"=" '{print $2}'` fi return $ASTERISK_PRESENT } read_mor_db_settings() { # Author: Nerijus Sapola # Year: 2012 # About: This function reads Asterisk settings # # Returns: # DB_PRESENT - {0 - MOR Database should not be running on server; 1 - MOR Database should be running on server} if [ -f $settings_config_file ] && [ `awk -F"#" '{print $1}' $settings_config_file | grep "DB_PRESENT" | wc -l` == "1" ]; then DB_PRESENT=`awk -F"#" '{print $1}' $settings_config_file | grep DB_PRESENT | awk -F"=" '{print $2}'` else # checking if values are not duplicated if [ -f $settings_config_file ] && [ `awk -F"#" '{print $1}' $settings_config_file | grep "DB_PRESENT" | wc -l` -gt "1" ]; then report "Duplicated values on $settings_config_file, please fix manually" 1 exit 1 fi fi return $DB_PRESENT } read_m2_pcap_settings() { # This fucntion read pcap settings # Returns: # PCAP_HDD_RESERVED_SPACE - # -1 - setting is not present in system.conf # -2 - inavlid value (contains non number characters) # > 0 - how much space reserve for pcapsipdump # PCAP_LISTENING_NET_INTERFACE - # -1 - setting is not present in system.conf # default - default interface # name of interface # PCAP_ENABLED- # -1 - setting is not present in system.conf # 0 - setting is disabled # 1 - setting is enabled # # # PCAP_BUFFER_SIZE - # -1 - setting is not present in system.conf # pcap buffer size to set (eg 64MiB) PCAP_HDD_RESERVED_SPACE="" PCAP_LISTENING_NET_INTERFACE="" PCAP_ENABLED="" PCAP_BUFFER_SIZE="" local temp_value="" if [ -f $settings_config_file ] && [ $(awk -F"#" '{print $1}' $settings_config_file | grep -i "PCAP_HDD_RESERVED_SPACE" | wc -l) == "1" ] then temp_value=$(awk -F"#" '{print $1}' $settings_config_file | sed 's/[[:space:]]//g' | grep -i "PCAP_HDD_RESERVED_SPACE" | awk -F"=" '{print $2}') if echo $temp_value | grep -qE "^[0-9]+$" then PCAP_HDD_RESERVED_SPACE="$temp_value" else PCAP_HDD_RESERVED_SPACE="-2" fi else PCAP_HDD_RESERVED_SPACE="-1" fi temp_value="" if [ -f $settings_config_file ] && [ $(awk -F"#" '{print $1}' $settings_config_file | grep -i "PCAP_LISTENING_NET_INTERFACE" | wc -l) == "1" ] then temp_value=$(awk -F"#" '{print $1}' $settings_config_file | sed 's/[[:space:]]//g' | grep -i "PCAP_LISTENING_NET_INTERFACE" | awk -F"=" '{print $2}') if echo $temp_value | grep -qiF "default" then PCAP_LISTENING_NET_INTERFACE="default" else PCAP_LISTENING_NET_INTERFACE="$temp_value" fi else PCAP_LISTENING_NET_INTERFACE="-1" fi if [ -f $settings_config_file ] && [ $(awk -F"#" '{print $1}' $settings_config_file | grep -i "PCAP_ENABLED" | wc -l) == "1" ] then temp_value=$(awk -F"#" '{print $1}' $settings_config_file | sed 's/[[:space:]]//g' | grep -i "PCAP_ENABLED" | awk -F"=" '{print $2}') if [ $temp_value == "1" ]; then PCAP_ENABLED="1" else PCAP_ENABLED="0" fi else PCAP_ENABLED="-1" fi if [ -f $settings_config_file ] && [ $(awk -F"#" '{print $1}' $settings_config_file | grep -i "PCAP_BUFFER_SIZE" | wc -l) == "1" ] then temp_value=$(awk -F"#" '{print $1}' $settings_config_file | sed 's/[[:space:]]//g' | grep -i "PCAP_BUFFER_SIZE" | awk -F"=" '{print $2}') if echo $temp_value | grep -qE '^[[:digit:]]+MiB$'; then PCAP_BUFFER_SIZE="$temp_value" else PCAP_BUFFER_SIZE="-1" fi else PCAP_BUFFER_SIZE="-1" fi } # wrapper to kf read_m2_settings() { k_config_details }