How to run nginx.service after /vagrant is mounted

前端 未结 5 600
青春惊慌失措
青春惊慌失措 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:02

    Summarization previous answers and comments in terms of Ansible (if used for provision):

    - name: Copy Nginx Systemd unit to /etc/
      copy:
        src: /lib/systemd/system/nginx.service
        dest: /etc/systemd/system/nginx.service
        remote_src: yes
    
    - name: Change Nginx Systemd unit
      lineinfile:
        path: /etc/systemd/system/nginx.service
        regexp: '^WantedBy='
        line: 'WantedBy={{ vagrant_mount_unit }}'
        state: present
    
    - name: Systemd daemon reload
      systemd:
        daemon_reload: yes
    
    - name: Disable Nginx
      service:
        name: nginx
        enabled: no
    
    - name: Enable Nginx
      service:
        name: nginx
        enabled: yes
    

    Replace {{ vagrant_mount_unit }} by Vagrant mount unit name. It depends from mount point, e.g. if mount point is /home/vagrant/app, unit name would be home-vagrant-app.mount.

提交回复
热议问题