How to auto start service in the Debian chroot environment?

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

How to auto start service in the Debian chroot environment?

Post by pvdveen » Sun Jan 08, 2012 1:02 pm

Hi

I have made the chroot debian environment available on my NAS and installed the logitech media server in it.

It works perfect.

The only thing is that when i restart my nas in need to start the server by hand using /etc/init.d/logitechmediaserver start

Is there a way to autostart that service as the nas in starting?

Anybody an idea how to accomplish that?

Peter


pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Mon Jan 09, 2012 7:07 pm

Hi

No its not in the NAS it self, but in the debian chroot i installed next to it

http://lacie.nas-central.org/wiki/Categ ... nvironment

Now i open Putty, login to the NAS then put the command squeeze

i come in a new linux shell and there i put the command /etc/init.d/logitechmediaserver start

Peter

Mijzelf
Posts: 6207
Joined: Mon Jun 16, 2008 10:45 am

Re: How to auto start service in the Debian chroot environme

Post by Mijzelf » Mon Jan 09, 2012 7:19 pm

I see. What does the 'squeeze' command exactly do? Can you post the script here?

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Thu Jan 12, 2012 6:34 am

Hi

Tried to find the script, but not sure where i can find that script.

Is there an easy way to find files with such a name?

Peter

Mijzelf
Posts: 6207
Joined: Mon Jun 16, 2008 10:45 am

Re: How to auto start service in the Debian chroot environme

Post by Mijzelf » Thu Jan 12, 2012 9:01 am

execute
which squeeze

andreus
Posts: 134
Joined: Wed Dec 16, 2009 9:57 pm

Re: How to auto start service in the Debian chroot environme

Post by andreus » Thu Jan 12, 2012 7:48 pm

See in the file /root/.profile

Something like this...

Code: Select all

 function mount4squeeze () {
         mount proc /debian-squeeze/proc -t proc 2>/dev/null && \
         mount sys /debian-squeeze/sys -t sysfs
         # mount udev /debian-squeeze/dev -t tmpfs && \
         mount usbfs /debian-squeeze/proc/bus/usb -t usbfs 2>/dev/null
         # mkdir /debian-squeeze/dev/pts 2>/dev/null
         # mount -vt devpts -o gid=4,mode=620 none /debian-squeeze/dev/pts -t devpts 2
         mount -t none /dev /debian-squeeze/dev -o bind
         mount /dev/seb1 /debian-squeeze/usbkey/ 2>/dev/null
         mount /dev/sda2 /debian-squeeze/sda2/ 2>/dev/null
 }
 function umount4squeeze () {
         umount /debian-squeeze/sda2/ 2>/dev/null
         umount /debian-squeeze/usbkey/ 2>/dev/null
         umount /debian-squeeze/dev 2>/dev/null
         umount /debian-squeeze/proc/bus/usb 2>/dev/null
         umount /debian-squeeze/sys 2>/dev/null
         umount /debian-squeeze/proc 2>/dev/null
 }
alias squeeze='mount4squeeze ; chroot /debian-squeeze /bin/bash ; umount4squeeze'

Mijzelf
Posts: 6207
Joined: Mon Jun 16, 2008 10:45 am

Re: How to auto start service in the Debian chroot environme

Post by Mijzelf » Thu Jan 12, 2012 9:05 pm

Oh? That means that as soon as you leave the chrooted shell, the mounts are undone (as far as they aren't busy). So a service started in that shell could fail out of the blue, when it needs something from /proc, or something like that.

@pvdveen: A script like this might work:

Code: Select all

#!/bin/sh

. /root/.profile

case $1 in
      start) 
              mount4squeeze
              chroot /debian-squeeze /etc/init.d/logitechmediaserver start
              ;;
      stop)
              chroot /debian-squeeze /etc/init.d/logitechmediaserver stop
              umount4squeeze
              ;;
esac
Put it in /etc/init.d/squeeze.sh, and make it executable. Test it.

Then create a file /etc/initng/squeeze.i:

Code: Select all

#!/sbin/itype
# This is a i file, used by initng parsed by install_service

service squeeze {
need = mountuserfs;
   script start = {
        /etc/init.d/squeeze.sh start
       exit 0
   };

   script stop = {
        /etc/init.d/squeeze.sh start
       exit 0
   };
}
Add squeeze to /etc/initng/runlevel/default.runlevel

Even better would be not to use 'chroot /debian-squeeze /etc/init.d/logitechmediaserver start & stop' but
'chroot /debian-squeeze /etc/init.d/rc 2 & 1' and use the Debian runlevel management to control which services to start.

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Thu Jan 12, 2012 9:26 pm

thx all

wil try it tomorrow

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Fri Jan 13, 2012 1:40 pm

Hi

I managed to get it work with the above scripts :)
When my NAS is rebooting it starts the Logitech Media server too.

I only had to do one modification, instead of mountuserfs i needed to use samba-bind as this mount the shares it needed.

Thanks for all the advise!

Peter

Code: Select all

#!/sbin/itype
# This is a i file, used by initng parsed by install_service

service squeeze {
need = samba-bind;
   script start = {
        /etc/init.d/squeeze.sh start
       exit 0
   };

   script stop = {
        /etc/init.d/squeeze.sh stop
       exit 0
   };
}
Last edited by pvdveen on Sun Jan 15, 2012 10:42 am, edited 1 time in total.

andreus
Posts: 134
Joined: Wed Dec 16, 2009 9:57 pm

Re: How to auto start service in the Debian chroot environme

Post by andreus » Fri Jan 13, 2012 2:07 pm

Cool. Nice job!

If you have time, that would be a great improvement to the wiki.
http://lacie.nas-central.org/wiki/Categ ... nvironment

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Sat Jan 14, 2012 10:10 am

yes of course :)

Although today i came across something else.

I had put the NAS into deep-sleep.
This morning i let it woke-up by the squeezebox, but no mediaserver.
Looking with putty is saw some shares where not there (the shares for the Debian squeeze)
At the command prompt i typed 'reboot' and after the reboot the shares were present and the mediaserver was running.

To test it again i put the NAS in deep-sleep through the web access and let it wake-up again.
Same result.
After a reboot from the command prompt it was working.

So there is something different going on from a deep-sleep or a reboot.

Any ideas?

Peter

Mijzelf
Posts: 6207
Joined: Mon Jun 16, 2008 10:45 am

Re: How to auto start service in the Debian chroot environme

Post by Mijzelf » Sat Jan 14, 2012 12:03 pm

I think the 'deep sleep' is actually a reboot, where during the boot process the box is set in a low-power mode. More info here:
viewtopic.php?f=236&t=5009

This will have timing consequences when the box wakes up. For instance normally the disk is spinning when Linux boots, now the disk is in standby when it comes out of deep sleep, with the kernel already booted.

Assuming that squeeze.i is called, you could try a simple work-around in /etc/init.d/squeeze.sh:

Code: Select all

case $1 in
      start) 
              mount4squeeze
              if cat /proc/mounts | grep /debian-squeeze/sda2/
              then 
                  chroot /debian-squeeze /etc/init.d/logitechmediaserver start
              else
                  reboot
              fi
              ;;
For the grep have a look which mount is actually missing.

pvdveen
Posts: 21
Joined: Sat Dec 17, 2011 11:02 am

Re: How to auto start service in the Debian chroot environme

Post by pvdveen » Sun Jan 15, 2012 10:57 am

Mmm

not working.

It puts the NAS in an endless loop of rebooting.

I managed to get it repaired by quickly enter the command the rename the squeeze.i file just when the command prompt got available :)

Will have a better look at it later.

Mijzelf
Posts: 6207
Joined: Mon Jun 16, 2008 10:45 am

Re: How to auto start service in the Debian chroot environme

Post by Mijzelf » Sun Jan 15, 2012 6:55 pm

pvdveen wrote:It puts the NAS in an endless loop of rebooting.

I managed to get it repaired by quickly enter the command the rename the squeeze.i file just when the command prompt got available :)
Really? I suppose you don't have a long password then.
Will have a better look at it later.
Maybe you should first do a 'cat /proc/mounts >/tmp/mounts' to find out what is actually mounted at that moment.

Post Reply