|
| 1 | +#! /bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# check net |
| 5 | +ping -q -w 1 -c 1 www.baidu.com > /dev/null || (echo "Plese check your network." && exit 1) |
| 6 | +#nslookup www.baidu.com >/dev/null || (echo "Plese check your dns!" && exit 1) |
| 7 | + |
| 8 | +# Determine OS platform |
| 9 | +UNAME=$(uname | tr "[:upper:]" "[:lower:]") |
| 10 | +# If Linux, try to determine specific distribution |
| 11 | +if [ "$UNAME" = "linux" ]; then |
| 12 | + # If available, use LSB to identify distribution |
| 13 | + if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then |
| 14 | + distro=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//) |
| 15 | + # Otherwise, use release info file |
| 16 | + else |
| 17 | + distro=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1) |
| 18 | + fi |
| 19 | +fi |
| 20 | +# For everything else (or if above failed), just use generic identifier |
| 21 | +[ "$distro" = "" ] && distro=$UNAME |
| 22 | +unset UNAME |
| 23 | + |
| 24 | +# set user id |
| 25 | +if [ $1 ];then |
| 26 | + uid=$1 |
| 27 | +else |
| 28 | + uid="2" |
| 29 | +fi |
| 30 | + |
| 31 | +# set device name |
| 32 | +if [ $2 ];then |
| 33 | + hname=$2 |
| 34 | +else |
| 35 | + hname=`ip -4 route get 114.114.114.114 | awk {'print $7'} | tr -d '\n'` |
| 36 | +fi |
| 37 | + |
| 38 | +minstall(){ |
| 39 | + # set hugepage and memlock |
| 40 | + grep -q -F '* soft memlock 262144' /etc/security/limits.conf || echo '* soft memlock 262144' >> /etc/security/limits.conf |
| 41 | + grep -q -F '* hard memlock 262144' /etc/security/limits.conf || echo '* hard memlock 262144' >> /etc/security/limits.conf |
| 42 | + grep -q -F 'vm.nr_hugepages = 256' /etc/sysctl.conf || echo 'vm.nr_hugepages = 256' >> /etc/sysctl.conf |
| 43 | + set +e |
| 44 | + sysctl -w vm.nr_hugepages=256 |
| 45 | + set -e |
| 46 | + |
| 47 | + #apt-get -y install libhwloc4 |
| 48 | + wget http://www.yiluzhuanqian.com/soft/linux/yilu_centos6.tgz -O /opt/yilu.tgz |
| 49 | + tar zxf /opt/yilu.tgz -C /opt/ |
| 50 | + |
| 51 | + /opt/yilu/mservice -user_id $uid -reg_device -dev_name $hname |
| 52 | + |
| 53 | + # uninstall old service |
| 54 | + set +e |
| 55 | + /opt/yilu/mservice -service uninstall |
| 56 | + |
| 57 | + # install new service |
| 58 | + /opt/yilu/mservice -service install |
| 59 | + |
| 60 | + # give priority to make money |
| 61 | + sed -i 's/"cpu_priority": 1/"cpu_priority": 34/g' /opt/yilu/work/workers.json |
| 62 | +} |
| 63 | + |
| 64 | +if [[ "${distro,,}" = *"ubuntu"* ]] || [[ "${distro,,}" = *"debian"* ]];then |
| 65 | + set +e |
| 66 | + apt-get -y update |
| 67 | + apt-get -y install wget cron sudo |
| 68 | + set -e |
| 69 | + minstall |
| 70 | + # start |
| 71 | + service YiluzhuanqianSer restart |
| 72 | + # start with system boot |
| 73 | + sudo crontab -l -u root 2>/dev/null | grep -q -F 'service YiluzhuanqianSer start' || (sudo crontab -l -u root 2>/dev/null;echo "* * * * * pidof mservice || service YiluzhuanqianSer start") | sudo crontab -u root - |
| 74 | +elif [[ "${distro,,}" = *"centos"* ]] || [[ "${distro,,}" = *"redhat"* ]];then |
| 75 | + set +e |
| 76 | + yum -y update |
| 77 | + yum -y install wget crontab sudo |
| 78 | + set -e |
| 79 | + osversion=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release` |
| 80 | + if [[ "$osversion" = "7"* ]];then |
| 81 | + minstall |
| 82 | + # start |
| 83 | + service YiluzhuanqianSer restart |
| 84 | + # start with system boot |
| 85 | + sudo crontab -l -u root 2>/dev/null | grep -q -F 'service YiluzhuanqianSer start' || (sudo crontab -l -u root 2>/dev/null;echo "* * * * * pidof mservice || service YiluzhuanqianSer start") | sudo crontab -u root - |
| 86 | + elif [[ "$osversion" = "6"* ]];then |
| 87 | + minstall |
| 88 | + # start |
| 89 | + sudo pidof mservice | xargs kill -9 2>/dev/null |
| 90 | + nohup /opt/yilu/mservice > /dev/null 2>&1 & |
| 91 | + # start with system boot |
| 92 | + sudo crontab -l -u root 2>/dev/null | grep -q -F 'service YiluzhuanqianSer start' || (sudo crontab -l -u root 2>/dev/null;echo "* * * * * pidof mservice || nohup /opt/yilu/mservice > /dev/null 2>&1 &") | sudo crontab -u root - |
| 93 | + fi |
| 94 | +else |
| 95 | + echo $distro |
| 96 | + echo "This system is not supported!" && exit 1 |
| 97 | +fi |
| 98 | + |
| 99 | +sleep 10 |
| 100 | +tail /opt/yilu/work/xig/debug.log -n 100 |
| 101 | +bash mservice.sh 23736 |
0 commit comments