drbdlinks-1.22/0000755000175000017500000000000011732151234012031 5ustar jafojafodrbdlinks-1.22/README.markdown0000644000175000017500000001171611732151234014540 0ustar jafojafoDRBDLINKS README ================ Sean Reifschneider Homepage: [http://www.tummy.com/Community/software/drbdlinks/](http://www.tummy.com/Community/software/drbdlinks/) Code/bugfixes: [https://github.com/linsomniac/drbdlinks](https://github.com/linsomniac/drbdlinks) drbdlinks is under the following license: GPLv2 Overview -------- drbdlinks is a program that will manage creation and removal of symbolic links. It is primarily used with clusters of machines using either shared storage or the "DRBD" replicated block device. It has the ability to fix SELinux contexts and restart cron and syslog as part of the linking process. While the name of the program is "drbdlinks", it can be used in any shared-storage sort of environment where the shared storage is only mounted on the active node. In cases like NFS where the shared storage is always mounted on all nodes, drbdlinks is not necessary. The advantage over creating static symbolic links is that package updates often require that directories point at real files, so updates can often fail if you do not have the shared storage mounted. drbdlinks also supports multiple instances of links, in the case of active/active clusters. For example, if you have MySQL running in one resource group, and Apache running in another, you can use the "-c" switch to specify a configuration file for each resource group. A simple configuration file, "/etc/drbdlinks.conf", specifies the links. This can be used to manage links for /etc/httpd, /var/lib/pgsql, and other system directories that need to appear as if they are local to the system when running applications after a drbd shared partition has been mounted. When run with "start" as the mode, drbdlinks will rename the existing files/directories, and then make symbolic links into the DRBD partition. "stop" does the reverse. By default, the rename appends ".drbdlinks" to the name, but this can be overridden. An init script is included which runs "stop" before heartbeat starts, and after heartbeat stops. This is done to try to ensure that when the shared partition isn't mounted, the links are in their normal state. Getting Started --------------- The first thing you need to do is create a "/etc/drbdlinks.conf" file. The package ships with an example, primarily you will need to uncomment and modify the "mountpoint" and "link" directives. The "mountpoint" directive tells drbdlinks the root of where your shared storage for this resource group is mounted. Next, you will need to set up the shared storage. Automatic population: drbdlinks now includes an "initialize_shared_storage" mode that will look at the links in the config file, and if they don't exist in the shared storage it will populate them from the root file-system. Parent paths that do not exist will be set to the same ownership and mode as the same directory from the source file-system, if they share the same name. So for example, if you have a "link('/etc/apache2', '/shared/etc/apache2')", it will create "/shared/etc" and "/shared/etc/apache2" with the same permissions/ownership. Manual population: Create the directories specified by the "link" directives in the configuration file and copy the appropriate files into them. Now run "drbdlinks checklinks". This will test the configuration file and make sure all the specified links exist in the shared storage. Now you just need to list "drbdlinks" in your resources, it needs to be after the shared storage is mounted, but before any references to it are used. I usually bring it up immediately after the resource that mounts the shared storage. About Apache ------------ The easy route is to just set up all of "/etc/apache2" or "/etc/httpd" as the directory that is linked. However, this contains many sub-directories or links that may best be left on the root file-system, so that updates don't get the shared storage and the root file-system out of sync. In particular, the links to Apache modules may become out of sync. However, it also requires some discipline to ensure that all of the configuration changes you make are not in system directories or files. For example, ideally you would customize the configuration only in the "conf.d", "sites-available", "sites-enabled", and "mods-enabled" directories. I haven't yet tested these, but I'd propose you'd need to use the following. For RHEL/CentOS/Fedora: link('/etc/httpd/conf.d') link('/etc/httpd/conf/httpd.conf') link('/var/log/httpd') For Debian/Ubuntu: link('/etc/apache2/mods-enabled') link('/etc/apache2/sites-enabled') link('/etc/apache2/sites-available') link('/etc/apache2/conf.d') link('/etc/apache2/ports.conf') link('/etc/apache2/envvars') link('/etc/apache2/apache2.conf') link('/var/log/apache2') Please let me know if these values work or do not work for you. OCF Resource ------------ drbdlinks can also be used as an OCF resource. However, I don't fully understand how this is activated. If anyone can fill in any details here, that would be appreciated. drbdlinks-1.22/drbdlinksclean.init0000755000175000017500000000427611732151234015711 0ustar jafojafo#!/bin/sh # # drbdlinks: Cleans links made by drbdlinks. # # chkconfig: 2345 74 06 # description: Calls drbdlinks on initial system boot and shutdown to make # sure that any links set up by drbdlinks are cleaned up when # drbd is not running. # ### BEGIN INIT INFO # Provides: drbdlinks # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Should-Start: # Should-Stop: # Default-Start: 2345 # Default-Stop: 0 1 6 # Short-Description: Clean up drbdlinks links on system boot or shutdown. # Description: Calls drbdlinks on initial system boot and shutdown to make # sure that any links set up by drbdlinks are cleaned up when # drbd is not running. ### END INIT INFO # Source function library. . /lib/lsb/init-functions FOUNDFILE=0 [ -f /etc/drbdlinks.conf ] && FOUNDFILE=1 # also clean up old /var/run location. for FILE in /var/lib/drbdlinks/configs-to-clean/* \ /var/run/drbdlinks/configs-to-clean/* do [ ! -f "$FILE" ] && continue FOUNDFILE=1 break done if [ "$FOUNDFILE" != 1 ] then echo "No /etc/drbdlinks.conf file. Aborting." exit 1 fi case "$1" in start) "$0" stop exit "$?" ;; stop) echo -n 'Cleaning up drbdlinks.conf links...' # main drbdlinks.conf file RET=0 if [ -f /etc/drbdlinks.conf ] then if grep -q '^mountpoint(' /etc/drbdlinks.conf then /usr/sbin/drbdlinks stop RET=$? else echo "No mountpoint found in /etc/drbdlinks.conf, skipping." | \ logger -t drbdlinksclean echo "No mountpoint found in /etc/drbdlinks.conf, skipping." fi fi # clean up any supplemental config files for FILE in /var/lib/drbdlinks/configs-to-clean/* \ /var/run/drbdlinks/configs-to-clean/* do [ ! -f "$FILE" ] && continue echo -n "Cleaning up '${FILE##*/}' links..." echo "Cleaning up '${FILE##*/}' links..." | \ logger -t drbdlinksclean /usr/sbin/drbdlinks --config-file "$FILE" stop || RET=$? done if [ "$RET" -eq 0 ] then log_success_msg OK else log_failure_msg stop-failure exit 1 fi ;; restart|force-reload) "$0" start ;; status) exec /usr/sbin/drbdlinks status ;; *) echo "usage: $0 {start|stop}" ;; esac exit 0 drbdlinks-1.22/WHATSNEW0000644000175000017500000001126111732151234013215 0ustar jafojafoChanging configs-to-clean to be under "/var/lib" rather than "/var/run". Found by Alan Robertson, RHEL 6.x will clean out "/var/run/drbdlinks". Adding a syslog note to drbdlinksclean when it cleans up copied configs. The XML meta-data needs to have blank lines removed, reported by Alan Robertson. ================================ Version 1.21 -- Sun Nov 27, 2011 Thanks to Alan Robertson for testing and providing fixes for the OCFS code! Supporting being run as an OCF resource. Suggested by Alan Robertson. PACKAGER NOTE: drbdlinks now also needs to be installed in /usr/ocf/resource.d/tummy/drbdlinks as well as the previous locations. Adding "initialize_shared_storage" mode, suggested by Alan Robertson. Adding "checklinks" mode, suggested by Alan Robertson. Enhancing the README. ================================ Version 1.20 -- Wed Aug 10, 2011 Fix SELinux-related traceback on CentOS/RHEL version 6. (Patches provided by James Johnson and Robert Scheck) ================================ Version 1.19 -- Thu May 05, 2011 Changing cron restarting to look for init script existance instead of pid-file. ================================ Version 1.18 -- Fri May 22, 2009 Fixing a bug in the location of the cron pid file on Fedora/CentOS. (Patch provided by Robert Scheck) ================================ Version 1.17 -- Mon May 18, 2009 Fixing in a bug introduced in 1.12 that prevented drbdlinksclean from working. ================================ Version 1.16 -- Sat May 16, 2009 Making the license more clear. ================================ Version 1.15 -- Sun Apr 19, 2009 Fixing a bug in drbdlinksclean init script which would cause clean to fail if there was no "/etc/drbd.conf". Switched to check drbdlinks.conf instead. Fix by Stefan Seifert. ================================ Version 1.14 -- Fri Jan 23, 2009 Option to restart crond after links have changed. Adding patch from Heiko Schlittermann to add a "list" argument which dumps a list of the drbdlinks information for use with scripts that need this information from the configuration file. ================================ Version 1.12 -- Thu Sep 04, 2008 Added OPTIONS and EXAMPLES sections in the man page (Mike Loseke) Log debugging information via syslog. Added "cleanthisconfig" config command. This is meant to be used in a system with multiple drbd mountpoints, started at different times. Each one would typically have it's own config file, which may not be available at system boot. drbdlinks will now copy these files off to a safe location when it starts, and drbdlinksclean will run any of these it finds in addition to the normal drbdlinks.conf. Adding a "/var/run/drbdlinks/configs-to-clean" directory, any config files that are in there will get cleaned by "drbdlinksclean" at system boot. Modified monitor option so that it returns "stopped" instead of "not configured" if there is no configuration file. Required for the multiple configurations. ================================ Version 1.11 -- Mon Dec 24, 2007 Add option to make mountpoints shared using "mount --make-shared". Changing error writes to use syslog as well stdout. ================================ Version 1.09 -- Sat Aug 11, 2007 Look for init.d/rsyslog as alternative syslog start script to normal syslog. Suggested by Michael Mansour. ================================ Version 1.08 -- Tue Feb 27, 2007 Making the init script LSB-compliant. Suggested by Cyril Bouthors. ================================ Version 1.07 -- Fri Jul 14, 2006 Fixing a bug on the configuration test mode which resulted in: ValueError: too many values to unpack error. Reported by Ryan Suarez ================================ Version 1.06 -- Tue Mar 14, 2006 Fixing a bug related to the AnyLinksChanged code submitted by Alan. Problem detected and fixed by Arne R. van der Heyde. ================================ Version 1.05 -- Mon Feb 06, 2006 Several patches from Alan Robertson: Adding LSB exit codes. Restart syslog after links have changed. Exit code from start and stop reflects whether there were any errors. "restartsyslog" command in config file. All error messages start with "ERROR:" now. drbdlinksclean init script converted to LSB-compliance. Added "usebindmount" to allow using bind mounts instead of symbolic links (Suggested by Alessandro Zummo) ================================ Version 1.04 -- Tue Jul 19, 2005 Adding a "monitor" and "status" mode to drbdlinks which check to ensure that all links are up. Suggested by Cyril Bouthors. Adding a drbdlinks.8 man page. Original version submitted by Cyril Bouthors. drbdlinks-1.22/drbdlinks.spec0000644000175000017500000000506011732151234014662 0ustar jafojafo%define name drbdlinks %define version 1.22 %define release 1 %define prefix %{_prefix} Summary: A program for managing links into a DRBD shared partition. Name: %{name} Version: %{version} Release: %{release} License: GPLv2 Group: Applications/System URL: http://www.tummy.com/krud/ Source: %{name}-%{version}.tar.gz Packager: Sean Reifschneider BuildRoot: /var/tmp/%{name}-root Requires: python BuildArch: noarch %description drbdlinks is a program which manages links into a DRBD partition which is shared among several machines. A simple configuration file, "/etc/drbdlinks.conf", specifies the links. This can be used to manage links for /etc/httpd, /var/lib/pgsql, and other system directories that need to appear as if they are local to the system when running applications after a drbd shared partition has been mounted. When run with "start" as the mode, drbdlinks will rename the existing files/directories, and then make symbolic links into the DRBD partition. "stop" does the reverse. By default, the rename appends ".drbdlinks" to the name, but this can be overridden. An init script is included which runs "stop" before heartbeat starts, and after heartbeat stops. This is done to try to ensure that when the shared partition isn't mounted, the links are in their normal state. %prep %setup %build %install [ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" # make directories mkdir -p "$RPM_BUILD_ROOT"/etc//init.d/ mkdir -p "$RPM_BUILD_ROOT"/etc/ha.d/resource.d/ mkdir -p "$RPM_BUILD_ROOT"/usr/lib/ocf/resource.d/tummy/ mkdir -p "$RPM_BUILD_ROOT"/usr/sbin/ mkdir -p "$RPM_BUILD_ROOT"/var/lib/drbdlinks/configs-to-clean mkdir -p "%{buildroot}/%{_mandir}"/man8 # copy over files cp drbdlinks "$RPM_BUILD_ROOT"/usr/sbin/ ln -s ../../../usr/sbin/drbdlinks "$RPM_BUILD_ROOT"/etc/ha.d/resource.d/drbdlinks ln -s ../../../../sbin/drbdlinks "$RPM_BUILD_ROOT"/usr/lib/ocf/resource.d/tummy/drbdlinks cp drbdlinks.conf "$RPM_BUILD_ROOT"/etc/ cp drbdlinksclean.init "$RPM_BUILD_ROOT"/etc/init.d/drbdlinksclean cp drbdlinks.8 "%{buildroot}/%{_mandir}"/man8 %clean [ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" %post chkconfig --add drbdlinksclean %preun chkconfig --del drbdlinksclean %files %defattr(-,root,root) /usr/sbin/drbdlinks /etc/init.d/drbdlinksclean /etc/ha.d/resource.d/drbdlinks /usr/lib/ocf/resource.d/tummy %dir /var/lib/drbdlinks/configs-to-clean %config /etc/drbdlinks.conf %doc README LICENSE %{_mandir}/man8/* drbdlinks-1.22/drbdlinks.80000644000175000017500000001274511732151234014107 0ustar jafojafo.\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH DRBDLINKS 8 "September 3, 2008" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME drbdlinks \- manages links into a shared DRBD partition .SH SYNOPSIS .B drbdlinks [\fIOPTION\fR]... [start|stop|auto|status|monitor|checklinks] .SH DESCRIPTION .B drbdlinks is a program that will manage creation and removal of symbolic links. It is primarily used with clusters of machines using either shared storage or the "DRBD" replicated block device. While the name of the program is "drbdlinks", it can be used in any shared-storage sort of environment where the shared storage is only mounted on the active node. In cases like NFS where the shared storage is always mounted on all nodes, drbdlinks is not necessary. The advantage over creating static symbolic links is that package updates often require that directories point at real files, so updates can often fail if you do not have the shared storage mounted. .B drbdlinks also supports multiple instances of links, in the case of active/active clusters. For example, if you have MySQL running in one resource group, and Apache running in another, you can use the "-c" switch to specify a configuration file for each resource group. A simple configuration file, "/etc/drbdlinks.conf", specifies the links. This can be used to manage links for /etc/httpd, /var/lib/pgsql, and other system directories that need to appear as if they are local to the system when running applications after a drbd shared partition has been mounted. When run with "start" as the mode, drbdlinks will rename the existing files/directories, and then make symbolic links into the DRBD partition. "stop" does the reverse. Mode "checklinks" will report any links that do not exist in the destination area. During initial setup and configuration, this can help check that you have the destination file-system set up with the required components. If run with "initialize_shared_storage", destination links specified in the configuration file will be populated from the source storage. This is useful for initial setup to populate the shared storage. Preceding paths will be populated if they share the same name from source to destination. The "monitor" and "status" modes will check the file-system against the configuration file and will report "running" (monitor mode) or "OK" (status mode) if all links appear to be up. Otherwise they report "down" or "stopped" (respectively). By default, the rename appends .drbdlinks to the name, but this can be overridden in the configuration file. The "list" mode just show the list of links, with each line showing the link, destination, and a 0/1 flag for bindMount status. This may be useful for user scripts without having to parse the configuration. An init script is included which runs "stop" before heartbeat starts, and after heartbeat stops. This is done to try to ensure that when the shared partition isn't mounted, the links are in their normal state. .SH OPTIONS .PP .B drbdlinks has several options, using either short or long variants. .PP .IP "\fB-h, --help\fP" Print a short help message describing the available options and exit. .IP "\fB-c, --config-file=CONFIGFILE\fP" Specify an alternate config file. The default config file is /etc/drbdlinks.conf. Alternate config files should have a "drbdlinks-" prefix, e.g. "drbdlinks-httpd.conf". .IP "\fB-s, --suffix=SUFFIX\fP" Name to append to the local file-system name when the link is in place. The default is "drbdlinks", which would result in a renamed file like "/etc/httpd.drbdlinks". .IP "\fB-v, --verbose\fP" Increase verbosity level by 1 for every occurrence of this option. .SH EXAMPLES .PP Here are a few examples of how drbdlinks can be used. The most straight-forward, and default, method for starting drbdlinks: .PP .RS drbdlinks start .RE To use a suffix different from the default when linking to a file or directory, the -s option can be used, specifying the desired string: .PP .RS drbdlinks -s orig start .RE would rename the file-system name to "name.orig". Increase the verbosity to assist in debugging: .PP .RS drbdlinks -v -v start .RE Use an alternate configuration file, possibly from with a DRBD mounted file-system: .PP .RS drbdlinks -c /shared1/drbdlinks-httpd.conf start .RE This would use the specified configuration file, found on our DRBD device mounted on /shared1. This would allow us to easily keep drbdlinks configurations tied to a specific set of data on a DRBD disk in an active/active sort of HA configuration. .SH SEE ALSO .BR DRBD (8), .BR drbdadm (8), .BR drbdsetup (8), .BR heartbeat (8). .SH AUTHOR drbdlinks was written by Sean Reifschneider . .PP This manual page was written by Cyril Bouthors , for the Debian project (but may be used by others). Sean Reifschneider modified it for status and monitor arguments, and included it in the base drbdlinks release. Mike Loseke added the sections on options and examples. drbdlinks-1.22/README0000644000175000017500000001154511732151234012717 0ustar jafojafoDRBDLINKS README Sean Reifschneider Homepage: http://www.tummy.com/Community/software/drbdlinks/ Code/bugfixes: https://github.com/linsomniac/drbdlinks drbdlinks is under the following license: GPLv2 =================================== drbdlinks is a program that will manage creation and removal of symbolic links. It is primarily used with clusters of machines using either shared storage or the "DRBD" replicated block device. It has the ability to fix SELinux contexts and restart cron and syslog as part of the linking process. While the name of the program is "drbdlinks", it can be used in any shared-storage sort of environment where the shared storage is only mounted on the active node. In cases like NFS where the shared storage is always mounted on all nodes, drbdlinks is not necessary. The advantage over creating static symbolic links is that package updates often require that directories point at real files, so updates can often fail if you do not have the shared storage mounted. drbdlinks also supports multiple instances of links, in the case of active/active clusters. For example, if you have MySQL running in one resource group, and Apache running in another, you can use the "-c" switch to specify a configuration file for each resource group. A simple configuration file, "/etc/drbdlinks.conf", specifies the links. This can be used to manage links for /etc/httpd, /var/lib/pgsql, and other system directories that need to appear as if they are local to the system when running applications after a drbd shared partition has been mounted. When run with "start" as the mode, drbdlinks will rename the existing files/directories, and then make symbolic links into the DRBD partition. "stop" does the reverse. By default, the rename appends ".drbdlinks" to the name, but this can be overridden. An init script is included which runs "stop" before heartbeat starts, and after heartbeat stops. This is done to try to ensure that when the shared partition isn't mounted, the links are in their normal state. GETTING STARTED --------------- The first thing you need to do is create a "/etc/drbdlinks.conf" file. The package ships with an example, primarily you will need to uncomment and modify the "mountpoint" and "link" directives. The "mountpoint" directive tells drbdlinks the root of where your shared storage for this resource group is mounted. Next, you will need to set up the shared storage. Automatic population: drbdlinks now includes an "initialize_shared_storage" mode that will look at the links in the config file, and if they don't exist in the shared storage it will populate them from the root file-system. Parent paths that do not exist will be set to the same ownership and mode as the same directory from the source file-system, if they share the same name. So for example, if you have a "link('/etc/apache2', '/shared/etc/apache2')", it will create "/shared/etc" and "/shared/etc/apache2" with the same permissions/ownership. Manual population: Create the directories specified by the "link" directives in the configuration file and copy the appropriate files into them. Now run "drbdlinks checklinks". This will test the configuration file and make sure all the specified links exist in the shared storage. Now you just need to list "drbdlinks" in your resources, it needs to be after the shared storage is mounted, but before any references to it are used. I usually bring it up immediately after the resource that mounts the shared storage. ABOUT APACHE ------------ The easy route is to just set up all of "/etc/apache2" or "/etc/httpd" as the directory that is linked. However, this contains many sub-directories or links that may best be left on the root file-system, so that updates don't get the shared storage and the root file-system out of sync. In particular, the links to Apache modules may become out of sync. However, it also requires some discipline to ensure that all of the configuration changes you make are not in system directories or files. For example, ideally you would customize the configuration only in the "conf.d", "sites-available", "sites-enabled", and "mods-enabled" directories. I haven't yet tested these, but I'd propose you'd need to use the following. For RHEL/CentOS/Fedora: link('/etc/httpd/conf.d') link('/etc/httpd/conf/httpd.conf') link('/var/log/httpd') For Debian/Ubuntu: link('/etc/apache2/mods-enabled') link('/etc/apache2/sites-enabled') link('/etc/apache2/sites-available') link('/etc/apache2/conf.d') link('/etc/apache2/ports.conf') link('/etc/apache2/envvars') link('/etc/apache2/apache2.conf') link('/var/log/apache2') Please let me know if these values work or do not work for you. OCF Resource ------------ drbdlinks can also be used as an OCF resource. However, I don't fully understand how this is activated. If anyone can fill in any details here, that would be appreciated. drbdlinks-1.22/drbdlinks0000755000175000017500000004016111732151234013735 0ustar jafojafo#!/usr/bin/env python # # Manage a set of links into a DRBD shared directory # # Written by: Sean Reifschneider # Copyright (c) 2004-2011, tummy.com, ltd. All Rights Reserved # drbdlinks is under the following license: GPLv2 configFile = '/etc/drbdlinks.conf' cleanConfigsDirectory = '/var/lib/drbdlinks/configs-to-clean' import os, string, re, sys, stat, syslog, shutil syslog.openlog('drbdlinks', syslog.LOG_PID) try: import optparse except ImportError: import optik optparse = optik ########## class lsb: #{{{1 class statusRC: OK = 0 VAR_PID = 1 VAR_LOCK = 2 STOPPED = 3 UNKNOWN = 4 LSBRESERVED = 5 DISTRESERVED = 100 APPRESERVED = 150 RESERVED = 200 class exitRC: OK = 0 GENERIC = 1 EINVAL = 2 ENOTSUPPORTED = 3 EPERM = 4 NOTINSTALLED = 5 NOTCONFIGED = 6 NOTRUNNING = 7 LSBRESERVED = 8 DISTRESERVED = 100 APPRESERVED = 150 RESERVED = 200 ########### def log(s): #{{{1 sys.stderr.write(s) syslog.syslog(s) ############################################## def multiInitRestart(flavor, initscript_list): #{{{1 for initscript in initscript_list: if os.path.exists(initscript): retcode = os.system('%s restart' % initscript) if retcode != 0: log('%s restart returned %d, expected 0' % ( flavor, retcode )) return(retcode != 0) syslog.syslog('Unable to locate %s init script, not ' 'restarting.' % flavor) return(0) ########################## def restartSyslog(config): #{{{1 if not config.restartSyslog: return(0) return multiInitRestart('syslog', [ '/etc/init.d/syslog', '/etc/init.d/rsyslog' ]) ######################## def restartCron(config): #{{{1 if not config.restartCron: return(0) return multiInitRestart('cron', [ '/etc/init.d/crond', '/etc/init.d/cron', ]) ####################### def testConfig(config): #{{{1 allUp = 1 for linkLocal, linkDest, useBindLink in config.linkList: suffixName = linkLocal + options.suffix # check to see if the link is in place {{{3 if not os.path.exists(suffixName): allUp = 0 if options.verbose >= 1: print 'testConfig: Original file not present: "%s"' % suffixName continue if options.verbose >= 1: print 'testConfig: Returning %s' % allUp return(allUp) ############################### def loadConfigFile(configFile): #{{{1 class configClass: #{{{2 def __init__(self): #{{{3 self.mountpoint = None self.cleanthisconfig = 0 self.linkList = [] self.useSELinux = 0 self.selinuxenabledPath = None self.useBindMount = 0 self.debug = 0 self.restartSyslog = 0 self.restartCron = 0 self.makeMountpointShared = 0 # Locate where the selinuxenabled binary is for path in ( '/usr/sbin/selinuxenabled', '/sbin/selinuxenabled', ): if os.path.exists(path): self.selinuxenabledPath = path break # auto-detect if SELinux is on if self.selinuxenabledPath: ret = os.system(self.selinuxenabledPath) if ret == 0: self.useSELinux = 1 def cmd_cleanthisconfig(self, enabled = 1): #{{{3 self.cleanthisconfig = enabled def cmd_mountpoint(self, arg, shared = 0): #{{{3 self.mountpoint = arg if shared: self.makeMountpointShared = 1 def cmd_link(self, src, dest = None): #{{{3 self.linkList.append(( src, dest, self.useBindMount )) def cmd_selinux(self, enabled = 1): #{{{3 self.useSELinux = enabled def cmd_usebindmount(self, enabled = 1): #{{{3 self.useBindMount = enabled def cmd_debug(self, level = 1): #{{{3 self.debug = level def cmd_restartSyslog(self, enabled = 1): #{{{3 self.restartSyslog = enabled def cmd_restartCron(self, enabled = 1): #{{{3 self.restartCron = enabled # set up config environment #{{{2 config = configClass() namespace = { 'mountpoint' : config.cmd_mountpoint, 'link' : config.cmd_link, 'selinux' : config.cmd_selinux, 'debug' : config.cmd_debug, 'usebindmount' : config.cmd_usebindmount, 'restartSyslog' : config.cmd_restartSyslog, 'restartsyslog' : config.cmd_restartSyslog, 'restartCron' : config.cmd_restartCron, 'restartcron' : config.cmd_restartCron, 'cleanthisconfig' : config.cmd_cleanthisconfig, } # load the file #{{{2 try: execfile(configFile, {}, namespace) except Exception, e: print 'ERROR: Loading configuration file failed. See below for details:' print 'Environment: %s' % repr([ '%s=%s' % i for i in os.environ.items() if i[0].startswith('OCF_') ]) raise # process the data we got if config.mountpoint: config.mountpoint = string.rstrip(config.mountpoint, '/') for i in xrange(len(config.linkList)): oldList = config.linkList[i] if oldList[1]: arg2 = string.rstrip(oldList[1], '/') else: if not config.mountpoint: log('ERROR: Used link() when no mountpoint() was set ' 'in the config file.\n') sys.exit(3) arg2 = string.lstrip(oldList[0], '/') arg2 = os.path.join(config.mountpoint, arg2) config.linkList[i] = ([string.rstrip(oldList[0], '/'), arg2] + list(oldList[2:])) # return the data {{{2 return(config) def print_metadata(): print ''' 1.0 The full path of the configuration file on disc. The default is /etc/drbdlinks.conf, but you may wish to store this on the shared storage, or have different config files if you have multiple resource groups. Configuration Filename The suffix of the files/directories that are moved out of the way on the host file-system to make room for the symlink. By default this is ".drbdlinks". Host Filename Suffix '''.strip() sys.exit(lsb.exitRC.OK) # meta-data may happen when configuration is not present. {{{1 if 'meta-data' in sys.argv: print_metadata() # parse arguments {{{1 parser = optparse.OptionParser() parser.add_option('-c', '--config-file', dest = 'configFile', type = 'string', default = configFile, help = 'Location of the configuration file.') parser.add_option('-s', '--suffix', dest = 'suffix', type = 'string', default = '.drbdlinks', help = 'Name to append to the local file-system name when the link ' 'is in place.') parser.add_option('-v', '--verbose', default = 0, dest = 'verbose', action = 'count', help = 'Increase verbosity level by 1 for every "-v".') parser.set_usage('%prog (start|stop|auto|status|monitor|list|checklinks|\n' ' initialize_shared_storage)') options, args = parser.parse_args() origConfigFile = configFile # if called from OCF, parse the environment OCFenabled = os.environ.get('OCF_RA_VERSION_MAJOR') != None if OCFenabled: try: options.configFile = os.environ['OCF_RESKEY_configfile'] except KeyError: pass try: options.suffix = os.environ['OCF_RESKEY_suffix'] except KeyError: pass configFile = options.configFile # figure out what the mode to run in {{{1 if len(args) == 1 or (OCFenabled and len(args) > 0): # NOTE: OCF specifies that additional arguments beyond the first should # be ignored. if args[0] not in ( 'start', 'stop', 'auto', 'monitor', 'status', 'list', 'checklinks', 'initialize_shared_storage' ): parser.error('ERROR: Unknown mode "%s", expecting one of ' '(start|stop|auto|\n status|monitor|list|checklinks|' 'initialize_shared_storage)' % args[0]) sys.exit(lsb.exitRC.ENOTSUPPORTED) mode = args[0] else: parser.error('Expected exactly one argument to specify the mode.') sys.exit(lsb.exitRC.EINVAL) if options.verbose >= 2: print 'Initial mode: "%s"' % mode # load config file {{{1 try: config = loadConfigFile(configFile) except IOError, e: if e.errno == 2: if mode == 'monitor' or mode == 'status': print ('WARNING: Config file "%s" not found, assuming drbdlinks ' 'is stopped' % configFile) if mode == 'status': sys.exit(lsb.statusRC.STOPPED) else: sys.exit(lsb.exitRC.NOTRUNNING) print 'ERROR: Unable to open config file "%s":' % configFile print ' ', str(e) syslog.syslog('Invalid config file "%s"' % configFile) sys.exit(lsb.statusRC.UNKNOWN) raise if not config.mountpoint: log('No mountpoint found in config file. Aborting.\n') if mode == 'monitor': if config.debug: syslog.syslog('Monitor called without mount point') sys.exit(lsb.exitRC.EINVAL) if config.debug: syslog.syslog('No mount point') sys.exit(lsb.statusRC.UNKNOWN) if not os.path.exists(config.mountpoint): log('Mountpoint "%s" does not exist. Aborting.\n' % config.mountpoint) if mode == 'monitor': if config.debug: syslog.syslog('Mount point does not exist, monitor mode') sys.exit(lsb.exitRC.EINVAL) if config.debug: syslog.syslog('Mount point does not exist') sys.exit(lsb.statusRC.UNKNOWN) # startup log message {{{1 if config.debug: syslog.syslog('drbdlinks starting: args: "%s", configfile: "%s"' % ( repr(sys.argv), configFile )) # if mode is auto, figure out what mode to use {{{1 if mode == 'auto': if (os.stat(config.mountpoint).st_dev != os.stat(os.path.join(config.mountpoint, '..')).st_dev): if options.verbose >= 1: print 'Detected mounted file-system on "%s"' % config.mountpoint mode = 'start' else: mode = 'stop' if options.verbose >= 1: print 'Mode: "%s"' % mode # just display the list of links {{{1 if mode == 'list': for linkLocal, linkDest, useBindMount in config.linkList: print linkLocal, linkDest, useBindMount sys.exit(0) # set up links {{{1 anyLinksChanged = 0 if mode == 'start': errorCount = 0 # set up shared mountpoint if config.makeMountpointShared: #{{{2 os.system('mount --make-shared "%s"' % config.mountpoint) # loop over links for linkLocal, linkDest, useBindMount in config.linkList: #{{{2 suffixName = linkLocal + options.suffix # check to see if the link is in place {{{3 if os.path.exists(suffixName): if options.verbose >= 1: print 'Skipping, appears to already be linked: "%s"' % linkLocal continue # make the link {{{3 try: if options.verbose >= 2: print 'Renaming "%s" to "%s"' % ( linkLocal, suffixName ) os.rename(linkLocal, suffixName) anyLinksChanged = 1 except ( OSError, IOError ), e: log('Error renaming "%s" to "%s": %s\n' % ( suffixName, linkLocal, str(e) )) errorCount = errorCount + 1 if options.verbose >= 2: print 'Linking "%s" to "%s"' % ( linkDest, linkLocal ) anyLinksChanged = 1 if useBindMount: st = os.stat(linkDest) if stat.S_ISREG(st.st_mode): open(linkLocal, 'w').close() else: os.mkdir(linkLocal) os.system('mount -o bind "%s" "%s"' % ( linkDest, linkLocal )) else: try: os.symlink(linkDest, linkLocal) except ( OSError, IOError ), e: log('Error linking "%s" to "%s": %s' % ( linkDest, linkLocal, str(e) )) errorCount = errorCount + 1 # set up in SELinux if config.useSELinux: fp = os.popen('ls -d --scontext "%s"' % suffixName, 'r') line = fp.readline() fp.close() if line: line = string.split(line, ' ')[0] seInfo = string.split(line, ':') seUser, seRole, seType = seInfo[:3] if len(seInfo) >= 4: seRange = seInfo[3] os.system('chcon -h -u "%s" -r "%s" -t "%s" -l "%s" "%s"' % ( seUser, seRole, seType, seRange, linkLocal )) else: os.system('chcon -h -u "%s" -r "%s" -t "%s" "%s"' % ( seUser, seRole, seType, linkLocal )) if anyLinksChanged: if restartSyslog(config): errorCount = errorCount + 1 if restartCron(config): errorCount = errorCount + 1 if config.cleanthisconfig and origConfigFile != configFile: if not os.path.exists(cleanConfigsDirectory): if config.debug: syslog.syslog('Config copy directory "%s" does not exist.' % cleanConfigsDirectory) else: if config.debug: syslog.syslog('Preserving a copy of the config file.') shutil.copy(configFile, cleanConfigsDirectory) if errorCount: if config.debug: syslog.syslog('Exiting due to %d errors' % errorCount) sys.exit(lsb.exitRC.GENERIC) if config.debug: syslog.syslog('Exiting with no errors') sys.exit(lsb.exitRC.OK) # remove links {{{1 elif mode == 'stop': errorCount = 0 for linkLocal, linkDest, useBindMount in config.linkList: suffixName = linkLocal + options.suffix # check to see if the link is in place {{{3 if not os.path.exists(suffixName): if options.verbose >= 1: print 'Skipping, appears to already be shut down: "%s"' % linkLocal continue # break the link {{{3 try: if options.verbose >= 2: print 'Removing "%s"' % ( linkLocal, ) anyLinksChanged = 1 if useBindMount: os.system('umount "%s"' % linkLocal) try: os.remove(linkLocal) except: pass if os.path.exists(linkLocal): os.rmdir(linkLocal) else: os.remove(linkLocal) except ( OSError, IOError ), e: log('Error removing "%s": %s\n' % ( linkLocal, str(e) )) errorCount = errorCount + 1 try: if options.verbose >= 2: print 'Renaming "%s" to "%s"' % ( suffixName, linkLocal ) os.rename(suffixName, linkLocal) anyLinksChanged = 1 except ( OSError, IOError ), e: log('Error renaming "%s" to "%s": %s\n' % ( suffixName, linkLocal, str(e) )) errorCount = errorCount + 1 if anyLinksChanged: restartSyslog(config) restartCron(config) if errorCount: if config.debug: syslog.syslog('Exiting due to %d errors' % errorCount) sys.exit(lsb.exitRC.GENERIC) if config.debug: syslog.syslog('Exiting with no errors') sys.exit(lsb.exitRC.OK) # monitor mode {{{1 elif mode == 'monitor': if testConfig(config): if config.debug: syslog.syslog('Monitor mode returning ok') sys.exit(lsb.exitRC.OK) if config.debug: syslog.syslog('Monitor mode returning notrunning') sys.exit(lsb.exitRC.NOTRUNNING) # status mode {{{1 elif mode == 'status': if testConfig(config): print "info: DRBD Links OK (present)" if config.debug: syslog.syslog('Status mode returning ok') sys.exit(lsb.statusRC.OK) print "info: DRBD Links stopped (not set up)" if config.debug: syslog.syslog('Status mode returning stopped') sys.exit(lsb.statusRC.STOPPED) # check mode {{{1 elif mode == 'checklinks': for linkLocal, linkDest, useBindMount in config.linkList: if not os.path.exists(linkDest): print 'Doest not exist:', linkDest sys.exit(lsb.exitRC.OK) # initialize_shared_storage mode {{{1 elif mode == 'initialize_shared_storage': def dirs_to_make(src, dest): '''Return a list of paths, from top to bottom, that need to be created in the destination. The return value is a list of tuples of (src, dest) where the `src` is the corresponding source directory to the `dest`. ''' l = [] destdirname = os.path.dirname(dest) srcdirname = os.path.dirname(src) while srcdirname and srcdirname != '/': if os.path.exists(destdirname): break if os.path.basename(destdirname) != os.path.basename(srcdirname): break l.append(( srcdirname, destdirname )) srcdirname = os.path.dirname(srcdirname) destdirname = os.path.dirname(destdirname) return l[::-1] for linkLocal, linkDest, useBindMount in config.linkList: if os.path.exists(linkDest): continue for src, dest in dirs_to_make(linkLocal, linkDest): print 'Making directory "%s"' % dest os.mkdir(dest) srcstat = os.stat(src) os.chmod(dest, srcstat.st_mode) os.chown(dest, srcstat.st_uid, srcstat.st_gid) print 'Copying "%s" to "%s"' % ( linkLocal, linkDest ) os.system('cp -ar "%s" "%s"' % ( linkLocal, linkDest )) sys.exit(lsb.exitRC.OK) drbdlinks-1.22/Makefile0000644000175000017500000000003711732151234013471 0ustar jafojafotest: ( cd tests; make test ) drbdlinks-1.22/drbdlinks.conf0000644000175000017500000000513211732151234014655 0ustar jafojafo# # Sample configuration file for drbdlinks # If passed an option of 1, SELinux features will be used. If 0, they # will not. The default is to auto-detect if SELinux is enabled. If # enabled, created links will be added to the SELinux context using # chcon -h -u -r -t , where the values plugged # in this command are pulled from the original file. #selinux(1) # If passed an option of 1, syslog will be restarted if any links are # changed. If 0, syslog is not restarted after links are changed. #restartsyslog(1) # # If passed an option of 1, cron will be restarted if any links are # changed. If 0, cron is not restarted after links are changed. #restartcron(1) # If passed an option of 1, "mount -o bind" is used instead of symbolic # links. If 0, symbolic links are used. This only applies to link() # calls made after this call, and until usebindmount() is called with a # different value. In other words, usebindmount can be called with 1 and # then several link()s created that use bind mounts, then with 0 and other # link()s which will be symlinks. #usebindmount(1) # If set to 1, drbdlinks will log debugging information via syslog. debug(1) # One mountpoint must be listed. This is the location where the DRBD # drive is mounted. If the "shared" argument is set to 1, this will cause # bind mounts to be shared, meaning that sub-mounts are propagated. In # effect, "mountpoint('/mnt', shared = 1)" causes the following to be # run: "mount --make-shared /mnt". #mountpoint('/shared', shared = 1) # If enabled, this option will preserve a copy of the config file if # the "--config-file" option is given to drbdlinks so that drbdlinksclean # will undo the changes at the next system boot. Note that the config # files must have a unique base name ("/yada/yada/drbdlinks-www.conf" and # "/yada/drbdlinks-nfs.conf", NOT "/path/www/drbdlinks.conf" # and "/path/nfs/drbdlinks.conf"). These files are copied into # "/var/lib/drbdlinks/configs-to-clean" at "start" time so that drbdlinks # can clean them later. cleanthisconfig(1) # Multiple "link" lines may be listed, one for each link that needs to be # set up into the above shared mountpoint. If "link()" is passed one # argument, it is assumed that it is linked into that name under the # mountpoint above. Otherwise, you can specify a second argument which is # the location of the file on the shared partition. # # For example, if mountpoint is "/shared" and you call "link('/etc/httpd')", # it is equivalent to calling "link('/etc/httpd', '/shared/etc/httpd')". #link('/etc/httpd') #link('/var/lib/pgsql/') drbdlinks-1.22/tests/0000755000175000017500000000000011732151234013173 5ustar jafojafodrbdlinks-1.22/tests/Makefile0000644000175000017500000000064211732151234014635 0ustar jafojafoDRBDLINKS=python ../drbdlinks test: $(DRBDLINKS) meta-data | grep -iq 'Configuration Filename' mkdir shared echo 'Shared file' >shared/testlink echo 'Local file' >testlink $(DRBDLINKS) -c drbdlinks.conf start $(DRBDLINKS) -c drbdlinks.conf status grep -q 'Shared file' testlink $(DRBDLINKS) -c drbdlinks.conf stop grep -q 'Local file' testlink rm -f testlink rm -rf shared drbdlinks-1.22/tests/drbdlinks.conf0000644000175000017500000000021111732151234016010 0ustar jafojafoselinux(0) restartsyslog(0) restartcron(0) usebindmount(0) debug(1) mountpoint('shared', shared = 0) cleanthisconfig(0) link('testlink') drbdlinks-1.22/LICENSE0000644000175000017500000004330211732151234013040 0ustar jafojafo GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.