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.
Asked
Active
Viewed 2.0k times
2 Answers
44
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.
culmat
- 541
- 1
- 4
- 2
-
3The provided link doesn't say anything about `"always"`. Maybe this was removed in an newer version. – Rafael Eyng Jan 26 '16 at 21:10
-
7@RafaelEyng the docs for it are at https://www.vagrantup.com/docs/provisioning/basic_usage.html, search for "RUN ONCE OR ALWAYS" – Daniel Compton Jan 28 '16 at 03:10
-
Retested in 2017. Works like a charm. This is the best answer and still up-to-date. – iaforek Sep 04 '17 at 13:32
16
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 ...
billyw
- 1,552
- 15
- 25
-
Thanks! Not sure why I got the error `/bin/sh: 1: [: =: unexpected operator`, so I just uncommented that line. – wrongusername Jan 17 '14 at 17:13
-
-
-
For my upstart script `start on vagrant-mounted` doesn't work for some reason. Don't know why and don't know how to debug it at all. – maectpo Jan 04 '16 at 14:15