Re: Autostart command after network is available (usbip)

2022-02-09 Thread Andrei POPESCU
On Ma, 08 feb 22, 17:49:16, Christian Britz wrote:
> 
> 
> On 2022-02-08 17:44 UTC+0100, Christian Britz wrote:
> 
> > [Install]
> > WantedBy=multiuser.target
> 
> Changed that to
> 
> [Install]
> WantedBy=network-online.target

That's like putting the carriage before the horse ;)

(and it probably works only by chance)

You need Wants=network-online.target in addition to After=, see
'man systemd.special' for details.

Kind regards,
Andrei
-- 
http://wiki.debian.org/FAQsFromDebianUser


signature.asc
Description: PGP signature


Re: Autostart command after network is available (usbip)

2022-02-09 Thread 황병희
Andy Smith  writes:

> [... long line snip ...]
> 
> https://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/

Thanks Andy! Added into my bookmark Firefox.

Sincerely, Linux fan Byung-Hee



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Andy Smith
Hello,

On Tue, Feb 08, 2022 at 05:44:25PM +0100, Christian Britz wrote:
> On 2022-02-08 16:46 UTC+0100, Greg Wooledge wrote:
> > On Tue, Feb 08, 2022 at 03:46:09PM +0100, Christian Britz wrote:
> >> Is this to be done via systemd?
> > 
> > Yes, that's where you should be doing this.
> 
> That is what I thought of initially. And I think I am _almost_ there.
> The script works, after several hours of trial, errors and your and
> Dan's advice, when I manually execute it via systemctl. Start and stop
> works.
> 
> It still does not work during boot time, though:

Last time I was trying to make something start only after the
network was up I found I needed more than
Wants/After=network-online.target when using ifupdown. I wrote it up
here:


https://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/

Cheers,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Christian Britz



On 2022-02-08 17:44 UTC+0100, Christian Britz wrote:

> [Install]
> WantedBy=multiuser.target

Changed that to

[Install]
WantedBy=network-online.target

Now it works! :-)

-- 
http://www.cb-fraggle.de



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Greg Wooledge
On Tue, Feb 08, 2022 at 05:44:25PM +0100, Christian Britz wrote:
> On 2022-02-08 16:46 UTC+0100, Greg Wooledge wrote:
> > There's one thing in particular that you need to know first, and that's
> > how Debian defines interfaces for the purposes of determining that
> > "the network is available".  Assuming that you're using
> > /etc/network/interfaces (and not Network-Manager or some other thing)

> Yes, I need some more help in the context of using Network-Manager.

"Don't."

Unless this is a laptop or something, in which case, I'm just throwing
my hands up and stepping away.



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Christian Britz
On 2022-02-08 16:46 UTC+0100, Greg Wooledge wrote:
> On Tue, Feb 08, 2022 at 03:46:09PM +0100, Christian Britz wrote:
>> I want to know how I can execute a command as root once after the
>> network is available.
> 
>> Is this to be done via systemd?
> 
> Yes, that's where you should be doing this.

That is what I thought of initially. And I think I am _almost_ there.
The script works, after several hours of trial, errors and your and
Dan's advice, when I manually execute it via systemctl. Start and stop
works.

It still does not work during boot time, though:
Feb 08 17:34:53 amiga5000 usbip[1014]: usbip: error: tcp connect
Feb 08 17:34:53 amiga5000 systemd[1]: Starting usbip client service...
Feb 08 17:34:53 amiga5000 systemd[1]: usbip.service: Main process
exited, code=exited, status=1/FAILURE
Feb 08 17:34:53 amiga5000 systemd[1]: usbip.service: Failed with result
'exit-code'.
Feb 08 17:34:53 amiga5000 systemd[1]: Failed to start usbip client service.

I am almost sure I got the targets wrong. I _am_ actually using
Network-Manager. Here is my service file:

Unit]
Description=usbip client service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/usbip attach -r raspberrypi -b 1-1.4
RemainAfterExit=true
ExecStop=/usr/sbin/usbip detach -p 00
StandardOutput=journal

[Install]
WantedBy=multiuser.target

> 
> There's one thing in particular that you need to know first, and that's
> how Debian defines interfaces for the purposes of determining that
> "the network is available".  Assuming that you're using
> /etc/network/interfaces (and not Network-Manager or some other thing)
Yes, I need some more help in the context of using Network-Manager.

-- 
http://www.cb-fraggle.de



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Greg Wooledge
On Tue, Feb 08, 2022 at 03:46:09PM +0100, Christian Britz wrote:
> I want to know how I can execute a command as root once after the
> network is available.

> Is this to be done via systemd?

Yes, that's where you should be doing this.

There's one thing in particular that you need to know first, and that's
how Debian defines interfaces for the purposes of determining that
"the network is available".  Assuming that you're using
/etc/network/interfaces (and not Network-Manager or some other thing),
the interfaces that are maked as "auto" must be up, in order for Debian
to declare that the "network is available".

So, make sure your ethernet interface is marked as "auto" and NOT as
"allow-hotplug".

Once that's squared away, the rest is pretty straightforward.

Create a new systemd service (/etc/systemd/system/yourname.service),
and in the [Unit] section, make sure you've got this:

After=network-online.target

That's basically it.  Do the daemon-reload thing, then enable and start
the service, and if it works, reboot to really test it.



Re: Autostart command after network is available (usbip)

2022-02-08 Thread Dan Ritter
Christian Britz wrote: 
> I want to know how I can execute a command as root once after the
> network is available.
> 
> I activated usbipd on my home server and want to attach the client
> automatically at boot. Manually attaching it works already.
> 
> The command to be executed as root on the client is:
> usbip attach -r hostname -b n-n.n
> 
> Is this to be done via systemd? I was able to create a service on the
> server for the daemon, but failed to do so for the client.
> I also tried the root crontab using the @reboot timer, this failed
> probably because of the network is not available at execution time.

The normal methods for something that

- should run once
- as root
- after boot
- with a dependency on the network

would be:

- an init.d/ script with a dependency on network
- a systemd unit with a dependency on network
- an /etc/network/interfaces.d/ script run every time a
  particular interface is brought up (i.e. post-up).

-dsr-