diff --git a/Cargo.toml b/Cargo.toml index d92e2bd..d185013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,25 @@ license = "MITNFA" description = "Controls Tesla charge rate based on solar charge data" authors = ["Alex Janka"] +[lib] +name = "common" +path = "src/lib/lib.rs" + +[[bin]] +name = "tesla-charge-controller" +path = "src/bins/tesla/main.rs" + +[[bin]] +name = "charge-controller-supervisor" +path = "src/bins/controllers/main.rs" + [package.metadata.deb] -maintainer-scripts = "debian/" -systemd-units = { enable = false } +maintainer-scripts = "pkg/debian/" +systemd-units = [ + { unit-name = "tesla-charge-controller", unit-scripts = "pkg/systemd/", enable = false }, + { unit-name = "charge-controller-supervisor", unit-scripts = "pkg/systemd/", enable = false }, +] depends = "" -assets = [["target/release/tesla-charge-controller", "usr/bin/", "755"]] [dependencies] tesla-common = { git = "https://git.alexjanka.com/alex/tesla-common" } diff --git a/pkg/debian/.empty b/pkg/debian/.empty new file mode 100644 index 0000000..e69de29 diff --git a/pkg/systemd/charge-controller-supervisor.service b/pkg/systemd/charge-controller-supervisor.service new file mode 100644 index 0000000..2888638 --- /dev/null +++ b/pkg/systemd/charge-controller-supervisor.service @@ -0,0 +1,16 @@ +[Unit] +Description=Charge Controller Supervisor +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=10s +User=tesla +Environment="RUST_LOG=error,warn" +Environment="LOG_TIMESTAMP=false" +ExecStart=/usr/bin/charge-controller-supervisor watch + +[Install] +WantedBy=multi-user.target diff --git a/debian/service b/pkg/systemd/tesla-charge-controller.service similarity index 86% rename from debian/service rename to pkg/systemd/tesla-charge-controller.service index f87a991..ec46a78 100644 --- a/debian/service +++ b/pkg/systemd/tesla-charge-controller.service @@ -1,6 +1,7 @@ [Unit] Description=Tesla Charge Controller After=network.target +Requires=charge-controller-supervisor.service StartLimitIntervalSec=0 [Service] diff --git a/src/bins/controllers/main.rs b/src/bins/controllers/main.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/src/bins/controllers/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/src/bins/tesla/main.rs b/src/bins/tesla/main.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/src/bins/tesla/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/src/api_interface.rs b/src/lib/api_interface.rs similarity index 100% rename from src/api_interface.rs rename to src/lib/api_interface.rs diff --git a/src/api_interface/http.rs b/src/lib/api_interface/http.rs similarity index 100% rename from src/api_interface/http.rs rename to src/lib/api_interface/http.rs diff --git a/src/charge_controllers/gauges.rs b/src/lib/charge_controllers/gauges.rs similarity index 100% rename from src/charge_controllers/gauges.rs rename to src/lib/charge_controllers/gauges.rs diff --git a/src/charge_controllers/mod.rs b/src/lib/charge_controllers/mod.rs similarity index 100% rename from src/charge_controllers/mod.rs rename to src/lib/charge_controllers/mod.rs diff --git a/src/charge_controllers/pl.rs b/src/lib/charge_controllers/pl.rs similarity index 100% rename from src/charge_controllers/pl.rs rename to src/lib/charge_controllers/pl.rs diff --git a/src/charge_controllers/tristar.rs b/src/lib/charge_controllers/tristar.rs similarity index 100% rename from src/charge_controllers/tristar.rs rename to src/lib/charge_controllers/tristar.rs diff --git a/src/config.rs b/src/lib/config.rs similarity index 100% rename from src/config.rs rename to src/lib/config.rs diff --git a/src/errors.rs b/src/lib/errors.rs similarity index 100% rename from src/errors.rs rename to src/lib/errors.rs diff --git a/src/main.rs b/src/lib/lib.rs similarity index 100% rename from src/main.rs rename to src/lib/lib.rs diff --git a/src/server/mod.rs b/src/lib/server/mod.rs similarity index 100% rename from src/server/mod.rs rename to src/lib/server/mod.rs diff --git a/src/server/static_handler.rs b/src/lib/server/static_handler.rs similarity index 100% rename from src/server/static_handler.rs rename to src/lib/server/static_handler.rs diff --git a/src/tesla_charge_rate.rs b/src/lib/tesla_charge_rate.rs similarity index 100% rename from src/tesla_charge_rate.rs rename to src/lib/tesla_charge_rate.rs diff --git a/src/types.rs b/src/lib/types.rs similarity index 100% rename from src/types.rs rename to src/lib/types.rs