1

I want to setup a Vagrant configuration to create and launch an Ubuntu guest VM which will launch a supervisord service within the VM after Vagrant up. I'd like for this to work on Windows, Mac, and Linux hosts.

I have a supervisord.conf file which I copy to the VM during provisioning (by copying to user space first and then copying to /etc/supervisor/ as in this answer). This config file includes these lines to serve a GUI interface on port 9001 (this port is forwarded to the host):

[inet_http_server]
port=9001

However, if I issue a command in the Vagrant provisioning script like service supervisor start then this configuration is not correctly picked up. I can ssh into the VM and verify that the supervisor service is running, but the GUI is not available on port 9001. If I restart the service using ssh, then the GUI becomes available after restart.

That restarting the service causes it to pick up my config makes me think that the configuration wasn't available somehow when the service first started.

This answer seems to address a similar problem. So I tried also copying a file to /etc/init/supervisor.conf:

# start supervisord on vagrant mounted

start on vagrant-mounted

exec service supervisor restart

This would cause upstart to restart the service when it receives the vagrant-mounted event. However, even with this in place, supervisor did not appear to have started correctly.

I tested this upstart script by issuing sudo initctl emit vagrant-mounted, and observed the supervisor service restart, and the GUI became available on 9001.

This makes me think that the vagrant-mounted event probably occurred before the provisioning script was run.

Does anybody know if there's any other event I could predicate my upstart scripts on? Something that is emitted when vagrant provisioning is completed?

Also, is there any better or canonical way of launching a service in a vagrant VM? This all feels like I've gone down a rabbit hole and missed something really obvious.

laffoyb
  • 141
  • 6

1 Answers1

2

Okay, this post let me know that I could emit any upstart event I wanted as the final step in my Vagrantfile:

Vagrant.configure(2) do |config|
    config.vm.provision :file do |file|
        file.source = "./conf/vagrant-ready.conf"
        file.destination = "vagrant-ready.conf"
    end

    config.vm.provision :shell, path: "provision.sh"
    config.vm.provision :shell, :inline => "sudo initctl emit vagrant-ready"
end

And I could trigger restarting the supervisord service with the vagrant-ready event:

# start supervisord on vagrant mounted

start on vagrant-ready

exec service supervisor restart

And my provisioning script is:

#!/bin/bash
apt-get update
apt-get install -y supervisor

mv /home/vagrant/supervisord.conf /etc/supervisor/
mv /home/vagrant/vagrant-ready.conf /etc/init/

This setup ensures that the supervisord service restarts after the file supervisord.conf is in place. That way, my configuration is loaded correctly.

laffoyb
  • 141
  • 6