Author Topic: Running a script prior to Myth Backend start  (Read 6963 times)

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Running a script prior to Myth Backend start
« 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

Murdock

  • Guru
  • ****
  • Posts: 229
    • View Profile
Re: Running a script prior to Myth Backend start
« 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.

Esperanto

  • Guru
  • ****
  • Posts: 281
    • View Profile
Re: Running a script prior to Myth Backend start
« 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: [Select]
# 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

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

Esperanto

  • Guru
  • ****
  • Posts: 281
    • View Profile
Re: Running a script prior to Myth Backend start
« 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.

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

l3mce

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1084
    • View Profile
Re: Running a script prior to Myth Backend start
« 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: [Select]
#!/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 ?
I never quit... I just ping out.

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

l3mce

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1084
    • View Profile
Re: Running a script prior to Myth Backend start
« 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?

I never quit... I just ping out.

fibres

  • Guru
  • ****
  • Posts: 306
    • View Profile
    • LinuxMCE 08.10 RC Mirror.
Re: Running a script prior to Myth Backend start
« 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

Esperanto

  • Guru
  • ****
  • Posts: 281
    • View Profile
Re: Running a script prior to Myth Backend start
« 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.

l3mce

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1084
    • View Profile
Re: Running a script prior to Myth Backend start
« 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.
I never quit... I just ping out.