Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @task
- @roles('db')
- def prepare_dbstorage(
- additional_disks=None,
- mount_point_backups='/var/backups',
- mount_point_postgresql='/var/lib/postgresql',
- device_name_backups='/dev/vdb1',
- device_name_postgresql='/dev/vdb1',
- cloudless=False,
- ):
- """
- Format new partitions and mount, now and permanently
- for dbserver's backups and postgres
- """
- if additional_disks is None:
- additional_disks = env.buildparams.get('additional_disks_db', None)
- if additional_disks is None:
- # Single disk installation - nothing to do for db storage
- return None
- # Stop PostgreSQL while we're working with its data directories
- with settings(warn_only=True):
- # Postgres may not be running at this point in time (e.g. cloudless)
- sudo('service postgresql stop')
- # FIXME: do we really know which will be /dev/vdb and which /dev/vdc (async timing)
- # /var/backups: exists but is empty at this stage - just mount
- # cloudless vm does not need a backup
- if not cloudless:
- sudo('echo -e "o\\nn\\np\\n1\\n\\n\\nw\\n" | fdisk {}'.format(device_name_backups))
- sudo('mkfs.ext4 {}'.format(device_name_backups))
- # append to root-only writable file, suppress output (can't just sudo with >>):
- sudo(
- 'echo "{} {} ext4 defaults 0 0" | sudo tee --append /etc/fstab > /dev/null'.format(
- device_name_backups,
- mount_point_backups
- )
- )
- sudo('mount {}'.format(mount_point_backups))
- # /var/lib/postgresql: we know mount point already exists, move away
- sudo('mv {} {}_ORIG'.format(mount_point_postgresql, mount_point_postgresql))
- sudo('mkdir {}'.format(mount_point_postgresql))
- # Cloudless server has disk set up differently
- # Does not need a new disk created
- # Needs fstab to use UUID of disk manually created disk (by a sysadmin)
- if cloudless:
- postgres_device_uuid = env.buildparams['postgres_device_uuid']
- sudo(
- 'echo "UUID={} {} ext4 defaults 0 2" | sudo tee --append /etc/fstab > /dev/null'.format(
- postgres_device_uuid,
- mount_point_postgresql,
- )
- )
- else:
- sudo('echo -e "o\\nn\\np\\n1\\n\\n\\nw\\n" | fdisk {}'.format(device_name_postgresql))
- sudo('mkfs.ext4 {}'.foramt(device_name_postgresql))
- # append to root-only writable file, suppress output (can't just sudo with >>):
- sudo(
- 'echo "{} {} ext4 defaults 0 0" | sudo tee --append /etc/fstab > /dev/null'.format(
- device_name_postgresql, mount_point_postgresql
- )
- )
- sudo('mount {}'.format(mount_point_postgresql))
- sudo('chown postgres:postgres {}'.format(mount_point_postgresql))
- sudo('mv {}_ORIG/* {}'.format(mount_point_postgresql, mount_point_postgresql))
- # also copy hidden files like .pgpass (start with . but not the parent dir ..)
- # move breaks with inter_device copy on cloudless vm
- sudo('cp -R {}_ORIG/.[!.]* {}'.format(mount_point_postgresql, mount_point_postgresql))
- sudo('rm -rf {}_ORIG'.format(mount_point_postgresql))
- sudo('service postgresql start')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement