Skip to content

Commit c269c9d

Browse files
committed
feat: Starting work on daemon process
1 parent 294af62 commit c269c9d

File tree

9 files changed

+95
-4
lines changed

9 files changed

+95
-4
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Branches
1+
name: Main
22

33
on:
44
push:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ target
33
Cargo.lock
44
assets
55

6-
# firecracker
6+
firecracker
77
tmp
88
logs
99
todo

Cargo.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22
authors = ["Andrei Sousa <sousandrei@gmail.com>"]
33
edition = "2018"
44
name = "firesquid"
5+
readme = "README.md"
56
version = "0.1.0"
67

8+
9+
[package.metadata.deb]
10+
assets = [
11+
["target/release/firesquid", "usr/bin/firesquid", "755"],
12+
[
13+
"debian/firesquid.service",
14+
"/lib/systemd/system/firesquid.service",
15+
"644",
16+
],
17+
]
18+
depends = "$auto, systemd"
19+
extended-description = "firesquid daemon"
20+
maintainer-scripts = "debian/scripts"
21+
priority = "optional"
22+
section = "admin"
23+
724
[dependencies]
825
chrono = "0.4.19"
926
clap = { version = "2.33.3", features = ["yaml"] }
1027
hyper = { version = "0.14.4", features = ["client", "server", "stream", "http1", "tcp"] }
11-
hyperlocal = { version = "0.8" }
28+
hyperlocal = "0.8"
1229
serde = { version = "1.0.123", features = ["derive"] }
1330
serde_json = "1.0.63"
1431
tokio = { version = "1.2.0", features = [

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<br />
1515

16-
[![Build Status](https://github.com/sousandrei/firesquid/workflows/Branches/badge.svg)](https://github.com/sousandrei/firesquid/actions)
16+
[![Build Status](https://github.com/sousandrei/firesquid/workflows/Main/badge.svg)](https://github.com/sousandrei/firesquid/actions)
1717

1818
## Table of Contents
1919

@@ -36,6 +36,12 @@ It abstracts the hard part making it a breeze to spawn your very own fleet of mi
3636
- Lightweight
3737
- Customizable
3838

39+
Upcoming:
40+
41+
- Networking
42+
- Proper package release and distribution
43+
- Choices between which kernel to use for which machine
44+
3945
## <a name="help-wanted"></a> Assets 📦
4046

4147
Here are some assets to get you started. The default folder for assets is just called `assets` in the same folder as FireSquid.

debian/firesquid.service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
AssertPathExists=/usr/bin/firesquid
3+
4+
[Service]
5+
WorkingDirectory=~
6+
ExecStart=/usr/bin/firesquid
7+
Restart=always
8+
PrivateTmp=true
9+
NoNewPrivileges=true
10+
11+
[Install]
12+
Alias=firesquid
13+
WantedBy=default.target

debian/scripts/postinst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
## This will only remove masks created by d-s-h on package removal.
4+
deb-systemd-helper unmask firesquid.service > /dev/null || true
5+
6+
# was-enabled defaults to true, so new installations run enable.
7+
if deb-systemd-helper --quiet was-enabled firesquid.service
8+
then
9+
# Enables the unit on first installation, creates new
10+
# symlinks on upgrades if the unit file has changed.
11+
deb-systemd-helper enable firesquid.service > /dev/null || true
12+
deb-systemd-invoke start firesquid
13+
else
14+
# Update the statefile to add new symlinks (if any), which need to be
15+
# cleaned up on purge. Also remove old symlinks.
16+
deb-systemd-helper update-state firesquid.service > /dev/null || true
17+
fi

debian/scripts/postrm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# In case this system is running systemd, we make systemd reload the unit files
4+
# to pick up changes.
5+
if [ -d /run/systemd/system ] ; then
6+
systemctl --system daemon-reload >/dev/null || true
7+
fi
8+
9+
if [ "$1" = "remove" ]; then
10+
if [ -x "/usr/bin/deb-systemd-helper" ]; then
11+
deb-systemd-helper mask firesquid.service >/dev/null
12+
fi
13+
fi

debian/scripts/prerm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
deb-systemd-invoke stop firesquid

src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ mod vm;
1818
use crate::cli::generate_cli;
1919
use crate::state::{State, StatePtr};
2020

21+
use std::fs;
22+
use std::path;
23+
2124
#[tokio::main]
2225
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2326
if env::var("RUST_LOG").is_err() {
@@ -26,6 +29,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2629

2730
tracing_subscriber::fmt::init();
2831

32+
//TODO: better way of finding out if it's being run by system
33+
if !path::Path::new("/tmp/firesquid/lock.pid").exists() {
34+
start_daemon().await?;
35+
return Ok(());
36+
}
37+
38+
println!("CLI GOES HERE");
39+
40+
Ok(())
41+
}
42+
43+
async fn start_daemon() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
44+
info!("Creating lock file");
45+
fs::create_dir("/tmp/firesquid").ok();
46+
fs::File::create("/tmp/firesquid/lock.pid").ok();
47+
2948
let cli_options = match generate_cli() {
3049
Ok(options) => options,
3150
Err(e) => return Err(e),
@@ -75,6 +94,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
7594

7695
terminate_all_vms(state_ptr).await;
7796

97+
info!("Removing lock file");
98+
fs::remove_file("/tmp/firesquid/lock.pid").ok();
99+
78100
Ok(())
79101
}
80102

0 commit comments

Comments
 (0)