Failed to connect to socket /com/ubuntu/upstart: Connection refused: Errors were encountered while processing: runit [duplicate]

I'm using Ubuntu 15.04. Whenever I tried to install any package, I got the error message in the title. How can I get rid of this annoying error message?

:~$ uname -a
Linux LongerVision001 3.19.0-25-generic #26-Ubuntu SMP Fri Jul 24 21:17:31 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:        15.04
Codename:       vivid
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up runit (2.1.2-3ubuntu1) ...
start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
dpkg: error processing package runit (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 runit
E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution 1:

I've encountered the same error. Reading the error message, it appears that the runit install script expects upstart at one point, but my system (and I suspect yours) is running systemd. Notably, I've another machine that did not have this error during installation; the only substantive difference is that the erroring machine was an upgrade from 14.10, while the the "just works" machine was a fresh install.

As Vivid is not an LTS, I submit that one could edit the post installation dpkg file to get this back on track. (This trick should also work for LTS installations as well, but hopefully would be a non-issue).

When dpkg errors out with

Setting up runit (2.1.2-3ubuntu1) ...
start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
dpkg: error processing package runit (--configure):
 subprocess installed post-installation script returned error exit status 1
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
 runit
E: Sub-process /usr/bin/dpkg returned an error code (1)

it will have left the runit package in an semi-installed state. You should find a runit.postinst file in /var/lib/dpkg/info/. This file is executed as part of the post-installation details for the runit package (mainly for starting up runit immediately after installation, as opposed to waiting until next system boot). The error is that the script appears to forget the exclusive nature of systemd/upstart. Since you're clearly not running upstart, comment out the relevant lines (lines 58 - 60 on my install, currently).

Before:

if [ -x /sbin/start ]; then #provided by upstart
  /sbin/start runsvdir
fi

After:

#if [ -x /sbin/start ]; then #provided by upstart
#  /sbin/start runsvdir
#fi

When you've saved that change, you can tell apt to finish where it left off and you should be good to go:

$ sudo apt-get install -f

Solution 2:

Just purge upstart, it's broken anyway.

UPD: runit seems to be incompatible with systemd on ubuntu, that could be a surprise after reboot, runit will just fail saying it's not pid 1:

- runit: fatal: must be run as process no 1.

So the other way is to switch to upstart:

sudo aptitude install upstart-sysv
sudo update-initramfs -u
sudo reboot