Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Best way to delay a service under OpenRC (SOLVED)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1179

PostPosted: Fri Feb 09, 2018 10:29 am    Post subject: Best way to delay a service under OpenRC (SOLVED) Reply with quote

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
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1226

PostPosted: Fri Feb 09, 2018 11:03 am    Post subject: Reply with quote

You're probably looking for https://wiki.gentoo.org/wiki/OpenRC#Dependency_behavior .
_________________
Hello 911? How are you?
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Fri Feb 09, 2018 12:14 pm    Post subject: Reply with quote

massimo wrote:
You're probably looking for https://wiki.gentoo.org/wiki/OpenRC#Dependency_behavior .
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
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Fri Feb 09, 2018 5:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Fri Feb 09, 2018 7:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21624

PostPosted: Sat Feb 10, 2018 12:47 am    Post subject: Reply with quote

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
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1179

PostPosted: Sun Feb 11, 2018 8:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
geki
Advocate
Advocate


Joined: 13 May 2004
Posts: 2387
Location: Germania

PostPosted: Sun Feb 11, 2018 9:29 pm    Post subject: Reply with quote

NetworkManager can use dhcpcd as backend. Then, you could use dhcpcd hooks, I guess.
_________________
hear hear
Back to top
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1179

PostPosted: Sun Feb 11, 2018 9:49 pm    Post subject: Reply with quote

How to set that up?
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3509

PostPosted: Sun Feb 11, 2018 11:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
LIsLinuxIsSogood
Veteran
Veteran


Joined: 13 Feb 2016
Posts: 1179

PostPosted: Mon Feb 12, 2018 7:28 am    Post subject: Reply with quote

Solved. Worked great hooking in to the network service providing the extra benefit of specifying the interface as well!!

Thanks :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum