How to run nginx.service after /vagrant is mounted

前端 未结 5 601
青春惊慌失措
青春惊慌失措 2021-02-06 07:25

What I want to do?

I\'m trying to make nginx load configurations from /vagrant mounted by vagrant automatically.

So I edited nginx.service to make

5条回答
  •  [愿得一人]
    2021-02-06 08:04

    I wanted to drop my own answer here as it did seem each answer has parts of a correct answer and some details can be found in comments only.

    In this example I have 2 file system mounts in /var/www/mymount1 and /var/www/mymount2

    This part of my Vagrantfile:

    config.vm.provision "shell", path: "docs/vagrant/init-vagrant.sh"
    config.vm.synced_folder "mymount1", "/var/www/mymount1", type: "nfs"
    config.vm.synced_folder "mymount2", "/var/www/mymount2", type: "nfs"
    

    I am placing the script below in /docs/vagrant/init-vagrant.sh as its my provisioner file.

    # Copy nginx systemd script and make edits in /etc/systemd/system, as updates might change the original in /lib/systemd/system/nginx.service
    cp /lib/systemd/system/nginx.service /etc/systemd/system/
    # These tell that nginx should not be started before file system mounts are available
    echo WantedBy=var-www-mymount1.mount >> /etc/systemd/system/nginx.service
    echo WantedBy=var-www-mymount2.mount >> /etc/systemd/system/nginx.service
    
    # Update service symlinks
    systemctl daemon-reload
    systemctl disable nginx.service
    systemctl enable nginx.service
    

提交回复
热议问题