Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #245098 > unrolled thread
| Started by | Christian Britz <cbritz@t-online.de> |
|---|---|
| First post | 2022-02-08 15:50 +0100 |
| Last post | 2022-02-09 13:00 +0100 |
| Articles | 10 — 6 participants |
Back to article view | Back to linux.debian.user
Autostart command after network is available (usbip) Christian Britz <cbritz@t-online.de> - 2022-02-08 15:50 +0100
Re: Autostart command after network is available (usbip) Dan Ritter <dsr@randomstring.org> - 2022-02-08 16:20 +0100
Re: Autostart command after network is available (usbip) Greg Wooledge <greg@wooledge.org> - 2022-02-08 16:50 +0100
Re: Autostart command after network is available (usbip) Christian Britz <cbritz@t-online.de> - 2022-02-08 17:50 +0100
Re: Autostart command after network is available (usbip) Greg Wooledge <greg@wooledge.org> - 2022-02-08 17:50 +0100
OT: Network-Manager Christian Britz <cbritz@t-online.de> - 2022-02-08 18:00 +0100
Re: Autostart command after network is available (usbip) Christian Britz <cbritz@t-online.de> - 2022-02-08 17:50 +0100
Re: Autostart command after network is available (usbip) Andrei POPESCU <andreimpopescu@gmail.com> - 2022-02-09 15:50 +0100
Re: Autostart command after network is available (usbip) Andy Smith <andy@strugglers.net> - 2022-02-09 07:10 +0100
Re: Autostart command after network is available (usbip) 황병희 <soyeomul@doraji.xyz> - 2022-02-09 13:00 +0100
| From | Christian Britz <cbritz@t-online.de> |
|---|---|
| Date | 2022-02-08 15:50 +0100 |
| Subject | Autostart command after network is available (usbip) |
| Message-ID | <DOzYB-pL9-7@gated-at.bofh.it> |
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. Please share your ideas. It is probably quite simple, I was very surprised that I could not find anything usefull on the web. Regards, Christian -- http://www.cb-fraggle.de
[toc] | [next] | [standalone]
| From | Dan Ritter <dsr@randomstring.org> |
|---|---|
| Date | 2022-02-08 16:20 +0100 |
| Message-ID | <DOArD-qaO-1@gated-at.bofh.it> |
| In reply to | #245098 |
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-
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-02-08 16:50 +0100 |
| Message-ID | <DOAUF-qrc-1@gated-at.bofh.it> |
| In reply to | #245098 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Christian Britz <cbritz@t-online.de> |
|---|---|
| Date | 2022-02-08 17:50 +0100 |
| Message-ID | <DOBQJ-r0F-1@gated-at.bofh.it> |
| In reply to | #245101 |
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
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-02-08 17:50 +0100 |
| Message-ID | <DOBQK-r0F-5@gated-at.bofh.it> |
| In reply to | #245102 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Christian Britz <cbritz@t-online.de> |
|---|---|
| Date | 2022-02-08 18:00 +0100 |
| Subject | OT: Network-Manager |
| Message-ID | <DOC0p-r3T-3@gated-at.bofh.it> |
| In reply to | #245103 |
On 2022-02-08 17:48 UTC+0100, Greg Wooledge wrote: > On Tue, Feb 08, 2022 at 05:44:25PM +0100, Christian Britz wrote: >> 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. Yes, the client is a laptop. Network-Manager seems to be the default solution choosen by the Debian installer. I don't have problems with changing interface names or something, are there more reasons to avoid it on a desktop (KDE Plasma in my case)? Before you step away, please take notice that you helped me a lot. ;-) -- http://www.cb-fraggle.de
[toc] | [prev] | [next] | [standalone]
| From | Christian Britz <cbritz@t-online.de> |
|---|---|
| Date | 2022-02-08 17:50 +0100 |
| Message-ID | <DOBQK-r0F-9@gated-at.bofh.it> |
| In reply to | #245102 |
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
[toc] | [prev] | [next] | [standalone]
| From | Andrei POPESCU <andreimpopescu@gmail.com> |
|---|---|
| Date | 2022-02-09 15:50 +0100 |
| Message-ID | <DOWsb-DJU-15@gated-at.bofh.it> |
| In reply to | #245104 |
[Multipart message — attachments visible in raw view] — view raw
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
[toc] | [prev] | [next] | [standalone]
| From | Andy Smith <andy@strugglers.net> |
|---|---|
| Date | 2022-02-09 07:10 +0100 |
| Message-ID | <DOOkV-z0R-1@gated-at.bofh.it> |
| In reply to | #245102 |
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
[toc] | [prev] | [next] | [standalone]
| From | 황병희 <soyeomul@doraji.xyz> |
|---|---|
| Date | 2022-02-09 13:00 +0100 |
| Message-ID | <DOTND-C6g-3@gated-at.bofh.it> |
| In reply to | #245123 |
Andy Smith <andy@strugglers.net> 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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web