multiple instances of the same script?

paul phsdv at tiscali.fr
Sat Mar 10 18:35:42 GMT 2007


Scott James Remnant wrote:
> On Sat, 2007-03-10 at 14:32 -0300, Hervé Fache wrote:
>
>   
>> Probably nothing new, but I suppose this means that partition(s)
>> checking needs be done one by one by whatever script is called when a
>> new drive is detected?
>>
>> Paul said upstart received an event for the drive and not for each
>> partition, so that would make things just work with the current
>> upstart I suppose. 
>>
>>     
> Upstart receives whatever events you send it; block device events come
> from udev, so it's up to the sysadmin/distro maintainer how they do it.
>
>   
>> I am not an expert, so I wouldn't want to waste your time conjecturing
>> on this list though...
>>
>>     
> It's not a waste of time at all, needs to be solved so it's entirely
> profitable :p
>
> One way certainly would be to only react to drive events, and then have
> something like this:
>
> 	instance
> 	start on block-device-added *[!0-9]
>
> 	script
> 	    for partition in /sys$DEVPATH/$1[0-9]*
> 	    do
> 		NAME=${partition##*/}
> 		initctl emit partition-added ${partition##*/} \
> 			-eDEVPATH=${partition%/sys}
> 	    done
> 	end script
>
> Then for each partition you could do:
>
> 	instance
> 	start on partition-added
>
> 	exec /sbin/fsck "$1"
>
> Each call to "initctl emit" will automatically block until the fsck is
> complete; thus providing serial events for partitions.
>
> Scott
>   
This is an elegant solution. What I was thinking of the following ( I 
deal with root separately):

      start on block-device-added

      instance

      console output
      script
         blockdev=$DEVNAME
         blockdevlen=${#blockdev}

         echo "DEBUG FS-CHECK : $1"
         rootpart=`getmntent -f -N -d /`      # get partition root is 
mounted on
 
         # get list of all partitions and only check partions that are 
on this block device! And not /
         for partition in `getmntent -f -N` ;
         do
            if [[ ${partition} != ${rootpart} ]] # only if not root
            then
               if [[ ${partition:0:$blockdevlen} == ${blockdev} ]] # if 
this partion is on this block!
               then
                  echo "DEBUG FS_CHECK: FSCK: " $partition
                  fsck -C -T -a "$partition"
                  emit fs-checked "$partition"
               fi
            fi
         done
      end script

And with the following udev rule:
        ACTION=="add",    SUBSYSTEM=="block", KERNEL=="*[!0-9]", 
RUN="/usr/sbin/initctl emit block-device-added %k -eDEVNAME"

When I run this I get the following events ( / on /dev/xvda other 
partition on /dev/xvdb):

    Freeing unused kernel memory: 164k freed
    populating /dev with existing devices through uevents ...
    started mount-kernel-filesystems
    starting udev
    started udev
    starting modules
    starting udevtrigger
    starting tty1
    started modules
    started udevtrigger
    started tty1
    Letting udev process events
    DEBUG FS-CHECK : xvdb
    block-device-added xvdb
        DEVNAME=/dev/xvdb
    starting fs-check-root
    starting fs-check
    started fs-check-root
    started fs-check
    stopping modules ok
    stopped modules ok
    DEBUG FS_CHECK: FSCK:  /dev/xvdb
    DEBUG FS-CHECK : xvda
    block-device-added xvda
        DEVNAME=/dev/xvda
    starting fs-check
    /dev/xvdb: clean, 208398/524288 files, 394149/1048576 blocks
    started fs-check
    stopping fs-check ok
    stopped fs-check ok
    Mounting: /dev/xvdb
    fs-checked /dev/xvdb
    fs-checked /dev/xvdb
    mount-partition (start) waiting
    mount-partition (start) starting
    starting mount-partition
    mount-partition (start) pre-start
    mount-partition (start) spawned, process 582
    mount-partition (start) post-start, (main) process 582
    mount-partition (start) running, process 582
    started mount-partition
    fs-checked root
    starting mount-root
    started mount-root
    path-mounted root
    starting syslog-ng
    started syslog-ng
    stopping mount-root ok
    stopped mount-root ok
    path-mounted /dev/xvdb
    stopping fs-check-root ok
    stopped fs-check-root ok
    path-mounted /dev/xvdb
    mount-partition (stop) running
    mount-partition (stop) stopping
    stopping mount-partition ok
    mount-partition (stop) killed
    mount-partition (stop) post-stop
    mount-partition (stop) waiting
    stopped mount-partition ok
    stopping fs-check ok
    stopped fs-check ok
    stopping udevtrigger ok
    stopped udevtrigger ok
    stopping tty1 ok
    starting tty1
    started tty1


    This is upstart.(none) (Linux i686 2.6.16.33-xen) 19:20:09

    upstart login: root
    Password:
    Last login: Sat Mar 10 19:10:55 2007 on tty1
    upstart ~ #  mount
    proc on /proc type proc (rw)
    /dev/xvda on / type ext2 (rw,noatime)
    none on /dev/pts type devpts (rw,gid=5,mode=0620)
    /dev/xvdb on /mnt/gentoo type ext2 (rw,noatime)
    upstart ~ # 

I'll need to test a bit more, with different disk configurations. But so 
far it works for me.
Paul



More information about the upstart-devel mailing list