Subscribe

run as root, hose your repository

  1. 2007-06-04 09:35:56 PDT
    I ran apt-mirror as root to do the initial mirroring. Then I enabled the cron job. Apparently, it was failing, even though the log file (/var/spool/apt-mirror/var/cron.log) showed no error messages. The reason is that the cron job runs as user apt-mirror, and by running it initially as root, its repository files were owned by root. Then the process started by cron could not overwrite necessary files.

    There are two problems here. First, an ordinary execution creates a bad situation without warning. Second, there are no error messages being recorded even though the subsequent mirror attempts were failing.

    Let me suggest two fixes.

    1) Refuse to run as root, or switch effective user ID to "apt-mirror".

    2) Change the default cron entry so that error messages are recorded.

    0 1 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log 2>&1

    --- /usr/bin/apt-mirror 2006-09-08 06:39:41.000000000 -0700
    +++ apt-mirror 2007-06-04 09:27:56.000000000 -0700
    @@ -94,6 +94,24 @@


    ######################################################################################
    +## Ensure we don't run as root
    +
    +unless ($>) {
    + my @aptmirrornam = getpwnam "apt-mirror";
    + if (@aptmirrornam == 0) {
    + die "apt-mirror: this program should not be run as root\nuse \"su - USERNAME -c apt-mirror\" or similar\n";
    + }
    + $> = $aptmirrornam[2];
    + if ($!) {
    + die "apt-mirror: unable to set effective user id to $aptmirrornam[2] (apt-mirror): $!\n";
    + }
    + $) = $aptmirrornam[3];
    + if ($!) {
    + die "apt-mirror: unable to set effective group id to $aptmirrornam[3]: $!\n";
    + }
    +}
    +
    +######################################################################################
    ## Setting up $config_file variable

    $config_file = "/etc/apt/mirror.list"; # Default value
  2. nobody

    2007-06-20 00:25:44 PDT
    Joshua,

    As far as I understand, you should not redirect STDERR to log file in cron job because by default all output to STDERR (and to STDOUT too) will be emailed to root@localhost so he or she can receive error messages from apt-mirror.

    As for first suggestion, you may continuously run apt-mirror as root w/o any error.

    Ken.
  3. nobody

    2007-11-30 14:51:03 PST
    what about just chown'ing the /var/spool/apt-mirror/mirror/[repository] folder to apt-mirror:apt-mirror? Will that break things?
  4. nobody

    2007-12-14 12:13:07 PST
    Chown'ing doesn't break it. Tried and it works. :-)
Jump To:
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.