Search code examples
bashvagrantvagrant-provisionpgadmin-4

How to automatically start pgAdmin 4 in vagrant box


I have a Vagrant box based on ubuntu 14.04 Desktop and installed pgAdmin 4 following the instructions here (desktop mode). So I have pgAdmin in a virtual environnement in /home/vagrant/pgadmin4 and can start it from within the box as follows :

source pgadmin4/bin/activate
python pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py

What I would like to do now is to have pgAdmin up and running when the VM starts (following vagrant up). I added the following in my Vagrantfile :

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

And the shell script is simply :

#!/bin/bash
cd /home/vagrant/
source pgadmin4/bin/activate
python pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py &

But this does not seem to work (I also tried to add disown at the end of the script).

Is there any way I could have pgAdmin running in the background ?


Solution

  • I had issues running the commands with & and I ended up using nohup instead

    #!/bin/bash
    cd /home/vagrant/
    source pgadmin4/bin/activate
    nohup python pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py &> /vagrant/nohup.out&
    

    This way you can also easily check the output of your python command from the nohup.out file, in case there is any error.