[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Daemons in schroot or how to start chroot automatically



Ramon Hofer wrote:
> Installed sid
> $ sudo debootstrap sid /srv/chroot/sid/ http://ftp.ch.debian.org/debian/

I haven't submitted a bug yet but I always have problems with sysvinit
postinst depending upon ischroot and ischroot getting it wrong and
that leaving a broken /run - /var/run behind.  You might hit that too.

You should set up a usr/sbin/policy-rc.d script in your chroot.
Something like this:

  #!/bin/sh
  exit 101

That will prevent installations from starting daemons in the chroot.
Or if there is a daemon that you wish to start in the chroot then you
could use a script such as this:

  #!/bin/sh
  # /usr/sbin/policy-rc.d [options] <initscript ID> <actions>
  # [<runlevel>]
  # /usr/sbin/policy-rc.d [options] --list <initscript ID> [<runlevel>
  # ...]
  # See /usr/share/doc/sysv-rc/README.policy-rc.d for documentation.
  # Live example found in ps:
  #   /bin/sh /usr/sbin/policy-rc.d x11-common stop unknown
  while [ $# -gt 0 ]; do
      case $1 in
          --list) exit 101 ;;
          --quiet) shift ;;
          -*) shift ;;
          cron) exit 0 ;;
          nullmailer) exit 0 ;;
          *) exit 101 ;;
      esac
  done
  exit 101

See /usr/share/doc/sysv-rc/README.policy-rc.d.gz for documentation.

> Entered the chroot with
> $ sudo schroot -p -c sid
> 
> Installed locales and reconfigured them. I also installed vim.

Seems reasonable so far.  Some packages will require /proc.  Some will
also require /dev.  Some will require other things.

> I noticed that auto-completion isn't working.
> What packages should I install? Is auto-complete-el sufficient or is 
> there a meta package for some base system packages?

  apt-get install bash-completion

> In the chroot I have created a new user called hoferr and am now able to 
> login without root privilieges.
> But in there sudo is missing. Maybe this can be resolved by installing 
> the correct base system meta package mentioned above?

  apt-get install sudo

> Aside some missing packages everything looks promising.

The premise of debootstrap is that it installs a very small system.
If you want something installed you are going to need to install it
yourself.

Perhaps you should consider using 'tasksel' to install a standard task
set of packages.  That would pull in a lot.  I prefer the small system
and only install what I need to install.  But if you don't like that
then you may always install a larger set all at once.

> To get back to my main reason of doing this: After stopping the "old" 
> sabnzbdplus can I just install the chroot sabnzbplus with the "normal" 
> home partition mounted?

Yes.

> It will probably start automatically when the chroot is started

Wait!  Hold it right there.  What do you mean "when the chroot is
started"?  Unless you are doing something "magical" there isn't
anything that "starts a chroot".  I think right here there is a huge
misunderstanding of chroots.  If you want a particular daemon to start
in the chroot then you will need to ensure that it is started.

> and I should be able to access its web service from the LAN.

Yes.

> But how can I start the chroot on bootup automatically. i probably just 
> have to write a init.d script and do a update.rc.

Yes.  By creating an init script.

> Is this enough as init.d script?
> http://pastebin.com/raw.php?i=hHSvG30v

No.  That has a misunderstanding about this part:

  start)
    echo "Starting chroot sid"
    schroot -c sid

But that would simply start an interactive shell there.  That isn't
what you want at all.

> Or should I use the skeleton?

Yes.  Please copy the skeleton and use it.

> And should I then just create a DAEMON script in /usr/sbin with the 
> following content?
> 
> #! /bin/sh
> schroot -c sid

No.  That isn't what you want.

> If yes what are the Required-Start/Stop variables?

I would use the same header as in the original script.

For example I run 'nullmailer' in the chroot.  Therefore I create an
initscript like this following.  And I install it using update-rc.d.
Copy it to /etc/init.d/chroot-nullmailer and then install it with:

  update-rc.d chroot-nullmailer defaults

In a chroot I usually run nullmailer and cron plus whatever else I
wanted the chroot for, such as apache.

Also there are a zillion other ways to do it too.  This is just one
way.

Bob

#! /bin/sh
# nullmailer    start/stop the nullmailer deamon in chroot
#
### BEGIN INIT INFO
# Provides:          chrootnullmailer
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
#
#		Written by Bob Proulx <bob@proulx.com>
#
# update-rc.d chroot-nullmailer defaults

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nullmailer
CHROOTS="sid"

set -e

for ROOT in $CHROOTS ; do
  rootdir=/srv/chroot/$ROOT
  case $1 in
    start)
      chroot  $rootdir /etc/init.d/$NAME start
      ;;
    stop)
      chroot  $rootdir /etc/init.d/$NAME stop
      ;;
    reload)
      chroot  $rootdir /etc/init.d/$NAME reload
      ;;
    restart)
      chroot  $rootdir /etc/init.d/$NAME restart
      ;;
    force-reload)
      chroot  $rootdir /etc/init.d/$NAME force-reload
      ;;
    *)
      N=/etc/init.d/$NAME
      echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
      exit 1
      ;;
  esac
done

exit 0

Attachment: signature.asc
Description: Digital signature


Reply to: