Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 13 down vote accepted

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 ...
share|improve this answer
    
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
    
Oops! I edited the post so that the syntax is correct. – billyw Jan 17 '14 at 17:30
    
Just the solution for my problem, Thanks – davidselo Apr 24 '14 at 7:16
    
Can start on vagrant-mounted MOUNTPOINT=/vagrant work as well? – ogc-nick Aug 26 '15 at 18:54
    
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 4 at 14:15

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.

share|improve this answer
1  
Simple solution requiring no plugins. Thanks! – Martin Carney Jan 21 '15 at 18:49
1  
This is by far the best solution! Thank you! – wulftone May 1 '15 at 23:16
2  
The provided link doesn't say anything about "always". Maybe this was removed in an newer version. – Rafael Eyng Jan 26 at 21:10
4  
@RafaelEyng the docs for it are at vagrantup.com/docs/provisioning/basic_usage.html, search for "RUN ONCE OR ALWAYS" – dantiberian Jan 28 at 3:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.