hhvm_CentOS.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_hhvm_CentOS() {
  11. cd $oneinstack_dir/src
  12. id -u $run_user >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  14. if [ "$CentOS_RHEL_version" == '7' ];then
  15. if [ -e /etc/yum.repos.d/epel.repo_bk ];then
  16. /bin/mv /etc/yum.repos.d/epel.repo{_bk,}
  17. elif [ ! -e /etc/yum.repos.d/epel.repo ];then
  18. cat > /etc/yum.repos.d/epel.repo << EOF
  19. [epel]
  20. name=Extra Packages for Enterprise Linux 7 - \$basearch
  21. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  22. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  23. failovermethod=priority
  24. enabled=1
  25. gpgcheck=0
  26. EOF
  27. fi
  28. cat > /etc/yum.repos.d/hhvm.repo << EOF
  29. [hhvm]
  30. name=gleez hhvm-repo
  31. baseurl=http://mirrors.linuxeye.com/hhvm-repo/7/\$basearch/
  32. enabled=1
  33. gpgcheck=0
  34. EOF
  35. yum -y install hhvm
  36. [ ! -e "/usr/bin/hhvm" -a "/usr/local/bin/hhvm" ] && ln -s /usr/local/bin/hhvm /usr/bin/hhvm
  37. fi
  38. if [ "$CentOS_RHEL_version" == '6' ];then
  39. if [ -e /etc/yum.repos.d/epel.repo_bk ];then
  40. /bin/mv /etc/yum.repos.d/epel.repo{_bk,}
  41. elif [ ! -e /etc/yum.repos.d/epel.repo ];then
  42. cat > /etc/yum.repos.d/epel.repo << EOF
  43. [epel]
  44. name=Extra Packages for Enterprise Linux 6 - \$basearch
  45. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  46. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  47. failovermethod=priority
  48. enabled=1
  49. gpgcheck=0
  50. EOF
  51. fi
  52. for Package in libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel libevent-devel libcurl-devel libmemcached-devel lcms2 inotify-tools
  53. do
  54. yum -y install $Package
  55. done
  56. yum -y remove libwebp boost-system boost-filesystem
  57. cat > /etc/yum.repos.d/hhvm.repo << EOF
  58. [hhvm]
  59. name=gleez hhvm-repo
  60. baseurl=http://mirrors.linuxeye.com/hhvm-repo/6/\$basearch/
  61. enabled=1
  62. gpgcheck=0
  63. EOF
  64. yum --disablerepo=epel -y install mysql mysql-devel mysql-libs
  65. yum --disablerepo=epel -y install hhvm
  66. fi
  67. userdel -r nginx;userdel -r saslauth
  68. rm -rf /var/log/hhvm
  69. mkdir /var/log/hhvm
  70. chown -R ${run_user}.${run_user} /var/log/hhvm
  71. cat > /etc/hhvm/config.hdf << EOF
  72. ResourceLimit {
  73. CoreFileSize = 0 # in bytes
  74. MaxSocket = 10000 # must be not 0, otherwise HHVM will not start
  75. SocketDefaultTimeout = 5 # in seconds
  76. MaxRSS = 0
  77. MaxRSSPollingCycle = 0 # in seconds, how often to check max memory
  78. DropCacheCycle = 0 # in seconds, how often to drop disk cache
  79. }
  80. Log {
  81. Level = Info
  82. AlwaysLogUnhandledExceptions = true
  83. RuntimeErrorReportingLevel = 8191
  84. UseLogFile = true
  85. UseSyslog = false
  86. File = /var/log/hhvm/error.log
  87. Access {
  88. * {
  89. File = /var/log/hhvm/access.log
  90. Format = %h %l %u % t \"%r\" %>s %b
  91. }
  92. }
  93. }
  94. MySQL {
  95. ReadOnly = false
  96. ConnectTimeout = 1000 # in ms
  97. ReadTimeout = 1000 # in ms
  98. SlowQueryThreshold = 1000 # in ms, log slow queries as errors
  99. KillOnTimeout = false
  100. }
  101. Mail {
  102. SendmailPath = /usr/sbin/sendmail -t -i
  103. ForceExtraParameters =
  104. }
  105. EOF
  106. cat > /etc/hhvm/server.ini << EOF
  107. ; php options
  108. pid = /var/log/hhvm/pid
  109. ; hhvm specific
  110. ;hhvm.server.port = 9001
  111. hhvm.server.file_socket = /var/log/hhvm/sock
  112. hhvm.server.type = fastcgi
  113. hhvm.server.default_document = index.php
  114. hhvm.log.use_log_file = true
  115. hhvm.log.file = /var/log/hhvm/error.log
  116. hhvm.repo.central.path = /var/log/hhvm/hhvm.hhbc
  117. EOF
  118. cat > /etc/hhvm/php.ini << EOF
  119. hhvm.mysql.socket = /tmp/mysql.sock
  120. expose_php = 0
  121. memory_limit = 400000000
  122. post_max_size = 50000000
  123. EOF
  124. if [ -e "$web_install_dir/sbin/nginx" -a -e "/usr/bin/hhvm" -a ! -e "$php_install_dir" ];then
  125. sed -i 's@/dev/shm/php-cgi.sock@/var/log/hhvm/sock@' $web_install_dir/conf/nginx.conf
  126. [ -z "`grep 'fastcgi_param SCRIPT_FILENAME' $web_install_dir/conf/nginx.conf`" ] && sed -i "s@fastcgi_index index.php;@&\n\t\tfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;@" $web_install_dir/conf/nginx.conf
  127. sed -i 's@include fastcgi.conf;@include fastcgi_params;@' $web_install_dir/conf/nginx.conf
  128. service nginx reload
  129. fi
  130. rm -rf /etc/ld.so.conf.d/*_64.conf
  131. ldconfig
  132. # Supervisor
  133. yum -y install python-setuptools
  134. ping pypi.python.org -c 4 >/dev/null 2>&1
  135. easy_install supervisor
  136. echo_supervisord_conf > /etc/supervisord.conf
  137. sed -i 's@pidfile=/tmp/supervisord.pid@pidfile=/var/run/supervisord.pid@' /etc/supervisord.conf
  138. [ -z "`grep 'program:hhvm' /etc/supervisord.conf`" ] && cat >> /etc/supervisord.conf << EOF
  139. [program:hhvm]
  140. command=/usr/bin/hhvm --mode server --user $run_user --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
  141. numprocs=1 ; number of processes copies to start (def 1)
  142. directory=/tmp ; directory to cwd to before exec (def no cwd)
  143. autostart=true ; start at supervisord start (default: true)
  144. autorestart=unexpected ; whether/when to restart (default: unexpected)
  145. stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  146. EOF
  147. /bin/cp ../init.d/Supervisor-init-CentOS /etc/init.d/supervisord
  148. chmod +x /etc/init.d/supervisord
  149. chkconfig supervisord on
  150. service supervisord start
  151. cd ..
  152. }