def _deploy(self, code_dirs): compressed_file_name = 'tmp.tar.gz' exclude_dir = '.git' for code_dir in code_dirs: if os.path.exists(code_dir): upholstery.local(self.tar + ' ' + self.tar_compress_flags + ' ' + compressed_file_name + \ ' ' + code_dir + ' --exclude "' + exclude_dir + '"') upholstery.put(compressed_file_name, compressed_file_name) upholstery.local(self.rm + compressed_file_name) # Decompress and Clean up upholstery.run(self.tar + ' ' + self.tar_decompress_flags + ' ' + compressed_file_name) upholstery.run(self.rm + compressed_file_name) if self.datetime: indivo_servers_location = '/web/' + code_dir + 's/' + \ code_dir + '-' + \ str(self.datetime.year) + '_' + \ str(self.datetime.month) + '_' + \ str(self.datetime.day) else: indivo_server_location = '/web/' # SZ: Remove this in the future upholstery.sudo(self.mv + code_dir + ' ' + indivo_servers_location) return True
def add_sudo_group(self): sudo_group = self.random_string(6) self.set_user('root') self.add_group(sudo_group) self.change_mode(640, self.remote_sudoer_location) sudo_line = '%%' + sudo_group + ' ALL=(ALL) NOPASSWD:ALL' upholstery.run(self.echo + '\'' + sudo_line + "' >> " + self.remote_sudoer_location) return sudo_group
def add_group(self, group, num_tries=0): try: upholstery.run(self.groupadd + group) except: if num_tries == 0: self.del_group(group) self.add_group(group, 1) else: pass
def change_mode(self, mode, file): if isinstance(mode, int): try: mode = str(mode) except: raise TypeError if isinstance(mode, str): upholstery.run(self.chmod + mode + ' ' + file) return True return False
def _post_deploy(self): self.set_user(USER) upholstery.sudo(self.chown + 'web:www-data -R /web/indivo_servers/') upholstery.sudo(self.chown + 'web:www-data -R /web/indivo_ui_servers/') #self.set_user('web') #upholstery.run(self.cd + '/web/indivo_server && ./reset.sh') # Restart apache upholstery.run(self.touch + '/tmp/successful') # SZ: For development #upholstery.run('python manage.py runserver 0.0.0.0:8000') return True
def create_users(self, users): authorized_keys_file = 'authorized_keys' public_key_location = self.get_public_key_location() sudo_group = self.add_sudo_group() for user in users: if users[0] == user: upholstery.run(self.useradd + user + ' -G ' + sudo_group) else: upholstery.run(self.useradd + user) # If a public key exists then push it to the server if public_key_location: upholstery.run(self.mkdir + self.default_home_dir + user + '/' + self.default_ssh_dir) upholstery.put(public_key_location, self.default_home_dir + user + '/' + \ self.default_ssh_dir + \ authorized_keys_file) # Symlink all users > 0 upholstery.run(self.symlink + self.default_home_dir + user + ' /' + user) self.change_mode(440, self.remote_sudoer_location) return True
def create_postgres_user(self, user): # SZ: All postgres users should NOT be superusers! upholstery.run(self.sudo + 'postgres createuser -s ' + user)
def _post_install_packages(self): self.create_postgres_user('root') self.create_postgres_user('web') self.create_postgres_user('www-data') upholstery.run(self.sudo + 'postgres createdb indivo') return True
def del_group(self, group): upholstery.run(self.groupdel + group)