Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does HHVM in daemon mode not start automatically after server reboot?

HipHop/HHVM can be run as a daemon (so it starts automatically after rebooting) with

sudo /usr/bin/hhvm --mode daemon --config /etc/hhvm/server.hdf

When run, it works perfectly (which shows that the configs are okay). But after restarting the machine HHVM is gone and needs to be restarted manually. The above line incl. the configs have been taken out of official tutorials of the HHVM creators. Classic service syntax like sudo service hhvm start also works perfectly, but doesn't survice a machine restart.

What I've done to track down the problem:

The HHVM error log in /var/log/hhvm/error.log logs this line at each restart: Unable to open pid file /var/run/hhvm/pid for write. /etc/hhvm/server.hdf has PidFile = /var/run/hhvm/pid in first line. As this ships with HHVM by default, I don't want to change it. I think the sudo is the problem here. Without sudo HHVM won't run. Chmod 777'ing the pid file and pointing to another empty file don't solve the problem.

Question:

What's the correct way to install HHVM as a daemon ?

like image 516
Sliq Avatar asked Feb 21 '14 13:02

Sliq


1 Answers

The Manual Way

With reference to HHVM's own packaging material, you need to run hhvm as a daemon.

So, create a file at /etc/init.d/hhvm and paste this:

#! /bin/sh

test -x /usr/bin/hhvm || exit 0

case "$1" in
  start)
        /usr/bin/hhvm --config /etc/hhvm/server.hdf --user www-data --mode daemon
        ;;
  stop)
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/hhvm/pid
        ;;

  reload|force-reload|restart|try-restart)
        $0 stop
        $0 start
        ;;

  status)
        echo "No status"
        ;;

  *)
        echo "Usage: /etc/init.d/hhvm {start|stop|restart|status}"
        exit 1
esac

exit 0

Now, we need to create the /etc/hhvm/server.hdf file. Here is a sample file: https://gist.github.com/sinaa/9151973

And for the /usr/share/hhvm/hdf/static.mime-types.hdf file, use this: https://github.com/hhvm/packaging/blob/master/hhvm/deb/skeleton/usr/share/hhvm/hdf/static.mime-types.hdf

And finally, create the directories:

  • /var/run/hhvm
  • /var/log/hhvm

And now simply start hhvm as a service: /etc/init.d/hhvm restart


The Automated Way: Installing pre-built packages (Ubuntu)

HHVM by default comes with all above, if you are using a pre-built version. You can install it as below (source):

# If this command is not found then do this: sudo apt-get install python-software-properties
sudo add-apt-repository ppa:mapnik/boost
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

After reboot

To get your service to automatically run on boot, run this command:

sudo update-rc.d hhvm defaults
like image 76
Sina Avatar answered Sep 22 '22 16:09

Sina