Example #1
0
 def rollback(self):
     if self.use_bind:
         if self.is_mounted(self.destination):
             debug('Unmounting ...')
             run('umount %s' % self.destination)
         else:
             debug('Not mounted. Nothing to unmount.')
     else:
         if os.path.exists(self.destination):
             debug('Unlinking ...')
             run('rm %s' % self.destination)
         else:
             debug('Not linked. Nothing to unlink.')
Example #2
0
 def apply(self):
     if self.use_bind:
         if not self.is_mounted(self.destination):
             debug('Mounting ...')
             run('mount --bind %s %s' % (self.source, self.destination))
         else:
             debug('Already mounted.')
     else:
         if not os.path.exists(self.destination):
             debug('Linking ...')
             run('ln -s %s %s' % (self.source, self.destination))
         else:
             debug('Already linked.')
Example #3
0
    def _exec_action(self, action):

        valid_actions = ('start', 'restart', 'reload')
        if action not in valid_actions:
            raise Exception('Unknown service action "%s". Valid actions for upstart are: %s' % (
                self.action,
                ', '.join(valid_actions)
            ))
        action_ = '%s %s' % (action, self.name)
        debug('Exec action: %s' % action_)
        try:
            run(action_, ignore_errors=True)
        except CalledProcessError as e:
            error('Exec failed: %s' % e.message)
Example #4
0
    def exec_bash_script(script):
        script = compile_content(script)

        if "\n" in script:
            f = NamedTemporaryFile(delete=False)
            f.write(script)
            f.close()
            if user:
                subprocess.call(['chown', user, f.name])
            command = 'bash %s' % f.name
            if user:
                command = 'su -c "%s" - %s ' % (command, user)

            debug('bash$ %s' % command)
            debug('\n\n%s\n' % script)
            run(command)
            os.unlink(f.name)
        else:
            if user:
                script = 'su -c "%s" - %s ' % (script, user)
            run(script, log_output=True)
Example #5
0
 def is_mounted(self, path):
     return path in run('mount -l', ignore_errors=True)
Example #6
0
 def exec_script(script):
     script = compile_content(script)
     run(script, log_output=True)
Example #7
0
    def _exec_action(self, action):

        try:
            run('service %s %s' % (self.name, action))
        except CalledProcessError as e:
            error('Exec failed: %s' % e.message)
Example #8
0
 def rollback(self):
     try:
         pwd.getpwnam(self.name)
         run('userdel %s' % self.name)
     except KeyError:
         pass
Example #9
0
 def apply(self):
     try:
         pwd.getpwnam(self.name)
     except KeyError:
         run('useradd %s' % self.name)