Systemd is used for services control in Debian Jessie, and, there are some problems with some of the services.
One of thoose problems is: VirtualBox doesn’t restart it’s virtual network adapters after system’s wake-up (from suspension).
When does it happens:
- When you are using VirtualBox version 4.3.8 and lower (didn’t tested this on higher versions)
- When there are a host-only adapter configured in VirtualBox
- You suspended your computer (for example, by closing your laptop), and than woke it up
What are the signs:
- Virtual machine doesn’t respond to ping
- It’s also impossible to connect to a VM via ssh
- If one of VM’s folders mounted by sshfs to a real machine, all porcesses, that used this folder before suspension are freezed badly
What to do?
To restart adapter manually, you can use command like this: (192.168.100.1 – is my host-only adapter’s address, configured in virtualbox)
[bash] # ifconfig vboxnet0 192.168.100.1 up
[/bash] and I have used it for a while, until one this situation made me mad, and I’ve decided to atomate the process.
For automation of the process, let’s create new systemd service, which would run when “resume” event is happened (the computer is resumed from suspension)
Create bash script, what should restore network
Put it into /opt/bin/resume-vboxnet0.sh. Contents are simple:[bash] #!/bin/bash
ifconfig vboxnet0 192.168.100.1 up
Create new systemd service:
New systemd service is represented by a file, which contains:
[bash] [Unit] # Service name
Description=Reconfigure vboxnet0 after resume
# When should service start
# what starts an stay on the background,
# it’s just a simple bash script that is runned once)
# run script resume-vboxnet.sh
ExecStart=/opt/bin/resume-vboxnet.sh [Install] # What services are using this service:
This file should be placed in the /lib/systemd/sys/ folder, under some memorable name, for example, resume-vboxnet.service.
There are all installed systemd services placed in this folder.
Let’s install newly created service, so that systemd load and run it:[bash] # systemctl reenable resume-vboxnet.service
Let’s try how it works
Now, try to close laptop’s lid, so that it go to “sleep” (or use some other method to “sleep” your computer), after that wake it up, and lets see, what state is your vboxnet0 network device in.