How can I get Vagrant to start the server on startup?

I want Vagrant to start the Play server in the /vagrant/ folder every time I do vagrant up. Putting @reboot on the crontab doesn't work because the script runs before the /vagrant/ folder is connected.


Instead of using crontab, have you tried using Upstart?

Vagrant emits a "vagrant-mounted" event when the shared folder is mounted, so you could create an upstart conf file, say /etc/init/play.conf, to run when that event is emitted:

description "Play server"
start on vagrant-mounted

pre-start script
    [ "$MOUNTPOINT" == "/vagrant" ] || stop
end script

... rest of config file for starting Play server ...

I found using a seperate vagrant provisioner with the option run : "always" a lot easier, eg:

config.vm.provision :shell, path: "yourStartUp.sh", run: "always", privileged: false

See https://docs.vagrantup.com/v2/provisioning/shell.html for full doc.