stop.js 927 B

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