This a Rocket based HTTP server used to serve static content.
Why?
Over the years I've written way too many small http servers just to try something out with static content. At some point I realized I should just write a simple server and reuse it, but the code is so simple that making it its own project felt like overkill. One day I needed to install such a small http server as a Windows service and suddenly it was worth creating this project.
Build and run as a regular foreground process
Update Rocket.toml
as appropriate and run:
cargo run
Windows Service Installation/Uninstallation
First build the server binary:
> cargo build --release
The resulting binary (staticrocket.exe
) will be statically linked against the
CRT, so there should be no need to install vcredist or other dependencies.
In this example, for purposes of illustration, we'll assume the target binary
is copied to C:\Temp\staticrocket.exe
.
Next create a runtime directory for the server. This is the directory that
staticrocket will switch to when it starts up and where it expects to find
the Rocket.toml
configuration file. Note that this this shouldn't be the
static content directory being served. We'll use C:\Temp\myservice
as an
example.
Run the subcommand make-config
to create a default configuration file:
> mkdir C:\Temp\myservice
> cd C:\Temp\myservice
> C:\Temp\staticrocket.exe make-config
This will create a Rocket.toml
in the curent directory.
Change the configuration parameters as appropriate. In particular, change the
htdocs
to point to the directory that will be served by staticrocket, and
create this directory if it does not exist.
Before registering the service, make sure you're in the service's runtime directory:
> cd C:\Temp\myservce
Register the service, using an elevated command prompt, by running:
> C:\Temp\staticrocket.exe register-service --name StaticRocket --display-name "Static Rocket" --description "Rocket HTTP server sharing static content" --auto-start
Registering the service will not start the service, though it is configured to autostart on boot.
In the service's registry section there's a Parameters
subkey which contains
the WorkDir
and LogLevel
parameters. The WorkDir
is the directory from
which the web server service will start; the Rocket.toml
should be located
in this directory. It will default to the directory the register-service
subcommand was run from. The LogLevel
have the same function as the one's in
Rocket.toml
, but the one in the registry must be used for Windows services.
To uninstall the service use the deregister-service
subcommand in an elevated
command prompt:
> C:\Temp\staticrocket.exe deregister-service --name StaticRocket
Linux/systemd Service Installation
Note: This does not currently work due to qsu being incomplete
Running with the first argument as register-service
and the second as unit
name will create a unit file for you in /etc/systemd/system
.
Assuming the staticrocket
binary has been been built and copied to
/usr/local/bin/staticrocket
running:
$ sudo /usr/local/bin/staticrocket register-service mystaticcontent
.. will install a systemd unit file in
/etc/systemd/system/mystaticcontent.service
. The command should be run from
the directory where the application instance's Rocket.toml
resides.
The service will neither be started nor enabled. To make it automatically start on boot run:
$ sudo systemctl enable mystaticcontent.service
To start it immediately run:
$ sudo systemctl start mystaticcontent.service
There's no corresponding deregister-service
. To uninstall: stop, disable and
remove the unit:
$ sudo systemctl stop mystaticcontent.service
$ sudo systemctl disable mystaticcontent.service
$ sudo rm /etc/systemd/system/mystaticcontent.service