[root@eGW SPECS]# cat egw.spec
Name: WCG
Version : 1.4.0
Release: 1%{?dist}
Summary: WCG rpm package
License: GPL
Packager: dongfeng
#URL:
Source0: WCG-1.4.0.tar.gz
#BuildRequires:
Requires: nginx,redis,hiredis,hiredis-devel,fcgi,fcgi-devel,spawn-fcgi,gsoap,curl,lksctp-tools,vconfig
%description
The rpm package for WCG install!
%prep
%setup -q
%build
#rm -rf $RPM_BUILD_ROOT
#mkdir -p $RPM_BUILD_ROOT/root/eGW
#cp -rf $RPM_BUILD_DIR/%{name}-%{version}/* $RPM_BUILD_ROOT/root/eGW
#cp -rf * $RPM_BUILD_ROOT/root/eGW
%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
##########################################################################################
DIR=/root/eGW
DIR_bak=${DIR}_bak
ltegwd_file=${DIR}/ltegwd
if [ -f "$ltegwd_file" ];then
date=`date +%Y%m%d%H%M`
if [ -d "$DIR_bak" ];then #如果备份文件存在,则删除
rm -rf $DIR_bak
fi
echo "eGW folder is already exist"
echo "mv $DIR to $DIR_bak"
mv $DIR $DIR_bak #如果目录存在,备份目录
else
rm -rf $DIR
fi
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
%post
###########################################################################################
rm -rf /root/eGW/dailystatic.pyc
rm -rf /root/eGW/dailystatic.pyo
systemctl stop monitor.service
DIR=/root/eGW
DIR_bak=${DIR}_bak
if [ -d "${DIR}_bak" ];then
if [ -f "${DIR_bak}/Licence/licence.bin" ];then
echo "cp ${DIR_bak}/Licence/licence.bin $DIR/Licence/licence.bin"
cp -rf ${DIR_bak}/Licence/licence.bin $DIR/Licence/licence.bin #替换网关配置文件
else
echo "licence.bin is not exist"
fi
if [ -f "${DIR_bak}/Licence/licence.auth" ];then
echo "cp ${DIR_bak}/Licence/licence.auth $DIR/Licence/licence.auth"
cp -rf ${DIR_bak}/Licence/licence.auth $DIR/Licence/licence.auth #替换网关配置文件
else
echo "licence.bin is not exist"
fi
if [ -f "${DIR_bak}/config.txt" ];then
echo "cp ${DIR_bak}/config.txt $DIR"
cp -rf ${DIR_bak}/config.txt $DIR #替换网关配置文件
else
echo "config.txt is not exist"
fi
if [ -f "${DIR_bak}/networkcfg.conf" ];then
echo "cp ${DIR_bak}/networkcfg.conf $DIR"
cp -rf ${DIR_bak}/networkcfg.conf $DIR #替换网络配置文件
else
echo "networkcfg.conf is not exist"
fi
cd $DIR_bak
if [ -d "CDR" ];then
echo "cp -rf ${DIR_bak}/CDR $DIR"
cp -rf ${DIR_bak}/CDR $DIR #保留话单到新版本
fi
if [ -d "static" ];then
echo "cp -rf ${DIR_bak}/static $DIR"
cp -rf ${DIR_bak}/static $DIR #保留统计到新版本
fi
#date=`date +%Y%m%d%H%M`
#DIR_date=${DIR}_$date
#mkdir $DIR_date #创建日期备份文件夹
#cp -rf $DIR_bak/* $DIR_date #拷贝备份文件夹到日期备份文件夹
fi
cd $DIR
chmod +x startAll.sh
#chmod +x monitor
chmod +x ltegwd
#chmod +x ltegw.sh
chmod +x lccmd
#chmod +x watchdog.sh
chmod +x vtysh
chmod +x dailystatic.py
cd ${DIR}/config.sh
chmod +x *
cd ${DIR}/OMC
chmod +x egw_manage
chmod +x egw_report
cd $DIR/Licence
chmod +x register
cd $DIR
mv -f monitor.service /usr/lib/systemd/system/
mv -f libzebra.so.0 /usr/local/lib
cp -f lccmd /usr/sbin/
systemctl daemon-reload
systemctl enable monitor.service
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 start nginx.service
systemctl enable redis.service
systemctl start redis.service
#设置系统环境
#配置ipsec写入自启动
#ipsec_autostart=`find /etc/rc.d -name "rc.local" |xargs grep "^ipsec start"`
#if [ ! -n "$ipsec_autostart" ];then
# echo "ipsec start" >> /etc/rc.d/rc.local
# chmod +x /etc/rc.d/rc.local
#fi
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
#sed -i "s/Defaults requiretty/#Defaults requiretty/g" /etc/sudoers #修改root权限
if [ ! -d "/var/opc/lc" ];then
mkdir -p /var/opt/lc
fi
if [ ! -d "/var/opc/mo" ];then
mkdir -p /var/opt/mo
fi
###########################################修改sysctl.conf表##############################################
ip_forward=`grep "net.ipv4.ip_forward" /etc/sysctl.conf`
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`
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 "$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
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
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
################################################设置coredump##############################################################
cd /root
folder_coredump=coredump
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
default_limit_core=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitCORE"`
default_limit_nofile=`find /etc/systemd -name "system.conf" |xargs grep "^DefaultLimitNOFILE"`
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
#修改ssh登录端口
grep '^Port 50683' /etc/ssh/sshd_config 2>&1>/dev/null
if [ $? -eq 1 ];then
echo 'Port 50683' >> /etc/ssh/sshd_config
systemctl restart sshd
fi
#启动eGW服务
systemctl start monitor.service
%preun
##########################################################################################
systemctl stop monitor.service
pkill ltegwd
pkill startAll.sh
pkill egw_manage
pkill egw_report
DIR=/root/eGW
DIR_bak=${DIR}_bak
if [ -d "$DIR" ];then
#date=`date +%Y%m%d%H%M`
if [ -d "$DIR_bak" ];then #如果备份文件存在,则删除
rm -rf $DIR_bak
fi
echo "cp $DIR to $DIR_bak"
cp -rf $DIR $DIR_bak #如果目录存在,备份目录
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}/static/dailystatic/*
rm -rf ${DIR}/static/userstatic/*
cp /usr/local/lib/libzebra.so.0 /root/eGW
mv /usr/lib/systemd/system/monitor.service /root/eGW
systemctl daemon-reload
fi
%postun
#rm -rf /root/eGW
rm -rf /usr/sbin/lccmd