First commit

This commit is contained in:
Gaetan Longree
2018-05-11 15:51:48 +02:00
commit 4411d5800e
87 changed files with 6573 additions and 0 deletions

View File

@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 2.8.9)
if (NOT DEFINED ENV{INCLUDEOS_PREFIX})
set(ENV{INCLUDEOS_PREFIX} /usr/local)
endif()
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
project (WebServer)
# Human-readable name of your service
set(SERVICE_NAME "CETIC Unikernel Web Server")
# Name of your service binary
set(BINARY "WebServer")
# Source files to be linked with OS library parts to form bootable image
set(SOURCES
service.cpp # ...add more here
)
# To add your own include paths:
# set(LOCAL_INCLUDES ".")
# DRIVERS / PLUGINS:
set(DRIVERS
virtionet # Virtio networking
)
set(PLUGINS
autoconf
)
# STATIC LIBRARIES:
set(LIBRARIES
# path to full library
)
# include service build script
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)
# Create in-memory filesystem from folder
diskbuilder(disk)

View File

@ -0,0 +1,7 @@
#!/bin/bash
mkdir -p build
pushd build
cmake ..
make
popd

View File

@ -0,0 +1,13 @@
{
"net": [
{
"iface": 0,
"config": "static",
"address": "10.0.0.5",
"netmask": "255.255.255.0",
"gateway": "10.0.0.254"
}
]
}

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CETIC Internship Unikernel Web Page</title>
<link href="https://fonts.googleapis.com/css?family=Ubuntu:500,300" rel="stylesheet" type="text/css">
</head>
<body>
<h1 style="font-family: Arial, sans-serif">
CETIC Internship Unikernel Web Page
</h1>
<hr />
<p>This is the first web server spawn from a unikernel during the CETIC Intership 2017-18</p>
</body>
</html>

View File

@ -0,0 +1,47 @@
/*
* This code is adapted from the IncludeOS Acorn web server example.
*/
#include <service>
#include <net/inet4>
#include <net/http/server.hpp>
#include <memdisk>
std::unique_ptr<http::Server> server;
void Service::start()
{
// Retreive the stack (configured from outside)
auto& inet = net::Inet4::stack<0>();
Expects(inet.is_configured());
// Init the memdisk
auto& disk = fs::memdisk();
disk.init_fs([] (auto err, auto&) {
Expects(not err);
});
// Retreive the HTML page from the disk
auto file = disk.fs().read_file("/index.html");
Expects(file.is_valid());
net::tcp::buffer_t html(
new std::vector<uint8_t> (file.data(), file.data() + file.size()));
// Create a HTTP Server and setup request handling
server = std::make_unique<http::Server>(inet.tcp());
server->on_request([html] (auto req, auto rw)
{
// We only support get
if(req->method() != http::GET) {
rw->write_header(http::Not_Found);
return;
}
// Serve HTML on /
if(req->uri() == "/") {
rw->write(html);
} else {
rw->write_header(http::Not_Found);
}
});
// Start listening on port 80
server->listen(80);
}