Skip to content

Commit

Permalink
Issue geerlingguy#2154: Add vagrant-nfs-fix role to fix NFS timeout i…
Browse files Browse the repository at this point in the history
…ssues on macOS

Co-authored-by: MokDevelopment
Co-authored-by: Susanne Coates <[email protected]>
  • Loading branch information
oxyc and Susanne Coates committed May 4, 2021
1 parent 0c3af7d commit 639d773
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
4 changes: 4 additions & 0 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ vagrant_plugins:
- name: vagrant-vbguest
- name: vagrant-hostsupdater

# Automatically fix timeout issues with NFS on macOS. See
# https://github.com/geerlingguy/drupal-vm/issues/2154
vagrant_nfs_fix_enabled: "{{ vagrant_synced_folder_default_type == 'nfs' }}"

ansible_python_interpreter: python3

# Minimum required versions.
Expand Down
1 change: 1 addition & 0 deletions provisioning/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- { role: geerlingguy.repo-epel, when: ansible_os_family == 'RedHat' }
- { role: geerlingguy.repo-remi, when: ansible_os_family == 'RedHat', tags: ['webserver', 'php'] }
- { role: drupalvm.hostname, when: hostname_configure }
- { role: drupalvm.vagrant-nfs-fix, when: vagrant_nfs_fix_enabled }
- { role: geerlingguy.firewall, when: firewall_enabled }
- { role: geerlingguy.git }
- { role: geerlingguy.postfix }
Expand Down
29 changes: 29 additions & 0 deletions provisioning/roles/drupalvm.vagrant-nfs-fix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Drupal VM Vagrant NFS Fix Role

This role exists to fix [issue #2154](https://github.com/geerlingguy/drupal-vm/issues/2154).

## Requirements

This role is meant to be run in Drupal VM.

## Role Variables

Available variables are listed below:

```yaml
vagrant_nfs_fix_keepalive_file: "/vagrant/.vagrant-nfs-fix-keepalive.tmp"
```
Path to the keepalive file that we'll be `touch`ed every 30 seconds to keep NFS from timing out.

## Dependencies

None.

## License

MIT / BSD

## Author Information

This role was created in 2021 by [Oskar Schöldström](http://oxy.fi) and [Jeff Geerling](https://www.jeffgeerling.com/) (author of [Ansible for DevOps](https://www.ansiblefordevops.com/)).
2 changes: 2 additions & 0 deletions provisioning/roles/drupalvm.vagrant-nfs-fix/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
vagrant_nfs_fix_keepalive_file: "/vagrant/.vagrant-nfs-fix-keepalive.tmp"
32 changes: 32 additions & 0 deletions provisioning/roles/drupalvm.vagrant-nfs-fix/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Copy Vagrant NFS fix script into place.
template:
src: vagrant-nfs-fix.j2
dest: /usr/sbin/vagrant-nfs-fix
owner: root
group: root
mode: 0755

- name: Copy Vagrant NFS fix init script into place.
template:
src: vagrant-nfs-fix.init.j2
dest: /etc/init.d/vagrant-nfs-fix
owner: root
group: root
mode: 0755
when: ansible_service_mgr != 'systemd'

- name: Copy Vagrant NFS fix systemd unit file into place (for systemd systems).
template:
src: vagrant-nfs-fix.unit.j2
dest: /etc/systemd/system/vagrant-nfs-fix.service
owner: root
group: root
mode: 0644
when: ansible_service_mgr == 'systemd'

- name: Configure the NFS fix service.
service:
name: vagrant-nfs-fix
state: started
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /bin/sh
# /etc/init.d/vagrant-nfs-fix

### BEGIN INIT INFO
# Provides: vagrant-nfs-fix
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start vagrant-nfs-fix at boot time
# Description: Continuously touch a file within an NFS mount to avoid timeout problems on macOS.
### END INIT INFO

PID_FILE="/var/run/vagrant-nfs-fix.pid"

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting vagrant-nfs-fix."
/usr/sbin/vagrant-nfs-fix &
echo $! > $PID_FILE
;;
stop)
echo "Stopping vagrant-nfs-fix."
kill `cat $PID_FILE`
rm $PID_FILE
;;
restart)
echo "Restarting firewall."
kill `cat $PID_FILE`
rm $PID_FILE

/usr/sbin/vagrant-nfs-fix &
echo $! > $PID_FILE
;;
status)
EXIT=4 # program or service status is unknown
if [ -e $PID_FILE ]; then
if ps -p `cat $PID_FILE` > /dev/null 2>&1; then
EXIT=0 # program is running or service is OK
else
EXIT=3 # program is not running
fi
else
EXIT=3 # program is not running
fi
exit $EXIT
;;
*)
echo "Usage: /etc/init.d/vagrant-nfs-fix {start|stop|status|restart}"
exit 1
;;
esac

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

while true; do
touch {{ vagrant_nfs_fix_keepalive_file }}
sleep 30
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Workaround for vagrant NFS inactivity bug
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/sbin/vagrant-nfs-fix

[Install]
WantedBy=multi-user.target

0 comments on commit 639d773

Please sign in to comment.