hhvm_CentOS.sh 5.1 KB

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