Running a script after a specific daemon service is started
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Running a script after a specific daemon service is started
I have a Raspberry Pi that I configured as my torrenting box, currently running openvpn as a service and deluged, both are started at boot time, with deluged starting after openvpn.
I have 2 scripts that I want run to configure the port forwarding for the connection:
- One script was provided by the VPN provider, which returns a JSON string with the port number. I modified this script to pass it through jq, and dumps the port number into a temp file in /tmp.
- Another script I have runs 2 commands for deluge-console, to update the listen_ports and disable random_ports parameters.
First script I can put it in up.sh in openvpn as they suggested, but I'm trying to figure out the right place to put the second one. Basically I want this to run after the deluged is started.
how are you getting deluge to start at boot?
if within a init script then call it on the last line in that (deluge) script. you could put a loop in that second script that will keep checking to insure that deluge has started, then if true then start whatever you have starting in the second script. leave loop.
Code:
while (true)
do
[[ $(pgrep deluge | wc -l) == '1' ]] && (
echo "deluge on"
break
)
done
how are you getting deluge to start at boot?
if within a init script then call it on the last line in that (deluge) script. you could put a loop in that second script that will keep checking to insure that deluge has started, then if true then start whatever you have starting in the second script. leave loop.
Code:
while (true)
do
[[ $(pgrep deluge | wc -l) == '1' ]] && (
echo "deluge on"
break
)
done
results
deluge on
It's part of init.d. Although I just found out somehow deluged is on S01deluged but openvpn is S02openvpn. Tried update-rc.d a few times and it's still on S01...
I am not familiar with PI but it is Linux.
Your using init.d which is a directory, yes?
it has scripts that will get ran on start up of system. so just created a different script using that loop within it. put it in init.d it should in theory just keep running until it gets a return=0 on deluge PID
all that loop is doing is keeping the if statement checking for is deluge PID until it gets a return=0
you can mod that to fit whatever name deluge uses as a daemon. to get your return=0 then try running whatever code you need to do whatever you need to do with deluge.
even try using a wildcard * to match it *deluge* so if it is S01deluged the 'deluge' is within it. then you'll get your return=0
try it first if not working post back results.
Question. You are using a separate script within init.d to start deluge yes:no?
if yes you still can place the name of that script (whatever you name it) at the bottom of the deluge script - this way deluge is started first then the other script is called to make changes afterwords.
It may need to wait before it attempts to make these changes. After your system has completely booted up and perhaps even logged into before any changes to deluge can be attempted to be made even. Again I am not familiar with PI. So whatever little differences their is I have no idea what they are.
This is where you come in to use your knowledge and apply it to this scenario.
I am not familiar with PI but it is Linux.
Your using init.d which is a directory, yes?
it has scripts that will get ran on start up of system. so just created a different script using that loop within it. put it in init.d it should in theory just keep running until it gets a return=0 on deluge PID
all that loop is doing is keeping the if statement checking for is deluge PID until it gets a return=0
you can mod that to fit whatever name deluge uses as a daemon. to get your return=0 then try running whatever code you need to do whatever you need to do with deluge.
even try using a wildcard * to match it *deluge* so if it is S01deluged the 'deluge' is within it. then you'll get your return=0
try it first if not working post back results.
Question. You are using a separate script within init.d to start deluge yes:no?
if yes you still can place the name of that script (whatever you name it) at the bottom of the deluge script - this way deluge is started first then the other script is called to make changes afterwords.
It may need to wait before it attempts to make these changes. After your system has completely booted up and perhaps even logged into before any changes to deluge can be attempted to be made even. Again I am not familiar with PI. So whatever little differences their is I have no idea what they are.
This is where you come in to use your knowledge and apply it to this scenario.
Should've been clearer, I'm actually running Raspbian Jessie on it.
I was under the impression that since it's S01deluged, S02openvpn, that means it'll run deluged first then openvpn? Higher the number, later the start?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.