diff --git a/deb/vpncloud/debian/vpncloud.default b/deb/vpncloud/debian/vpncloud.default index b1d349b..b805940 100644 --- a/deb/vpncloud/debian/vpncloud.default +++ b/deb/vpncloud/debian/vpncloud.default @@ -1 +1,4 @@ +# Warning: This file is ignored on systemd systems +# Please use instantiated services (vpncloud@NAME) instead + NETWORKS="default" diff --git a/deb/vpncloud/example.net.disabled b/deb/vpncloud/example.net.disabled index cf686f7..a86a1ff 100644 --- a/deb/vpncloud/example.net.disabled +++ b/deb/vpncloud/example.net.disabled @@ -1,5 +1,12 @@ # This configuration file uses the YAML format. +# This configuration can be enabled/disabled and controlled by adding the +# network to `/etc/default/vpncloud` and starting/stopping it via +# `/etc/init.d/vpncloud start/stop` on non-systemd systems and via +# `systemctl enable/disable vpncloud@NAME` and +# `service vpncloud@NAME start/stop` on systemd systems. + + # The port number on which to listen for data. # Note: Every VPN needs a different port number. #port: 3210 @@ -68,3 +75,14 @@ # The name of the allocated device will be available via the environment # variable `IFNAME`. #ifdown: "" + +# Store the process id in this file when running in the background. If set, +# the given file will be created containing the process id of the new +# background process. This option is only used when running in background. +#pid_file: "" + +# Change the user and/or group of the process once all the setup has been +# done and before spawning the background process. This option is only used +# when running in background. +#user: "" +#group: "" diff --git a/src/main.rs b/src/main.rs index d1da5c7..ee7248c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,7 @@ impl log::Log for DualLogger { if self.enabled(record.metadata()) { println!("{} - {}", record.level(), record.args()); let mut file = self.file.lock().expect("Lock poisoned"); - if let &mut Some(ref mut file) = &mut file as &mut Option { + if let Some(ref mut file) = *file { let time = time::strftime("%F %T", &time::now()).expect("Failed to format timestamp"); writeln!(file, "{} - {} - {}", time, record.level(), record.args()).expect("Failed to write to logfile"); } diff --git a/src/tests.rs b/src/tests.rs index 88e0467..f975e68 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -412,6 +412,9 @@ mode: normal subnets: - 10.0.1.0/24 port_forwarding: true +user: nobody +group: nogroup +pid_file: /run/vpncloud.run "; assert_eq!(configfile::parse_str::(config_file).unwrap(), ConfigFile{ device_type: Some(Type::Tun), @@ -427,7 +430,10 @@ port_forwarding: true mode: Some(Mode::Normal), dst_timeout: None, subnets: Some(vec!["10.0.1.0/24".to_string()]), - port_forwarding: Some(true) + port_forwarding: Some(true), + user: Some("nobody".to_string()), + group: Some("nogroup".to_string()), + pid_file: Some("/run/vpncloud.run".to_string()) }) } @@ -448,7 +454,10 @@ fn config_merge() { mode: Some(Mode::Normal), dst_timeout: None, subnets: Some(vec!["10.0.1.0/24".to_string()]), - port_forwarding: None + port_forwarding: None, + user: Some("nobody".to_string()), + group: Some("nogroup".to_string()), + pid_file: Some("/run/vpncloud.run".to_string()) }); assert_eq!(config, Config{ device_type: Type::Tun, @@ -461,6 +470,9 @@ fn config_merge() { peer_timeout: 1800, mode: Mode::Normal, subnets: vec!["10.0.1.0/24".to_string()], + user: Some("nobody".to_string()), + group: Some("nogroup".to_string()), + pid_file: Some("/run/vpncloud.run".to_string()), ..Default::default() }); config.merge_args(Args{ @@ -482,6 +494,9 @@ fn config_merge() { peer_timeout: 1800, mode: Mode::Normal, subnets: vec!["10.0.1.0/24".to_string()], + user: Some("nobody".to_string()), + group: Some("nogroup".to_string()), + pid_file: Some("/run/vpncloud.run".to_string()), ..Default::default() }); }