From 54e5b5983ad836d678ddea8b09276949ca0c558b Mon Sep 17 00:00:00 2001 From: daniwe4 Date: Fri, 10 Nov 2023 10:51:50 +0100 Subject: [PATCH] master Delete: 403 delete command now requires root privillages --- app/src/Commands/Instances/DeleteCommand.php | 10 +++++++++- app/src/Lib/Docker/DockerShell.php | 8 ++++++++ setup/doil.sh | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/Commands/Instances/DeleteCommand.php b/app/src/Commands/Instances/DeleteCommand.php index d444ced8..930e1058 100644 --- a/app/src/Commands/Instances/DeleteCommand.php +++ b/app/src/Commands/Instances/DeleteCommand.php @@ -24,7 +24,7 @@ class DeleteCommand extends Command protected static $defaultName = "instances:delete"; protected static $defaultDescription = - "This command deletes one or all instances. It will remove everything belonging " . + "!NEEDS SUDO PRIVILEGES! This command deletes one or all instances. It will remove everything belonging " . "to the given instance including all its files, configuration and misc data." ; @@ -55,6 +55,14 @@ public function configure() : void public function execute(InputInterface $input, OutputInterface $output) : int { + if (! $this->posix->isSudo()) { + $this->writer->error( + $output, + "Please execute this script as sudo user!" + ); + return Command::FAILURE; + } + $instance = $input->getArgument("instance"); $all = $input->getOption("all"); diff --git a/app/src/Lib/Docker/DockerShell.php b/app/src/Lib/Docker/DockerShell.php index 9fc68f28..8d98c699 100644 --- a/app/src/Lib/Docker/DockerShell.php +++ b/app/src/Lib/Docker/DockerShell.php @@ -60,6 +60,14 @@ public function startContainerByDockerCompose(string $path) : void "rm -f /run/apache2/apache2.pid &>/dev/null" ); + $this->executeCommand( + $path, + basename($path), + "/bin/bash", + "-c", + "killall salt-minion &>/dev/null && /etc/init.d/salt-minion start &>/dev/null" + ); + $this->cleanupMasterKey($path); } diff --git a/setup/doil.sh b/setup/doil.sh index 3b8038ba..ff0c27c2 100755 --- a/setup/doil.sh +++ b/setup/doil.sh @@ -74,6 +74,7 @@ docker run --rm "${TERMINAL}" \ -v /etc:/etc \ -v /var/log:/var/log \ -e PHP_INI_SCAN_DIR=/srv/php/mods-available \ + -e SUDO_UID="$SUDO_UID" \ $GLOBAL_INSTANCES_PATH \ -w $(pwd) \ $MAP_USER \