I have a Vagrant box running Ubuntu 15.04, which has an upstart script that starts a service when the system boots. It has a start on vagrant-mounted stanza because the service requires that the /vagrant directory be mounted by Vagrant.

I am now migrating this script to systemd (which I am completely new to) and cannot get the script to successfully run during boot because /vagrant is not mounted when the script is run. After=vagrant-mounted doesn't work, but might help show what I'm trying to do.

How do I run a systemd unit when a Vagrant directory has been mounted during boot?

Note systemctl start my.service does successfully start the service, and the service is systemctl enabled'ed.


My understanding of the Vagrant boot sequence is that Vagrant mounts /vagrant (and any other shared filesystems you have defined) using SSH, after the boot sequence has completed.

As such, you'll probably want to run systemctl start my.service in a provisioner, with run: always specified, so the provisioner runs on every boot, not just when the VM is initially created.

This wouldn't be necessary if systemd had the ability to detect when a filesystem was mounted, but to my surprise I can't find any indication that systemd supports such functionality.

  • I came to the same conclusion myself; if the script is simple enough, it has been recommended to just put it in its own bash script and run it with run: 'always' like you said. Of course, this works if systemd specific functionality isn't needed. – T.J. Mazeika Sep 27 '15 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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