~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-mountallusers

Dispatch now generates an index for each plugin type, allowing plugins to
be written which are aware of other plugins, and other plugin types.

All view plugins now subclass from ivle.webapp.base.plugins.ViewPlugin,
as opposed to subclassing BasePlugin directly. This will allow us to
easily re-write console as an OverlayPlugin, and allow future new
plugins types to be created.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# IVLE - Informatics Virtual Learning Environment
 
3
# Copyright (C) 2007-2008 The University of Melbourne
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
# Program: MountAllUsers
 
20
# Author:  William Grant
 
21
# Date:    4/7/2008
 
22
 
 
23
# Script to UnionFS-mount jails for all users on the system.
 
24
# Requires root to run.
 
25
 
 
26
import sys
 
27
import os
 
28
import os.path
 
29
import optparse
 
30
import logging
 
31
 
 
32
import ivle.database
 
33
import ivle.conf
 
34
 
 
35
p = optparse.OptionParser()
 
36
p.add_option('--verbose', '-v', action='store_true')
 
37
p.add_option('--unmount', '-u', action='store_true')
 
38
options, arguments = p.parse_args()
 
39
 
 
40
if options.verbose:
 
41
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
 
42
                        level=logging.DEBUG)
 
43
else:
 
44
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
 
45
                        level=logging.WARNING)
 
46
 
 
47
if os.getuid() != 0:
 
48
    print >> sys.stderr, "%s must be run as root" % \
 
49
                          os.path.basename(sys.argv[0])
 
50
    sys.exit(1)
 
51
 
 
52
store = ivle.database.get_store()
 
53
users = store.find(ivle.database.User).order_by(ivle.database.User.login)
 
54
 
 
55
logging.info("mass aufs mount started")
 
56
 
 
57
for user in users:
 
58
    login = user.login
 
59
    # This is where we'll mount to...
 
60
    destdir = os.path.join(ivle.conf.jail_base, login)
 
61
    # ... and this is where we'll get the user bits.
 
62
    srcdir = os.path.join(ivle.conf.jail_src_base, login)
 
63
 
 
64
    try:
 
65
        if not options.unmount:
 
66
            if not os.path.exists(srcdir):
 
67
                logging.info("user %s doesn't have a jail - skipping" % login)
 
68
                continue
 
69
            if not os.path.exists(destdir):
 
70
                logging.debug("user %s had no mountpoint - creating" % login)
 
71
                os.mkdir(destdir)
 
72
        
 
73
            if os.system('/bin/mount -t aufs -o dirs=%s:%s=ro none %s'
 
74
                             % (srcdir,ivle.conf.jail_system,destdir)) == 0:
 
75
                logging.info("mounted user %s's jail." % login)
 
76
            else:
 
77
                logging.error("failed to mount user %s's jail!" % login)
 
78
        else:
 
79
            os.system('/bin/umount ' + destdir)
 
80
            logging.info("unmounted user %s's jail." % login)
 
81
    except Exception, message:
 
82
        logging.warning(str(message))
 
83
        continue
 
84
 
 
85
logging.info("mount completed successfully")