LinuxMCE Forums
May 20, 2013, 02:36:59 am GMT-1 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Rule #1 - Be Patient - Rule #2 - Don't ask when, if you don't contribute - Rule #3 - You have coding skills - LinuxMCE's small brother is available: http://www.agocontrol.com
 
   Home   Help Search Chat Login Register  
Pages: [1]
  Print  
Author Topic: Running a script prior to Myth Backend start  (Read 624 times)
fibres
Guru
****
Posts: 306


View Profile WWW
« on: January 22, 2012, 09:07:14 pm »

Hi Guys

I am trying to get a script to run to load a couple of programs before MythBackEnd loads on my core.

Can anyone give an easy way to fire off a script that will complete before mythbackend is loaded.

Regards
Logged
Murdock
Guru
****
Posts: 229



View Profile
« Reply #1 on: January 23, 2012, 01:55:27 am »

as always, be super careful, but the easiest way to do that is to insert your script:
/etc/rc5.d/S90<script_name>

As that will fire prior to MCE and subsequently called programs.
Logged
Esperanto
Veteran
***
Posts: 107


View Profile
« Reply #2 on: January 23, 2012, 03:26:02 pm »

Create a script in /etc/init/

On the exec line you put the command you want to run.

Code:
# sasc-ng service

description     "sasc-ng"
author          "espe"

start on starting mythtv-backend
stop on starting shutdown

respawn

pre-start script
        rm -rf /usr/local/etc/ecm.cache
        echo `date +%s` > /tmp/MythTvInitialFillDBRun
        echo `date` "sasc init" >> /tmp/sasc-start
        sleep 8s

        insmod /root/sc/contrib/sasc-ng/dvbloopback.ko num_adapters=2
        sleep 2s

end script

exec   /root/sc/contrib/sasc-ng/sasc-ng -j 0:2 -j 1:3  --cam-budget --cam-dir /usr/local/etc/ --sid-filt 12 --sid-allpid --sid-nocache --buffer 8M --pidfile /var/run/sasc-ng.pid --log /var/log/sasc-ng.log

post-start script
        echo `date` "sasc init post pre sleep" >> /tmp/sasc-start
end script

post-stop script
        rmmod dvbloopback
end script
Logged
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #3 on: January 23, 2012, 10:54:10 pm »

Hi Esperanto

Thanks for that.

Can I add an exec line before that to execute a program first with a quick sleep inbetween?

Also how do I make the system run that script?

Regards
Logged
Esperanto
Veteran
***
Posts: 107


View Profile
« Reply #4 on: January 24, 2012, 08:33:37 pm »

Can I add an exec line before that to execute a program first with a quick sleep inbetween?
as you can see I do the same in the pre-script code. just replace that with the items you want done before. the same applies for the post script (or remove it).

Also how do I make the system run that script?
it get's run automatically before mythtv-backend gets started. that's what the 'start on starting mythtv-backend' line is all about.
Logged
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #5 on: January 24, 2012, 11:18:07 pm »

Hi Esperanto.

I have sussed the script and made the changes I need.

I have put it into /etc/init called sasc.conf and rebooted but it does not load.

Do I need to run anything to make it reload the init config?

Regards
Logged
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #6 on: January 24, 2012, 11:48:38 pm »

Ignore that. I had to make a few changes.

I had to change insmod to modprobe

Regards
Logged
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #7 on: January 24, 2012, 11:57:25 pm »

Hi Esperanto

Ok thought I had is sussed. Script is running but for some reason it is not running before mythtv-backend.

For some reason mythtv is running first and is therefore not picking up the adapters.

Regards
Logged
l3mce
NEEDS to work for LinuxMCE
***
Posts: 1031



View Profile
« Reply #8 on: January 25, 2012, 05:07:50 pm »

Not to be a complete dork... but couldn't you just add your scripts to the beginning of the upstart job /etc/init.d/mythtv-backend ?

So... like
Code:
#!/bin/sh -e
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.
. /path/to/script.sh
. /path/to/second/script.pl
set -e

INITSCRIPT="$(basename "$0")"
JOB="${INITSCRIPT%.sh}"

etc ?
Logged

I never quit... I just ping out.
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #9 on: January 26, 2012, 12:08:12 am »

Hi L3mce

I am not overly familir with linux boot scripts. Would the above script be able to be called from the mythtv-backend in the way you suggest.

As in is i put the above script from Esperanto into /usr/bin/script.sh and call it as per your example would it work?

Regards
Logged
l3mce
NEEDS to work for LinuxMCE
***
Posts: 1031



View Profile
« Reply #10 on: January 26, 2012, 01:02:18 am »

I expect it to. Give it a whirl.

One question though... does this script do X and then exit? Or does it persist?

Logged

I never quit... I just ping out.
fibres
Guru
****
Posts: 306


View Profile WWW
« Reply #11 on: January 26, 2012, 11:17:13 am »

How do I tell that?

I didn't get your post till late last night so decided not to play around, as I have a tendency to then end up tinkering for hours and being dead in work the next day! At least I'm the boss so only get a telling off from myself!

Regards
Logged
Esperanto
Veteran
***
Posts: 107


View Profile
« Reply #12 on: January 26, 2012, 01:34:40 pm »

Don't hack into existing scripts if it is not necessary. That's the nice thing about upstart that you can put a script before something else without touching it.

As you can see in my script I have also some sleeps etc. Actually I cleaned it up a bit and there was also a 'sleep 30s' in the post-start script to be sure that the adapters are up and running before mythtv-backend get's started. That will do the trick.
Logged
l3mce
NEEDS to work for LinuxMCE
***
Posts: 1031



View Profile
« Reply #13 on: January 26, 2012, 04:29:42 pm »

Don't hack into existing scripts if it is not necessary. That's the nice thing about upstart that you can put a script before something else without touching it.

As you can see in my script I have also some sleeps etc. Actually I cleaned it up a bit and there was also a 'sleep 30s' in the post-start script to be sure that the adapters are up and running before mythtv-backend get's started. That will do the trick.

Esperanto is surely correct that this is a poor way to handle it. I have a tendency to butcher things for my immediate needs. It is a bad practice. Especially for someone with terrible memory... as once I restore some image, or do some upgrade it erases what I forgot I had broken to make work... so follow their advice over mine.
Logged

I never quit... I just ping out.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!