Commit 42e018b0 authored by Valentin Reis's avatar Valentin Reis

Minor refactor.

parent a2eda2ec
Pipeline #5326 passed with stage
in 2 minutes and 28 seconds
......@@ -33,49 +33,31 @@ import Control.Monad as CM
import Data.Maybe
import Control.Foldl as Fold
import Text.Show.Pretty
import System.Environment
cleanLeftovers :: WorkingDirectory -> Shell () --TODO
cleanLeftovers (WorkingDirectory wd) = do
printInfo "Cleaning working(output) directory."
cleanLog wd
printInfo "Cleaning sockets."
CM.mapM_ cleanSocket ["/tmp/nrm-downstream-in", "/tmp/nrm-upstream-in", "/tmp/nrm-downstream-event"]
checkFsAttributes :: FilePath -> Shell ()
checkFsAttributes workingDirectory = do
let dir = case toText workingDirectory of
Left di -> di
Right di -> di
let findmnt = inproc "findmnt" ["-T", dir, "-o", "OPTIONS"] empty
b <- liftIO $ Turtle.Shell.fold (grep (has "nosuid") findmnt) Fold.length
when (b > 0) $ dieRed $ format
("The output directory, " % fp % ", must not mounted with \"nosuid\"")
workingDirectory
CM.mapM_
cleanSocket
[ "/tmp/nrm-downstream-in"
, "/tmp/nrm-downstream-event"
, "/tmp/nrm-upstream-in"
, "/tmp/nrm-upstream-event"
]
printInfo "Cleaning output directory."
void $ shell (format ("rm -rf " % fp) wd) Turtle.empty
prepareDaemon
:: StdOutLog -> StdErrLog -> Maybe TestText -> Shell Instrumentation
prepareDaemon out stdErr test = do
_ <- myWhich "daemon"
confPath <- myWhich "argo_nodeos_config"
let confPath' = "./argo_nodeos_config"
cp confPath confPath'
printInfo $ format ("Copied the configurator to " % fp) confPath'
printInfo $ format "Trying to sudo chown and chmod argo_nodeos_config"
sudoPath <- liftIO $ pack <$> getEnv "SUDO"
verboseShell (format (s % " chown root:root " % fp) sudoPath confPath') empty
>>= \case
ExitSuccess -> printInfo "Chowned argo_nodeos_config to root:root."
ExitFailure n ->
die ("Failed to set argo_nodeos_config permissions " <> repr n)
verboseShell (format (s % " chmod u+sw " % fp) sudoPath confPath') empty
>>= \case
ExitSuccess -> printInfo "Set the suid bit."
ExitFailure n ->
die ("Setting suid bit failed with exit code " <> repr n)
_ <- myWhich "daemon"
let confPath' = "/tmp/argo_nodeos_config"
cleanContainers confPath' 1 2
export "ARGO_NODEOS_CONFIG" (format fp confPath')
return $ Instrumentation (P.proc "daemon" []) out stdErr test
return $ Instrumentation (P.proc "daemon" ["--nrm_log", "./nrm_log"])
out
stdErr
test
where
nodeOsFailure n = do
printError ("argo_nodeos_config failed with exit code :" <> repr n)
......@@ -198,18 +180,9 @@ runStack :: StackArgs -> Shell StackOutput
runStack sa@StackArgs {..} = do
when (verbosity == Verbose) $ liftIO $ pPrint sa
CM.mapM_
cleanSocket
[ "/tmp/nrm-downstream-in"
, "/tmp/nrm-downstream-event"
, "/tmp/nrm-upstream-in"
, "/tmp/nrm-upstream-event"
]
let (WorkingDirectory wd) = workingDirectory
_ <- Turtle.shell (format ("rm -rf " % fp) wd) Turtle.empty
mktree wd
checkFsAttributes wd
cd wd
cleanLeftovers workingDirectory
CM.mapM_ ($ (coerce workingDirectory :: FilePath)) [mktree, cd]
iDaemon <- case daemon of
DontRun -> return Nothing
......
......@@ -100,7 +100,7 @@ verboseShell' :: Text -> Shell Line -> Shell (ExitCode, Text, Text)
verboseShell' command i = printCommand command >> shellStrictWithErr command i
cleanSocket :: FilePath -> Shell ()
cleanSocket = sudoRemoveFile printError "socket"
cleanSocket = sudoRemoveFile printWarning "socket"
cleanLog :: FilePath -> Shell ()
cleanLog = sudoRemoveFile printWarning "log folder"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment