stop.js 957 B

12345678910111213141516171819202122232425262728293031323334
  1. const path = require('path');
  2. const isRoot = require('is-root');
  3. const hostile = require('hostile');
  4. const colors = require('colors');
  5. const docker = require('docker-compose');
  6. const log = require('../inc/log');
  7. const ProjectEnvironment = require('../classes/ProjectEnvironment');
  8. const uninstallHosts = (hosts) => {
  9. if (!isRoot()) {
  10. log.warn('Unable to unset hosts because you need root privileges');
  11. } else {
  12. for (var ip in hosts) {
  13. const hostsString = hosts[ip].join(' ');
  14. log.log('Uninstalling hosts for %s: %s', ip, hostsString);
  15. hostile.remove(ip, hostsString);
  16. }
  17. }
  18. };
  19. const stopServices = async (projectEnv) => {
  20. await docker.down(projectEnv.getDockerOptions());
  21. };
  22. module.exports = (env) => {
  23. const projectEnv = new ProjectEnvironment(process.cwd(), env);
  24. log.log("Shutting down project (%s environment)...", colors.bold(env));
  25. uninstallHosts(projectEnv.getHosts());
  26. stopServices(projectEnv);
  27. };