-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
install: | ||
cp dist/build/GHCiOnline/GHCiOnline /opt/ghc-online/ghci-online | ||
cp -r static/ /opt/ghc-online/ | ||
cp prod.env /etc/conf.d/ghci-online | ||
cp systemd/*.service /etc/systemd/system/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: /opt/ghc-online/ghci-online |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CJAIL_PATH=/opt/ghc-online/jail/ | ||
|
||
GHCI_PATH=/usr/bin/ghci-safe | ||
GHCI_ARGS=-XSafe, -fpackage-trust, -distrust-all-packages, -trust base | ||
|
||
HTML_ROOT=/opt/ghc-online/static/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- | State associated with user or application. | ||
module State ( | ||
GHCiHandle, GhciState(..), ClientState(..), initState | ||
) where | ||
|
||
import CJail.System.Process | ||
import Control.Concurrent.MVar | ||
import Data.Functor | ||
import Data.List | ||
import qualified Data.IntMap as I | ||
import System.Environment | ||
|
||
import Sessions | ||
import qualified Timeout as T | ||
|
||
type GHCiHandle = ProcessHandle | ||
|
||
-- global application state. | ||
data GhciState = GhciState { | ||
gsClients :: Session ClientState, | ||
gsTimeout :: T.Manager, | ||
gsCJail :: CJailConf, | ||
gsGhciPath :: FilePath, | ||
gsGhciArgs :: [String], | ||
gsHtmlRoot :: String | ||
} | ||
|
||
-- Session data for a single user. | ||
data ClientState = ClientState { | ||
csGhci :: GHCiHandle, | ||
csTout :: T.Handle | ||
} | ||
|
||
initState :: IO GhciState | ||
initState = do | ||
st <- newMVar I.empty | ||
tm <- T.initialize (15 * 1000000) | ||
cjailPath <- getEnv "CJAIL_PATH" | ||
let cj = CJailConf Nothing Nothing cjailPath | ||
ghciPath <- getEnv "GHCI_PATH" | ||
ghciArgs <- splitOn ',' <$> getEnv "GHCI_ARGS" | ||
htmlRoot <- getEnv "HTML_ROOT" | ||
|
||
putStrLn $ "CJAIL_PATH: " ++ cjailPath | ||
putStrLn $ "GHCI_PATH: " ++ ghciPath | ||
putStrLn $ "GHCI_ARGS: " ++ show ghciArgs | ||
putStrLn $ "HTML_ROOT: " ++ htmlRoot | ||
|
||
return $ GhciState st tm cj ghciPath ghciArgs htmlRoot | ||
|
||
splitOn :: Eq a => a -> [a] -> [[a]] | ||
splitOn chr = unfoldr sep where | ||
sep [] = Nothing | ||
sep l = Just . fmap (drop 1) . break (==chr) $ l | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Setup CJail on the machine. | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/cjail --init | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=GHCiOnline Web App | ||
After=network.target cjail.service | ||
|
||
[Service] | ||
Type=simple | ||
EnvironmentFile=/etc/conf.d/ghci-online | ||
ExecStart=/opt/ghc-online/ghci-online | ||
Restart=on-abort | ||
#User=ghcio | ||
|
||
[Install] | ||
WantedBy=multi-user.target |