Clear the container before decoding for inplace adapter
[hiphop-php.git] / hphp / tools / oss-repo-mode
blobfdda35e0c836ba53f79337571b7323e363572970
1 #!/bin/sh
3 set -e
5 INI="/etc/hhvm/server.ini"
7 usage() {
8 echo "Usage: $0 enable root-dir"
9 echo " $0 disable"
10 echo
11 echo "Enables HHVM's \"repo authoritative\" mode. In this mode, HHVM"
12 echo "uses a pre-built and pre-optimized version of your PHP or Hack"
13 echo "source code. These ahead-of-time optimizations mean that code run"
14 echo "in repo mode can be significantly faster. Keep in mind that after"
15 echo "this mode is enabled, source code is no longer consulted, so"
16 echo "changes there will not be reflected unless this command is re-run"
17 echo "to either rebuild the repo or disable repo authoritative mode."
18 echo
19 echo "This command changes HHVM configuration; you will probably need"
20 echo "to be root."
21 echo
22 echo
23 echo "$0 enable root-dir"
24 echo
25 echo "Enables repo authoritative mode. Finds PHP or Hack source code"
26 echo "under \"root-dir\" and computes an optimized repo where that code"
27 echo "(and only that code) is available. If repo mode is already"
28 echo "enabled, the repo will be recomputed and replaced."
29 echo
30 echo
31 echo "$0 disable"
32 echo
33 echo "Disables repo authoritative mode. HHVM will return to its default"
34 echo "configuration of reading and executing code directly from disk."
35 exit 1
38 set_hhbc() {
39 HHBC=`grep hhvm.repo.path "$INI" | sed 's/[^=]*=\s*\(.*\)/\1/'`
40 if [ "x$HHBC" = "x" ]; then
41 mkdir -p /var/cache/hhvm
42 USER=`stat -c "%U" "/var/run/hhvm"`
43 chown -R "$USER" "/var/cache/hhvm"
44 echo "hhvm.repo.path = /var/cache/hhvm/hhvm.hhbc" >> "$INI"
45 HHBC="/var/cache/hhvm/hhvm.hhbc"
49 repo_enable() {
50 FILE_LIST=`mktemp`
51 find "$1" -type f > "$FILE_LIST"
53 OUT_DIR=`dirname "$HHBC"`
54 hhvm --hphp --output-dir "$OUT_DIR" --input-list "$FILE_LIST" -l3
56 OUT_DIR_USER=`stat -c "%U" "$OUT_DIR"`
57 HHBC_USER=`stat -c "%U" "$HHBC"`
58 if [ "$OUT_DIR_USER" != "$HHBC_USER" ]; then
59 chown "$OUT_DIR_USER" "$HHBC"
62 echo "hhvm.repo.authoritative = true" >> "$INI"
65 repo_disable() {
66 rm -f "$HHBC"
67 sed -i '/hhvm.repo.authoritative/d' "$INI"
70 case "$1" in
71 enable)
72 if [ "$#" -ne 2 ] || ! [ -d "$2" ]; then
73 echo "Invalid root-dir"
74 usage
76 service hhvm stop
77 set_hhbc
78 repo_disable
79 repo_enable "$2"
80 service hhvm start
82 disable)
83 service hhvm stop
84 set_hhbc
85 repo_disable
86 service hhvm start
89 usage
91 esac
93 echo
94 echo "Success!"