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.')
 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.')
    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)
Exemple #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)
 def is_mounted(self, path):
     return path in run('mount -l', ignore_errors=True)
Exemple #6
0
 def exec_script(script):
     script = compile_content(script)
     run(script, log_output=True)
    def _exec_action(self, action):

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