Browse Source

Merge pull request 'debian-packaging' (#1) from debian-packaging into master

Reviewed-on: #1
master
stephen 6 months ago
parent
commit
c6dd2b2efe
6 changed files with 71 additions and 9 deletions
  1. +20
    -2
      Cargo.toml
  2. +4
    -4
      Jenkinsfile
  3. +9
    -0
      debian/config.toml
  4. +1
    -0
      debian/maintainer_scripts/postinst
  5. +14
    -0
      debian/proxy-manager.service
  6. +23
    -3
      src/main.rs

+ 20
- 2
Cargo.toml View File

@ -1,8 +1,9 @@
[package]
name = "proxy_manager"
version = "0.1.0"
authors = ["Stephen D"]
authors = ["Stephen D <@stephen:m.scd31.com>"]
edition = "2018"
description = "Manages web proxies across different projects/processes"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -12,4 +13,21 @@ serde = { version = "1.0", features = ["derive"] }
chrono = "0.4.15"
warp = "0.2"
tokio = { version = "0.2", features = ["macros"] }
rand = "0.7.3"
rand = "0.7.3"
[package.metadata.deb]
maintainer = "Stephen D <@stephen:m.scd31.com>"
copyright = "2020, Stephen D <@stephen:m.scd31.com>"
extended-description = """\
Manages web proxies across different projects/processes
"""
depends = "systemd"
section = "utility"
priority = "optional"
assets = [
["target/release/proxy_manager", "usr/bin/", "755"],
["debian/proxy-manager.service", "/lib/systemd/system/proxy-manager.service", "644"],
["debian/config.toml", "/etc/proxy_manager/config.toml", "644"]
]
conf-files = ["/etc/proxy_manager/config.toml"]
maintainer-scripts = "debian/maintainer_scripts/"

+ 4
- 4
Jenkinsfile View File

@ -18,17 +18,17 @@ pipeline {
sh "cargo clippy --all-targets --all-features -- -D warnings"
}
}
/*stage('Build') {
stage('Build') {
steps {
sh "cargo install cargo-deb"
sh "cargo deb"
}
}*/
}
}
/*post {
post {
always {
archiveArtifacts artifacts: 'target/debian/*.deb', fingerprint: true
}
}*/
}
}

+ 9
- 0
debian/config.toml View File

@ -0,0 +1,9 @@
proxies = []
[websites]
# [websites.facebook]
# delay = 5 # number of seconds between requests, per proxy
# [websites.google]
# delay = 0 # no delay

+ 1
- 0
debian/maintainer_scripts/postinst View File

@ -0,0 +1 @@
adduser --system proxy-manager

+ 14
- 0
debian/proxy-manager.service View File

@ -0,0 +1,14 @@
[Unit]
Description=Proxy Manager
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
PIDFile=/run/proxy-manager.pid
ExecStart=/usr/bin/proxy_manager
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
User=proxy-manager
[Install]
WantedBy=multi-user.target

+ 23
- 3
src/main.rs View File

@ -40,9 +40,18 @@ struct ServerState {
async fn main() {
let mut websites: HashMap<String, Arc<Mutex<Website>>> = HashMap::new();
// TODO don't hard-code the file name
let config: Config =
toml::from_str(&fs::read_to_string("config.example.toml").unwrap()).unwrap();
let (filename, file_contents) = read_conf_file();
let config: Config = toml::from_str(&file_contents).unwrap();
// Validate the proxies
if config.proxies.is_empty() {
panic!("No proxies were specified. Edit {} to fix this.", filename);
}
// Validate the websites
if config.websites.is_empty() {
panic!("No websites were specified. Edit {} to fix this.", filename);
}
// Populate the proxies
for (site, site_conf) in &config.websites {
@ -172,3 +181,14 @@ async fn blacklist_proxy_fn(
.into_response()),
}
}
fn read_conf_file() -> (String, String) {
let filenames = ["config.toml", "/etc/proxy_manager/config.toml"];
for filename in filenames.iter() {
if let Ok(x) = fs::read_to_string(filename) {
return (filename.to_string(), x);
}
}
panic!("Could not open config file");
}

Loading…
Cancel
Save