LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 05-13-2017, 05:15 PM   #1
ToniCipriani
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Rep: Reputation: 0
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.

Thoughts?
 
Old 05-13-2017, 05:43 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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

Last edited by BW-userx; 05-13-2017 at 05:49 PM.
 
Old 05-13-2017, 09:07 PM   #3
ToniCipriani
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by BW-userx View Post
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...
 
Old 05-14-2017, 02:43 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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.

Last edited by BW-userx; 05-14-2017 at 02:48 PM.
 
Old 05-17-2017, 10:04 PM   #5
ToniCipriani
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by BW-userx View Post
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?
 
Old 05-18-2017, 02:35 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,510

Rep: Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552
yes, S01 executed (started) before S02
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running service command as root in a daemon on RHEL 6.5 linuxuser26 Red Hat 2 09-12-2014 11:22 AM
How to create a script that kills all processes started by a specific user? Squerl101 Linux - General 12 02-19-2013 07:09 AM
[SOLVED] write a shell script so that it can run as service/daemon deostroll Programming 10 03-08-2010 10:03 AM
Configuring Shell Script as service/daemon nkanthikiran Red Hat 2 11-07-2006 05:50 AM
Daemon started but NOT running with lpc status??? Ruth Linux - General 1 03-12-2001 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration