#291 Failed to restart network.service: Unit network.service not found.
Closed: fixed 4 years ago by jdoss. Opened 6 years ago by jdoss.

Rawhide removes network.service and this breaks things with Vagrant with the following error:

==> rawhide: Setting hostname...
#<Thread:0x000055e940a3b388@/usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/batch_action.rb:71 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    67: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'
    66: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/machine.rb:188:in `action'
    65: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/machine.rb:188:in `call'
    64: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/environment.rb:592:in `lock'
    63: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/machine.rb:202:in `block in action'
    62: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/machine.rb:227:in `action_raw'
    61: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/runner.rb:66:in `run'
    60: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/util/busy.rb:19:in `busy'
    59: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/runner.rb:66:in `block in run'
    58: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builder.rb:116:in `call'
    57: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    56: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    55: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    54: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/call.rb:53:in `call'
    53: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/runner.rb:66:in `run'
    52: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/util/busy.rb:19:in `busy'
    51: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/runner.rb:66:in `block in run'
    50: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builder.rb:116:in `call'
    49: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    48: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
    47: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    46: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/set_name_of_domain.rb:35:in `call'
    45: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    44: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/handle_storage_pool.rb:52:in `call'
    43: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    42: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
    41: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    40: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/handle_box_image.rb:113:in `call'
    39: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    38: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/create_domain_volume.rb:82:in `call'
    37: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    36: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/create_domain.rb:308:in `call'
    35: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    34: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/provision.rb:80:in `call'
    33: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    32: from /home/jdoss/.vagrant.d/gems/2.5.1/gems/vagrant-omnibus-1.5.0/lib/vagrant-omnibus/action/install_chef.rb:38:in `call'
    31: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    30: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb:12:in `call'
    29: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    28: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/plugins/synced_folders/nfs/action_cleanup.rb:25:in `call'
    27: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    26: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/synced_folder_cleanup.rb:28:in `call'
    25: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    24: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/synced_folders.rb:87:in `call'
    23: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    22: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/prepare_nfs_settings.rb:18:in `call'
    21: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    20: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/share_folders.rb:20:in `call'
    19: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    18: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/create_networks.rb:83:in `call'
    17: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    16: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/create_network_interfaces.rb:176:in `call'
    15: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    14: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/set_boot_order.rb:78:in `call'
    13: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    12: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/start_domain.rb:298:in `call'
    11: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
    10: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/wait_till_up.rb:77:in `call'
     9: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
     8: from /usr/share/vagrant/gems/gems/vagrant-libvirt-0.0.40/lib/vagrant-libvirt/action/forward_ports.rb:29:in `call'
     7: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/warden.rb:34:in `call'
     6: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/set_hostname.rb:21:in `call'
     5: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/guest.rb:43:in `capability'
     4: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/capability_host.rb:111:in `capability'
     3: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/lib/vagrant/capability_host.rb:111:in `call'
     2: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/plugins/guests/redhat/cap/change_host_name.rb:10:in `change_host_name'
     1: from /usr/share/vagrant/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:267:in `sudo'
/usr/share/vagrant/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:257:in `execute': The following SSH command responded with a non-zero exit status. (Vagrant::Errors::VagrantError)
Vagrant assumes that this means the command failed!

# Update sysconfig
sed -i 's/\(HOSTNAME=\).*/\1rawhide.kennasec.com/' /etc/sysconfig/network

# Update DNS
sed -i 's/\(DHCP_HOSTNAME=\).*/\1"rawhide"/' /etc/sysconfig/network-scripts/ifcfg-*

# Set the hostname - use hostnamectl if available
echo 'rawhide.kennasec.com' > /etc/hostname
if command -v hostnamectl; then
  hostnamectl set-hostname --static 'rawhide.kennasec.com'
  hostnamectl set-hostname --transient 'rawhide.kennasec.com'
else
  hostname -F /etc/hostname
fi

# Prepend ourselves to /etc/hosts
grep -w 'rawhide.kennasec.com' /etc/hosts || {
  sed -i'' '1i 127.0.0.1\trawhide.kennasec.com\trawhide' /etc/hosts
}

# Restart network
service network restart


Stdout from the command:

/usr/bin/hostnamectl


Stderr from the command:

Redirecting to /bin/systemctl restart network.service
Failed to restart network.service: Unit network.service not found.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

# Update sysconfig
sed -i 's/\(HOSTNAME=\).*/\1rawhide.kennasec.com/' /etc/sysconfig/network

# Update DNS
sed -i 's/\(DHCP_HOSTNAME=\).*/\1"rawhide"/' /etc/sysconfig/network-scripts/ifcfg-*

# Set the hostname - use hostnamectl if available
echo 'rawhide.kennasec.com' > /etc/hostname
if command -v hostnamectl; then
  hostnamectl set-hostname --static 'rawhide.kennasec.com'
  hostnamectl set-hostname --transient 'rawhide.kennasec.com'
else
  hostname -F /etc/hostname
fi

# Prepend ourselves to /etc/hosts
grep -w 'rawhide.kennasec.com' /etc/hosts || {
  sed -i'' '1i 127.0.0.1\trawhide.kennasec.com\trawhide' /etc/hosts
}

# Restart network
service network restart


Stdout from the command:

/usr/bin/hostnamectl


Stderr from the command:

Redirecting to /bin/systemctl restart network.service
Failed to restart network.service: Unit network.service not found.

This seems to be a Vagrant bug with changing the hostname when network.service is not installed. https://github.com/hashicorp/vagrant/issues/7750 is a similar issue.

We are seeing errors when setting the hostname but this code has only checks for restarting the network hard coded with network.service: https://github.com/hashicorp/vagrant/blob/85acf0cac724ef4bfda593a66e0c17f7e4110da0/plugins/guests/redhat/cap/change_host_name.rb#L32

This means we most likely need a PR to Vagrant itself to check to see if network.service is installed and if not, adjust this the command being sent via SSH to use NetworkManager.service instead. This code here https://github.com/hashicorp/vagrant/blob/85acf0cac724ef4bfda593a66e0c17f7e4110da0/plugins/guests/redhat/cap/configure_networks.rb#L21 has that kind of logic that we are looking for.


thanks @jdoss for opening this bug!

we can ask vagrant maintainers for input. cc @vondruch @pvalena

Well, it seems that some script is executed viassh on guest.

Specifically, this command fails:
service network restart
which returns error:
Failed to restart network.service: Unit network.service not found.

I'm not sure what the cause is- did something on guest changed? Have you tried using newer Vagrant? You can try this one, f.e.:

https://copr.fedorainfracloud.org/coprs/pvalena/vagrant/

@pvalena for some backround, yes something did change. We moved the cloud image to use NetworkManager because legacy network scripts got removed. See https://bugzilla.redhat.com/show_bug.cgi?id=1596062#c1. So what we need to do is get the vagrant glue code updated to conditionally run service network restart only if fedora version is <= 28. Do you think that is something you could help with?

I see. So this would be a general Fedora issue, which needs to be resolved in Vagrant upstream, right?

It would really help if you could check whether it's fixed in new Vagrant (rawhide) version, so I'd just backport it.

You can get the rawhide version from my copr (F27+):
https://copr.fedorainfracloud.org/coprs/pvalena/vagrant/

I could also push the fix there first (prior to rawhide or upstream) for you to test it.

Also, would you mind filing a bugzilla issue? JFTR.

@jdoss do you mind picking up @pvalena 's suggestions ?

@pvalena The problem still exists with the Rawhide version. Upstream vagrant only calls service network restart so that needs to get addressed to fix this problem. The line that it calls this is:

https://github.com/hashicorp/vagrant/blob/85acf0cac724ef4bfda593a66e0c17f7e4110da0/plugins/guests/redhat/cap/change_host_name.rb#L32

I have created a BZ for this issue as well. https://bugzilla.redhat.com/show_bug.cgi?id=1624068

I submitted a PR upstream Vagrant to fix this issue. https://github.com/hashicorp/vagrant/pull/10214

Metadata Update from @jdoss:
- Issue assigned to jdoss

6 years ago

Metadata Update from @jdoss:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

4 years ago

Log in to comment on this ticket.

Metadata