How to Solve Error Failed to acquire pid file ‘/var/run/libvirtd.pid’: Resource temporarily unavailable

Posted on

The title of this article has clearly shown the purpose of this article for being written. It is just to show how to solve an error occurred upon restarting or starting the libvirt daemon or libvirt service. Before going further, based on the reference given in Wikipedia, libvirt in this context is actually a library is an open-source API, daemon and management tool for managing platform virtualization. So, it relates closely with virtualization technology which is currently used to manage KVM, Xen, VMware ESX, QEMU and other virtualization technologies. The API provided from the library are widely used in the orchestration layer of hypervisors in the development of a cloud-based solution. For further information about libvirt, just visit the Wikipedia page about libvirt in this link .

The actual error is stated in the title of the article, but the error itself is actually found in a different error message which is also generated in the webvirt page. The error is :

root@hostname:/var/www/webvirtmgr$ virsh -c qemu://system
error: failed to connect to the hypervisor
error: Cannot read CA certificate '/etc/pki/CA/cacert.pem': No such file or directory
root@hostname:/var/www/webvirtmgr$ 

But soon as the service is checked below is the actual output of error generated of the libvirt daemon or libvirt service :

root@hostname:~# systemctl status libvirtd
● libvirt-bin.service - Virtualization daemon
   Loaded: loaded (/lib/systemd/system/libvirt-bin.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2018-05-03 18:13:39; 2 days ago
     Docs: man:libvirtd(8)
           http://libvirt.org
  Process: 1244 ExecStart=/usr/sbin/libvirtd $libvirtd_opts (code=exited, status=0/SUCCESS)
 Main PID: 1244 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/libvirt-bin.service
           ├─2326 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
           └─2327 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
...
May 05 17:30:36 hostname libvirtd[1332]: Unable to read from monitor: Connection reset by peer
root@hostname:~#

By executing the command journalctl -xe to print any , the following information can be retrieved :

May 05 19:30:46 hostname libvirtd[17169]: /usr/sbin/libvirtd: error: Unable to obtain pidfile. Check /var/log/messages or run without --daemon for more info.
May 05 19:30:46 hostname libvirtd[17171]: Failed to acquire pid file '/var/run/libvirtd.pid': Resource temporarily unavailable
May 05 19:30:46 hostname systemd[1]: libvirt-bin.service: Main process exited, code=exited, status=1/FAILURE
May 05 19:30:46 hostname systemd[1]: Failed to start Virtualization daemon.

Since the actual service is inactive, try to search the process :

root@hostname:~# ps -ef | grep libvirtd
root 16092 1 0 19:27 ? 00:00:00 /usr/sbin/libvirtd -d -l
root 18769 30750 0 19:40 pts/3 00:00:00 grep --color=auto libvirtd
root@hostname:~#

Since the process or the daemon of libvirt exist but apparently something went wrong with it, just kill the process as shown below :

root@hostname:~# kill -9 16092

After trying to restart or start the libvirt daemon or service as shown as follows :

root@hostname:~# systemctl start libvirtd
root@hostname:~# systemctl status libvirtd
● libvirt-bin.service - Virtualization daemon
   Loaded: loaded (/lib/systemd/system/libvirt-bin.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2018-05-05 19:41:22; 4s ago
     Docs: man:libvirtd(8)
           http://libvirt.org
  Process: 18908 ExecStart=/usr/sbin/libvirtd $libvirtd_opts (code=exited, status=0/SUCCESS)
 Main PID: 18908 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/libvirt-bin.service
           ├─ 2326 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
           ├─ 2327 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
           ├─18910 /usr/sbin/libvirtd -d -l
           └─18958 /usr/sbin/libvirtd -d -l

May 05 19:41:21 hostname systemd[1]: Starting Virtualization daemon...
May 05 19:41:22 hostname systemd[1]: Started Virtualization daemon.

After it has been successfully restarted, just execute the following command to try to connect to the libvirt service :

root@hostname:~# virsh -c qemu:///system
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # 

So, in summary, the error is caused by the libvirtd or libvirt daemon which in an unknown state. So, in order to make the solution simple, just kill the process and restart the service. In the context of the error found in this case, the solution is working.

One thought on “How to Solve Error Failed to acquire pid file ‘/var/run/libvirtd.pid’: Resource temporarily unavailable

Leave a Reply