[root@eGW SPECS]# cat egw-new.spec
Name: WCG
Version : 1.4.4
Release: 6%{?dist}
Summary: WCG rpm package
License: GPL
Packager: dongfeng
#URL:
Source0: WCG-1.4.4.tar.gz
#BuildRequires:
Requires: nginx,redis,hiredis,hiredis-devel,fcgi,fcgi-devel,spawn-fcgi,gsoap,curl,lksctp-tools,vconfig,wireshark-gnome,xinetd,tftp,tftp-server,keepalived
%description
The rpm package for WCG install!
%prep
%setup -q
%build
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/root/eGW
cp -rf * $RPM_BUILD_ROOT/root/eGW
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc
/root/eGW
%changelog
##########################################################################################
%pre
#Description: This script is used to check system before install WCG
#检查内核版本号
function check_kernel() {
kernel_ver=$(uname -r)
#echo $kernel_ver
if [[ $kernel_ver != "3.10.0-514.el7.centos.x86_64" ]];then
echo "system kernel must be 3.10.0-514.el7.centos.x86_64, please check!"
exit 1
fi
}
#升级前,检查备份原版本
function bak_wcg() {
DIR=/root/eGW
DIR_WCG=${DIR}.wcg
ltegwd_file=${DIR}/ltegwd
if [ -f "$ltegwd_file" ];then
#date=`date +%Y%m%d%H%M`
if [ -d "$DIR_WCG" ];then #如果备份文件存在,则删除
rm -rf $DIR_WCG
fi
echo "eGW folder is exist,automove it to eGW.wcg"
mv $DIR $DIR_WCG #如果目录存在,备份目录
else
rm -rf $DIR
fi
}
#关闭NetworkManager服务
function stop_networkmanager() {
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
}
function pre_install_wcg() {
check_kernel
bak_wcg
stop_networkmanager
}
pre_install_wcg
###########################################################################################
%post
DIR=/root/eGW
DIR_WCG=${DIR}.wcg
function del_py() {
rm -rf /root/eGW/dailystatic.pyc
rm -rf /root/eGW/dailystatic.pyo
}
#recover网关licence文件
function recover_wcg_licence() {
if [ -d "${DIR_WCG}" ];then
if [ -f "${DIR_WCG}/Licence/licence.bin" ];then
echo "cp ${DIR_WCG}/Licence/licence.bin $DIR/Licence/licence.bin"
cp -rf ${DIR_WCG}/Licence/licence.bin $DIR/Licence/licence.bin
else
echo "licence.bin is not exist"
fi
if [ -f "${DIR_WCG}/Licence/licence.auth" ];then
echo "cp ${DIR_WCG}/Licence/licence.auth $DIR/Licence/licence.auth"
cp -rf ${DIR_WCG}/Licence/licence.auth $DIR/Licence/licence.auth
else
echo "licence.auth is not exist"
fi
fi
}
#recover网关config文件
function recover_wcg_config() {
if [ -d "${DIR_WCG}" ];then
if [ -f "${DIR_WCG}/config.txt" ];then
echo "cp ${DIR_WCG}/config.txt $DIR"
cp -rf ${DIR_WCG}/config.txt $DIR
else
echo "config.txt is not exist"
fi
fi
}
#recover网关networkcfg文件
function recover_wcg_networkcfg() {
if [ -d "${DIR_WCG}" ];then
if [ -f "${DIR_WCG}/networkcfg.conf" ];then
echo "cp ${DIR_WCG}/networkcfg.conf $DIR"
cp -rf ${DIR_WCG}/networkcfg.conf $DIR
else
echo "networkcfg.conf is not exist"
fi
fi
}
#recover网关eGW_Cfg_Info文件
function recover_wcg_omc() {
if [ -d "${DIR_WCG}" ];then
if [ -f "${DIR_WCG}/OMC/eGW_Cfg_Info.xml" ];then
echo "cp ${DIR_WCG}/OMC/eGW_Cfg_Info.xml ${DIR}/OMC"
cp -rf ${DIR_WCG}/OMC/eGW_Cfg_Info.xml ${DIR}/OMC
else
echo "eGW_Cfg_Info.xml is not exist"
fi
fi
}
#recover网关cdr文件
function recover_wcg_cdr() {
if [ -d "${DIR_WCG}" ];then
if [ -d "${DIR_WCG}/CDR" ];then
echo "cp -rf ${DIR_WCG}/CDR $DIR"
cp -rf ${DIR_WCG}/CDR $DIR
fi
fi
}
#recover网关static文件
function recover_wcg_static() {
if [ -d "${DIR_WCG}" ];then
if [ -d "${DIR_WCG}/static" ];then
echo "cp -rf ${DIR_WCG}/static $DIR"
cp -rf ${DIR_WCG}/static $DIR
fi
fi
}
#recover网关log文件
function recover_wcg_log() {
if [ -d "${DIR_WCG}" ];then
if [ -d "${DIR_WCG}/Logs" ];then
echo "cp -rf ${DIR_WCG}/Logs $DIR"
cp -rf ${DIR_WCG}/Logs $DIR
fi
fi
}
function recover_wcg_configure() {
recover_wcg_licence
recover_wcg_config
recover_wcg_networkcfg
recover_wcg_omc
recover_wcg_cdr
recover_wcg_static
recover_wcg_log
}
#增加执行权限
function addx() {
cd $DIR
chmod +x startAll.sh
chmod +x ltegwd
chmod +x lccmd
chmod +x vtysh
chmod +x dailystatic.py
chmod +x vman
chmod +x Static
cd ${DIR}/config.sh
chmod +x *
cd ${DIR}/OMC
chmod +x egw_manage
chmod +x egw_report
cd $DIR/Licence
chmod +x register
}
#注册wcg
function register_wcg() {
/root/eGW/Licence/register
}
#配置other
function other() {
cd $DIR
mv -f monitor.service /usr/lib/systemd/system/
mv -f libzebra.so.0 /usr/local/lib
mv -f lccmd /usr/sbin/
systemctl daemon-reload
systemctl enable monitor.service
}
#配置nginx
function config_nginx() {
if [ ! -d "/usr/share/nginx/logs" ];then
mkdir -p /usr/share/nginx/logs
fi
grep 'server_name eGW_omc' /etc/nginx/nginx.conf 2>&1>/dev/null
if [ $? -eq 1 ];then
sed -i '/include \/etc\/nginx\/conf.d\/\*.conf;/r nginx_add.txt' /etc/nginx/nginx.conf
fi
rm -rf nginx_add.txt
systemctl enable nginx.service
systemctl restart nginx.service
}
#配置redis
function config_redis() {
systemctl enable redis.service
systemctl restart redis.service
}
#设置系统环境
function set_system_env() {
systemctl stop firewalld.service #为了防止系统防火墙屏蔽接口,先关闭防火墙
systemctl disable firewalld.service #关闭开机启动
#ulimit -c unlimited #不限制用户资源
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config #关闭selinux
if [ ! -d "/var/opc/lc" ];then
mkdir -p /var/opt/lc
fi
if [ ! -d "/var/opc/mo" ];then
mkdir -p /var/opt/mo
fi
}
function ip_forward() {
ip_forward=`grep "net.ipv4.ip_forward" /etc/sysctl.conf`
if [ ! -n "$ip_forward" ];then
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
else
sed -i "s/\(net.ipv4.ip_forward.*\)/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf
fi
}
function neigh_default_gc_thresh() {
neigh_default_gc_thresh1=`grep "net.ipv4.neigh.default.gc_thresh1" /etc/sysctl.conf`
neigh_default_gc_thresh2=`grep "net.ipv4.neigh.default.gc_thresh2" /etc/sysctl.conf`
neigh_default_gc_thresh3=`grep "net.ipv4.neigh.default.gc_thresh3" /etc/sysctl.conf`
if [ ! -n "$neigh_default_gc_thresh1" ];then
echo "net.ipv4.neigh.default.gc_thresh1 = 25000" >> /etc/sysctl.conf
else
sed -i "s/\(net.ipv4.neigh.default.gc_thresh1.*\)/net.ipv4.neigh.default.gc_thresh1 = 25000/g" /etc/sysctl.conf
fi
if [ ! -n "$neigh_default_gc_thresh2" ];then
echo "net.ipv4.neigh.default.gc_thresh2 = 30000" >> /etc/sysctl.conf
else
sed -i "s/\(net.ipv4.neigh.default.gc_thresh2.*\)/net.ipv4.neigh.default.gc_thresh2 = 30000/g" /etc/sysctl.conf
fi
if [ ! -n "$neigh_default_gc_thresh3" ];then
echo "net.ipv4.neigh.default.gc_thresh3 = 40000" >> /etc/sysctl.conf
else
sed -i "s/\(net.ipv4.neigh.default.gc_thresh3.*\)/net.ipv4.neigh.default.gc_thresh3 = 40000/g" /etc/sysctl.conf
fi
}
function kernel_msg() {
kernel_msgmni=`grep "kernel.msgmni" /etc/sysctl.conf`
kernel_msgmax=`grep "kernel.msgmax" /etc/sysctl.conf`
kernel_msgmnb=`grep "kernel.msgmnb" /etc/sysctl.conf`
if [ ! -n "$kernel_msgmax" ];then
echo "kernel.msgmax = 8192" >> /etc/sysctl.conf
else
sed -i "s/\(kernel.msgmax.*\)/kernel.msgmax = 8192/g" /etc/sysctl.conf
fi
if [ ! -n "$kernel_msgmni" ];then
echo "kernel.msgmni = 32768" >> /etc/sysctl.conf
else
sed -i "s/\(kernel.msgmni.*\)/kernel.msgmni = 32768/g" /etc/sysctl.conf
fi
if [ ! -n "$kernel_msgmnb" ];then
echo "kernel.msgmnb = 4203520" >> /etc/sysctl.conf
else
sed -i "s/\(kernel.msgmnb.*\)/kernel.msgmnb = 4203520/g" /etc/sysctl.conf
fi
}
function config_sysctl() {
ip_forward
neigh_default_gc_thresh
kernel_msg
}
function set_coredump() {
folder_coredump=coredump
default_limit_core=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitCORE"`
default_limit_nofile=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitNOFILE"`
cd /root
if [ ! -d "$folder_coredump" ];then
mkdir $folder_coredump
chmod 0773 $folder_coredump
fi
echo "kernel.core_pattern = /root/coredump/core-%e-sig%s-user%u-group%g-pid%p-time%t" > /etc/sysctl.d/core.conf
echo "kernel.core_uses_pid = 1" >> /etc/sysctl.d/core.conf
echo "fs.suid_dumpable = 2" >> /etc/sysctl.d/core.conf
echo "* hard core unlimited" > /etc/security/limits.d/core.conf
echo "* soft core unlimited" >> /etc/security/limits.d/core.conf
if [ ! -n "$default_limit_core" ];then
echo "DefaultLimitCORE=infinity" >> /etc/systemd/system.conf
else
sed -i "s/\(DefaultLimitCORE.*\)/DefaultLimitCORE=infinity/g" /etc/systemd/system.conf
fi
if [ ! -n "$default_limit_nofile" ];then
echo "DefaultLimitNOFILE=102400" >> /etc/systemd/system.conf
else
sed -i "s/\(DefaultLimitNOFILE.*\)/DefaultLimitNOFILE=102400/g" /etc/systemd/system.conf
fi
systemctl daemon-reload
systemctl daemon-reexec
sysctl -p /etc/sysctl.d/core.conf
sysctl -p
}
function set_history() {
grep '^HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
grep '^#HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
echo "HISTORY_IPADDR_tmp=\`who am i |awk '{ print \$5 }'\`" >> /etc/profile
else
sed -i "s/#HISTORY_IPADDR_tmp=/HISTORY_IPADDR_tmp=/" /etc/profile > /dev/null
fi
fi
grep '^HISTORY_IPADDR=' /etc/profile >/dev/null
if [[ $? -eq 1 ]];then
grep '^#HISTORY_IPADDR=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
echo "HISTORY_IPADDR=\${HISTORY_IPADDR_tmp:1:-1}" >> /etc/profile
else
sed -i "s/#HISTORY_IPADDR=/HISTORY_IPADDR=/" /etc/profile > /dev/null
fi
fi
grep '^HISTORY_FILE=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
grep '^#HISTORY_FILE=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
echo "HISTORY_FILE=/root/eGW/Logs/history/\${HISTORY_IPADDR}.log &> /dev/null" >> /etc/profile
else
sed -i "s/#HISTORY_FILE=/HISTORY_FILE=/" /etc/profile > /dev/null
fi
fi
grep '^export PROMPT_COMMAND=' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
prompt_command_format='{ date "+%Y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(pwd) #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTORY_FILE'
grep '^#export PROMPT_COMMAND' /etc/profile > /dev/null
if [[ $? -eq 1 ]];then
echo "export PROMPT_COMMAND='$prompt_command_format'" >> /etc/profile
else
sed -i "s/#export PROMPT_COMMAND=/export PROMPT_COMMAND=/" /etc/profile > /dev/null
fi
fi
source /etc/profile
}
function update_ssh() {
yum update -y openssh
}
function set_version() {
version="WCG-1.4.4"
mkdir -p /root/eGW/.version/versions
lccmd_md5=`md5sum /usr/sbin/lccmd |awk '{print $1}'`
ltegwd_md5=`md5sum /root/eGW/ltegwd |awk '{print $1}'`
gtp_relay_md5=`md5sum /root/eGW/gtp-relay.ko |awk '{print $1}'`
echo lccmd:$lccmd_md5 > /root/eGW/.version/versions/${version}.ver
echo ltegwd:$ltegwd_md5 >> /root/eGW/.version/versions/${version}.ver
echo gtp-relay.ko:$gtp_relay_md5 >> /root/eGW/.version/versions/${version}.ver
}
function recover_keepalived() {
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
mv /root/eGW/keepalived.conf /etc/keepalived/keepalived.conf
}
function post_install_wcg() {
systemctl stop monitor.service
del_py
recover_wcg_configure
addx
register_wcg
other
config_nginx
config_redis
set_system_env
config_sysctl
set_coredump
set_history
#update_ssh
set_version
recover_keepalived
systemctl start monitor.service
}
post_install_wcg
##########################################################################################
%preun
DIR=/root/eGW
DIR_WCG=${DIR}.wcg
function unset_history() {
grep '^HISTORY_IPADDR_tmp=' /etc/profile > /dev/null
if [[ $? -eq 0 ]];then
sed -i "s/HISTORY_IPADDR_tmp=/#HISTORY_IPADDR_tmp=/" /etc/profile > /dev/null
fi
grep '^HISTORY_IPADDR=' /etc/profile >/dev/null
if [[ $? -eq 0 ]];then
sed -i "s/HISTORY_IPADDR=/#HISTORY_IPADDR=/" /etc/profile > /dev/null
fi
grep '^HISTORY_FILE=' /etc/profile > /dev/null
if [[ $? -eq 0 ]];then
sed -i "s/HISTORY_FILE=/#HISTORY_FILE=/" /etc/profile > /dev/null
fi
grep '^export PROMPT_COMMAND=' /etc/profile > /dev/null
if [[ $? -eq 0 ]];then
sed -i "s/export PROMPT_COMMAND=/#export PROMPT_COMMAND=/" /etc/profile > /dev/null
fi
source /etc/profile
}
function stop_wcg() {
systemctl stop monitor.service
pkill ltegwd
pkill startAll.sh
pkill egw_manage
pkill egw_report
}
function bak_wcg() {
if [ -d "$DIR" ];then
if [ -d "$DIR_WCG" ];then #如果备份文件存在,则删除
rm -rf $DIR_WCG
fi
echo "cp $DIR to $DIR_WCG"
cp -rf $DIR $DIR_WCG #如果目录存在,备份目录
fi
}
function recover_file() {
if [ -d "$DIR" ];then
touch /root/eGW/dailystatic.pyc
touch /root/eGW/dailystatic.pyo
touch /root/eGW/nginx_add.txt
rm -rf ${DIR}/Licence/licence.auth
rm -rf ${DIR}/Licence/licence.bin
rm -rf ${DIR}/CDR/*
mkdir ${DIR}/CDR/cdrDat
rm -rf ${DIR}/Logs/ltegwd/*
rm -rf ${DIR}/Logs/manage/*
rm -rf ${DIR}/Logs/report/*
rm -rf ${DIR}/Logs/watchdog/*
rm -rf ${DIR}/Logs/history/*
rm -rf ${DIR}/Logs/keepalived/*
rm -rf ${DIR}/static/dailystatic/*
rm -rf ${DIR}/static/userstatic/*
rm -rf ${DIR}/.version
#rm -rf ${DIR}/update/*
cp /usr/local/lib/libzebra.so.0 /root/eGW
mv /usr/lib/systemd/system/monitor.service /root/eGW
mv /usr/sbin/lccmd /root/eGW
mv /etc/keepalived/keepalived.conf /root/eGW
mv /etc/keepalived/keepalived.conf.bak /etc/keepalived/keepalived.conf
#rm -rf /usr/lib/systemd/system/monitor.service
#rm -rf /usr/sbin/lccmd
systemctl daemon-reload
fi
}
function preun_uninstall_wcg() {
unset_history
stop_wcg
bak_wcg
recover_file
}
preun_uninstall_wcg
############################################################################################
%postun
#rm -rf /root/eGW
#rm -rf /usr/sbin/lccmd
############################################################################################