Cleanup/Delete provisioned URLs

Hi,

I provisioned my server with domains such as:
example2.staging.mydomain.com

However, I am now due to use single subdomain instead of multiple. To keep things clean, I would like to re-provision with the new urls, but also delete the existing too. Is there a known method to do this with Trellis, or just the manual way like so:

sudo rm -rf /etc/nginx/sites-available/example2.staging.mydomain.com
sudo rm -rf /etc/nginx/sites-enabled/example2.staging.mydomain.com
sudo rm -rf /etc/letsencrypt/live/example2.staging.mydomain.com
sudo rm -rf /etc/letsencrypt/archive/example2.staging.mydomain.com
sudo rm -rf /etc/letsencrypt/renewal/example2.staging.mydomain.com.conf

Hey @JordanC26 we have to clean up a site from time to time too. The thorough way would be to destroy the server and spin up a new one but if you don’t want to do that, we’ve got a guide written for our devs that I’m happy sharing:

Assuming you’ve made a backup of db/uploads/anything else you need

  • First, remove all mention from the vault.yml and wordpress-sites.yml files. Make note of the database credentials from vault.yml as you may need them.
  • Provision the server ansible-playbook server.yml -e env=[environment]
  • SSH into the server as web user e.g. ssh web@[server]
  • ls /srv/www and check if the site folder exists.
    • Exists
      • cd /srv/www/example.com/current and drop the database if you’ve already made a backup, using wp db drop --yes.
      • Go back to cd /srv/www && ls and rm -r example.com to remove site folder.
      • If you need sudo, you’ll need to exit and ssh as admin@[server].
    • Doesn’t exist
      • login to MariaDB using mysql -u example_com -p and the password from vault.yml. Root MySQL access is available as web user, so if you need that you can run mysql -u root -p. You may need to exit and ssh web@[server]. If this is an old site, check back through the vault history in the git repo to find the database password.
      • show databases; will do what you’d expect. Note the semicolon in these commands.
      • DROP DATABASE IF EXISTS name_of_database; to delete.
      • exit; to say Bye.
  • You’ll need sudo for the next tasks, so you may need to exit and use the admin user e.g. ssh admin@[server]
  • Run ls /etc/nginx/includes.d and sudo rm -r /etc/nginx/includes.d/example.com if site exists. There may be lots of old or unused sites in here - see PR #1573.
  • Run ls /etc/nginx/sites-enabled and sudo rm /etc/nginx/sites-enabled/example.com.conf if site exists.
  • Run ls /etc/cron.d and sudo rm /etc/cron.d/wordpress-example_com if site exists.
  • Run sudo ls /etc/nginx/ssl/letsencrypt. Look for and sudo rm the following:
    • /etc/nginx/ssl/letsencrypt/example.co.uk.key
    • /etc/nginx/ssl/letsencrypt/example.co.uk-[key].cert
    • /etc/nginx/ssl/letsencrypt/example.co.uk-[key]-bundled.cert
  • Restart cron sudo service cron restart
  • Restart Nginx sudo service nginx restart

If you happen to find any other files that aren’t on that list, can you share them back here for future searchers?

1 Like