View previous topic :: View next topic |
Author |
Message |
LIsLinuxIsSogood Veteran
Joined: 13 Feb 2016 Posts: 1179
|
Posted: Fri Feb 09, 2018 10:29 am Post subject: Best way to delay a service under OpenRC (SOLVED) |
|
|
Hi, I was wondering what the recommended way to have a specific service wait for the use of another service under OpenRC... basically I want to use my network connection (network manager) as the triggering situation for another service (MPD server) to run. this is because I want a headless server that will only play when it is connected to the internet.
How might I do this? Does it involve programming any runlevels?
I could look again to see if the software MPD has anything that I am missing in terms of this functionality (of waiting for network connectvity).
Any suggestions?
Last edited by LIsLinuxIsSogood on Mon Feb 12, 2018 7:29 am; edited 1 time in total |
|
Back to top |
|
|
massimo Veteran
Joined: 22 Jun 2003 Posts: 1226
|
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3922 Location: Hamburg
|
Posted: Fri Feb 09, 2018 12:14 pm Post subject: |
|
|
remark: for DHCP (well, it is a server) however the config of DHCP should be configured to return "ok" after an IP address was leased, not immediately after starting to request it. |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Fri Feb 09, 2018 5:12 pm Post subject: |
|
|
What about a cron job that starts every minute, checks the network connection and start or stops your MPD server if required. |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Fri Feb 09, 2018 7:40 pm Post subject: |
|
|
You can make an initscript that test network and wait for answer, and make mpd depends on it.
Code: | #!/sbin/openrc-run
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
depend() {
need net
}
ping_check() {
ping -c1 google.com >/dev/null
rc=$?
}
start() {
ping_check;
while [ ${rc} -ne 0 ]; do
sleep 60
ping_check;
done;
return 0
}
|
|
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21624
|
Posted: Sat Feb 10, 2018 12:47 am Post subject: |
|
|
mike155 wrote: | What about a cron job that starts every minute, checks the network connection and start or stops your MPD server if required. | While that could work, if you want to go the inefficient polling route, why not go all out? Instead of a cron job that runs once a minute, use a job that spins the CPU polling continuously to see if the system is in the right state.
On a more serious note, this seems like an ideal use case for the DHCP client notification hooks. If you use dhcpcd to acquire/release addresses, it has hooks that seem like they should work. See man dhcpcd section Hooking into events. If you use some other software to acquire addresses, you should consult its documentation to see if it has equivalent capabilities. |
|
Back to top |
|
|
LIsLinuxIsSogood Veteran
Joined: 13 Feb 2016 Posts: 1179
|
Posted: Sun Feb 11, 2018 8:57 pm Post subject: |
|
|
Network manager, not sure if that makes this a bit more challenging or not? But I would like to try with the the approach mentioned of using a hook for the networking event, as Hu's solution mentioned. However, based on the specific tool used for acquiring addresses from the dhcp server I am not sure where to begin.
I did find this, by checking online... https://superuser.com/questions/114099/add-a-hook-to-run-when-networkmanager-connects
Does that sound correct?
Thanks for the other suggestions, as my post said about OpenRC script, so that I may have not been completely thorough in weighing the possible solutions and thanks to Hu for helping to point me back towards the most basic of solutions that makes use of the system network events.
I read all the other solutions, including krinn's init script which is cool, I like it. however I am afraid it may not suffice but not because of anything in there. Just because the problem isn't as well defined yet, and that could be due to my not having tried other possible solutions at this time.
Thank you all for the help! |
|
Back to top |
|
|
geki Advocate
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Sun Feb 11, 2018 9:29 pm Post subject: |
|
|
NetworkManager can use dhcpcd as backend. Then, you could use dhcpcd hooks, I guess. _________________ hear hear |
|
Back to top |
|
|
LIsLinuxIsSogood Veteran
Joined: 13 Feb 2016 Posts: 1179
|
Posted: Sun Feb 11, 2018 9:49 pm Post subject: |
|
|
How to set that up? |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Sun Feb 11, 2018 11:40 pm Post subject: |
|
|
The hooks for network manager or dhcpcd are pretty similar, I've used both in the past. (My computer at work uses network manager, my home machines don't.) One advantage of using the network manager hooks is that you can trigger off of a VPN as well as a hardware interface. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
LIsLinuxIsSogood Veteran
Joined: 13 Feb 2016 Posts: 1179
|
Posted: Mon Feb 12, 2018 7:28 am Post subject: |
|
|
Solved. Worked great hooking in to the network service providing the extra benefit of specifying the interface as well!!
Thanks |
|
Back to top |
|
|
|