Results 1 to 3 of 3

Thread: How to access network in the service file while system is shutdown or reboot?

  1. #1

    Default How to access network in the service file while system is shutdown or reboot?

    I have a script which wanted to access network while system is shutdown or reboot.
    Though the systemd service file Required network-online.target, but the script always failed to access the network.

    Here is the service file:
    PHP Code:
    [Unit]
    Description=LSBSome description
    Requires
    =network-online.target network.service
    After
    =network-online.target network.service

    [Service]
    Type=forking
    ExecStart
    =/etc/init.d/my-monitor start
    ExecStop
    =/etc/init.d/my-monitor stop
    RemainAfterExit
    =yes
    TimeoutSec
    =0

    [Install]
    WantedBy=default.target 
    And also I notice there is a service called network@ens.target and if I put it as a requirement.
    The network access is OK.

    So how could I access the network when system shutdown or reboot?

  2. #2
    Join Date
    Sep 2012
    Posts
    7,103

    Default Re: How to access network in the service file while system is shutdown or reboot?

    Quote Originally Posted by sxzzsf View Post
    Code:
    [Unit]
    Description=LSB: Some description
    Requires=network-online.target network.service
    After=network-online.target network.service
    You should use Wants, not Requires here. Requires is too strong. Although end result is the same.

    And also I notice there is a service called network@ens.target
    service, not target
    and if I put it as a requirement.
    The network access is OK.

    So how could I access the network when system shutdown or reboot?
    That's another reincarnation of bug https://bugzilla.novell.com/show_bug.cgi?id=857031
    Network interfaces are configured by network@if.service, but those services themselves do not have any dependency on network-online.target so they are stopped early during shutdown. See https://forums.opensuse.org/english/...ml#post2612702 for a workaround. If it works for you, please add comment to above mentioned bug.

  3. #3

    Default Re: How to access network in the service file while system is shutdown or reboot?

    Quote Originally Posted by arvidjaar View Post
    You should use Wants, not Requires here. Requires is too strong. Although end result is the same.


    service, not target

    That's another reincarnation of bug https://bugzilla.novell.com/show_bug.cgi?id=857031
    Network interfaces are configured by network@if.service, but those services themselves do not have any dependency on network-online.target so they are stopped early during shutdown. See https://forums.opensuse.org/english/...ml#post2612702 for a workaround. If it works for you, please add comment to above mentioned bug.
    Thanks.
    It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •