hhvm_CentOS.sh 5.2 KB

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