os info propigation
Also, lost the systemd-nspawn parameters; I'll do that some other way.
This commit is contained in:
parent
cf3a8883ec
commit
36e89cd148
|
@ -86,8 +86,9 @@ clam = standardSystem "clam.kitenet.net" Unstable "amd64"
|
||||||
& Systemd.nspawned meow
|
& Systemd.nspawned meow
|
||||||
|
|
||||||
meow :: Systemd.Container
|
meow :: Systemd.Container
|
||||||
meow = Systemd.container "meow" (System (Debian Unstable) "amd64") []
|
meow = Systemd.container "meow" (System (Debian Unstable) "amd64")
|
||||||
& Apt.serviceInstalledRunning "uptimed"
|
& Apt.serviceInstalledRunning "uptimed"
|
||||||
|
& alias "meow.kitenet.net"
|
||||||
|
|
||||||
testChroot :: Chroot.Chroot
|
testChroot :: Chroot.Chroot
|
||||||
testChroot = Chroot.chroot "/tmp/chroot" (System (Debian Unstable) "amd64")
|
testChroot = Chroot.chroot "/tmp/chroot" (System (Debian Unstable) "amd64")
|
||||||
|
|
|
@ -19,6 +19,7 @@ import Data.List.Utils
|
||||||
import System.Posix.Directory
|
import System.Posix.Directory
|
||||||
|
|
||||||
data Chroot = Chroot FilePath System Host
|
data Chroot = Chroot FilePath System Host
|
||||||
|
deriving (Show)
|
||||||
|
|
||||||
instance Hostlike Chroot where
|
instance Hostlike Chroot where
|
||||||
(Chroot l s h) & p = Chroot l s (h & p)
|
(Chroot l s h) & p = Chroot l s (h & p)
|
||||||
|
@ -33,6 +34,7 @@ instance Hostlike Chroot where
|
||||||
-- > & ...
|
-- > & ...
|
||||||
chroot :: FilePath -> System -> Chroot
|
chroot :: FilePath -> System -> Chroot
|
||||||
chroot location system = Chroot location system (Host location [] mempty)
|
chroot location system = Chroot location system (Host location [] mempty)
|
||||||
|
& os system
|
||||||
|
|
||||||
-- | Ensures that the chroot exists and is provisioned according to its
|
-- | Ensures that the chroot exists and is provisioned according to its
|
||||||
-- properties.
|
-- properties.
|
||||||
|
|
|
@ -22,14 +22,12 @@ type ServiceName = String
|
||||||
|
|
||||||
type MachineName = String
|
type MachineName = String
|
||||||
|
|
||||||
type NspawnParam = CommandParam
|
data Container = Container MachineName System Host
|
||||||
|
|
||||||
data Container = Container MachineName System [CommandParam] Host
|
|
||||||
|
|
||||||
instance Hostlike Container where
|
instance Hostlike Container where
|
||||||
(Container n s ps h) & p = Container n s ps (h & p)
|
(Container n s h) & p = Container n s (h & p)
|
||||||
(Container n s ps h) &^ p = Container n s ps (h &^ p)
|
(Container n s h) &^ p = Container n s (h &^ p)
|
||||||
getHost (Container _ _ _ h) = h
|
getHost (Container _ _ h) = h
|
||||||
|
|
||||||
-- dbus is only a Recommends of systemd, but is needed for communication
|
-- dbus is only a Recommends of systemd, but is needed for communication
|
||||||
-- from the systemd inside a container to the one outside, so make sure it
|
-- from the systemd inside a container to the one outside, so make sure it
|
||||||
|
@ -67,9 +65,12 @@ persistentJournal = check (not <$> doesDirectoryExist dir) $
|
||||||
-- | Defines a container with a given machine name, containing the specified
|
-- | Defines a container with a given machine name, containing the specified
|
||||||
-- System. Properties can be added to configure the Container.
|
-- System. Properties can be added to configure the Container.
|
||||||
--
|
--
|
||||||
-- > container "webserver" (System (Debian Unstable) "amd64") []
|
-- > container "webserver" (System (Debian Unstable) "amd64")
|
||||||
container :: MachineName -> System -> [NspawnParam] -> Container
|
-- > & Apt.installedRunning "apache2"
|
||||||
container name system ps = Container name system ps (Host name [] mempty)
|
-- > & ...
|
||||||
|
container :: MachineName -> System -> Container
|
||||||
|
container name system = Container name system (Host name [] mempty)
|
||||||
|
& os system
|
||||||
|
|
||||||
-- | Runs a container using systemd-nspawn.
|
-- | Runs a container using systemd-nspawn.
|
||||||
--
|
--
|
||||||
|
@ -86,7 +87,7 @@ container name system ps = Container name system ps (Host name [] mempty)
|
||||||
-- Reverting this property stops the container, removes the systemd unit,
|
-- Reverting this property stops the container, removes the systemd unit,
|
||||||
-- and deletes the chroot and all its contents.
|
-- and deletes the chroot and all its contents.
|
||||||
nspawned :: Container -> RevertableProperty
|
nspawned :: Container -> RevertableProperty
|
||||||
nspawned c@(Container name system _ h) = RevertableProperty setup teardown
|
nspawned c@(Container name system h) = RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
setup = combineProperties ("nspawned " ++ name) $
|
setup = combineProperties ("nspawned " ++ name) $
|
||||||
map toProp steps ++ [containerprovisioned]
|
map toProp steps ++ [containerprovisioned]
|
||||||
|
@ -114,7 +115,7 @@ nspawned c@(Container name system _ h) = RevertableProperty setup teardown
|
||||||
chroot = mkChroot h
|
chroot = mkChroot h
|
||||||
|
|
||||||
nspawnService :: Container -> RevertableProperty
|
nspawnService :: Container -> RevertableProperty
|
||||||
nspawnService (Container name _ ps _) = RevertableProperty setup teardown
|
nspawnService (Container name _ _) = RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
service = nspawnServiceName name
|
service = nspawnServiceName name
|
||||||
servicefile = "/etc/systemd/system/multi-user.target.wants" </> service
|
servicefile = "/etc/systemd/system/multi-user.target.wants" </> service
|
||||||
|
@ -122,7 +123,6 @@ nspawnService (Container name _ ps _) = RevertableProperty setup teardown
|
||||||
setup = check (not <$> doesFileExist servicefile) $
|
setup = check (not <$> doesFileExist servicefile) $
|
||||||
started service
|
started service
|
||||||
`requires` enabled service
|
`requires` enabled service
|
||||||
-- TODO ^ adjust execStart line to reflect ps
|
|
||||||
|
|
||||||
teardown = undefined
|
teardown = undefined
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ nspawnService (Container name _ ps _) = RevertableProperty setup teardown
|
||||||
-- This uses nsenter to enter the container, by looking up the pid of the
|
-- This uses nsenter to enter the container, by looking up the pid of the
|
||||||
-- container's init process and using its namespace.
|
-- container's init process and using its namespace.
|
||||||
enterScript :: Container -> RevertableProperty
|
enterScript :: Container -> RevertableProperty
|
||||||
enterScript c@(Container name _ _ _) = RevertableProperty setup teardown
|
enterScript c@(Container name _ _) = RevertableProperty setup teardown
|
||||||
where
|
where
|
||||||
setup = combineProperties ("generated " ++ enterScriptFile c)
|
setup = combineProperties ("generated " ++ enterScriptFile c)
|
||||||
[ scriptfile `File.hasContent`
|
[ scriptfile `File.hasContent`
|
||||||
|
@ -152,7 +152,7 @@ enterScript c@(Container name _ _ _) = RevertableProperty setup teardown
|
||||||
scriptfile = enterScriptFile c
|
scriptfile = enterScriptFile c
|
||||||
|
|
||||||
enterScriptFile :: Container -> FilePath
|
enterScriptFile :: Container -> FilePath
|
||||||
enterScriptFile (Container name _ _ _ ) = "/usr/local/bin/enter-" ++ mungename name
|
enterScriptFile (Container name _ _ ) = "/usr/local/bin/enter-" ++ mungename name
|
||||||
|
|
||||||
enterContainerProcess :: Container -> [String] -> CreateProcess
|
enterContainerProcess :: Container -> [String] -> CreateProcess
|
||||||
enterContainerProcess = proc . enterScriptFile
|
enterContainerProcess = proc . enterScriptFile
|
||||||
|
|
Loading…
Reference in New Issue