diff --git a/Cargo.toml b/Cargo.toml index c608da6..03f4d93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ section = "video" assets = [ ["target/release/zealot", "usr/bin/zealot", "755"], ["build/etc/example.toml", "etc/zealot/example.toml", "644"], + ["build/etc/log4rs.yaml", "etc/zealot/log4rs.yaml", "755"], ["README.md", "usr/share/doc/zealot/README", "644"] ] [package.metadata.deb.systemd-units] diff --git a/build/debian/service/adept.service b/build/debian/service/zealot.service similarity index 60% rename from build/debian/service/adept.service rename to build/debian/service/zealot.service index 52e2dea..8e6bef6 100644 --- a/build/debian/service/adept.service +++ b/build/debian/service/zealot.service @@ -4,7 +4,7 @@ Description=Zealot video transcoder service [Service] User=zealot Group=zealot -ExecStart=/usr/bin/zealot +ExecStart=/usr/bin/zealot -l /etc/zealot/log4rs.yaml SuccessExitStatus=143 [Install] diff --git a/build/etc/log4rs.yaml b/build/etc/log4rs.yaml new file mode 100644 index 0000000..3011875 --- /dev/null +++ b/build/etc/log4rs.yaml @@ -0,0 +1,12 @@ +appenders: + stdout: + kind: console + encoder: + pattern: "{d(%+)(utc)} {h({l})}: {m}{n}" + filters: + - kind: threshold + level: info +root: + level: info + appenders: + - stdout diff --git a/build/scripts/postinst b/build/scripts/postinst index 529b87e..1f2728c 100755 --- a/build/scripts/postinst +++ b/build/scripts/postinst @@ -5,6 +5,7 @@ GETENT_GROUP=$(getent group zealot) # Create the zealot user if it doesn't already exist if [ "$GETENT_USER" = "" ]; then + echo "Creating the 'zealot' user." useradd -r zealot else echo "The 'zealot' user already exists, skipping creation." @@ -12,6 +13,7 @@ fi # Create the zealot group if it doesn't already exist if [ "$GETENT_GROUP" = "" ]; then + echo "Creating the 'zealot' group." groupadd zealot usermod -aG zealot zealot else @@ -21,6 +23,15 @@ fi # Change the directory ownership of /etc chown -R zealot:zealot /etc/zealot +# Create the log directory under /var/log +if [ ! -d /var/log/zealot ]; then + echo "Creating /var/log/zealot to store log files." + mkdir /var/log/zealot + chown zealot:zealot /var/log/zealot +else + echo "/var/log/zealot already exists, skipping creation." +fi + #DEBHELPER# exit 0 diff --git a/src/main.rs b/src/main.rs index 93093b6..b275001 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,10 @@ mod util; #[derive(Parser)] #[clap(author, version, about, long_about = None)] struct Cli { + /// Number of times to greet + #[clap(short = 'l', long, default_value_t = String::from("./log4rs.yaml"))] + log_config: String, + #[clap(subcommand)] command: Option, } @@ -23,12 +27,13 @@ enum Commands { } fn main() { - // initialize the log4rs logger - log4rs::init_file("./log4rs.yaml", Default::default()).unwrap(); - // initialize the clap CLI let cli = Cli::parse(); + // grab the log4rs config file path, then initialize log4rs + let log4rs_config: String = cli.log_config; + log4rs::init_file(&log4rs_config, Default::default()).unwrap(); + match &cli.command { // sub-commands will be handled here Some(Commands::Setup {}) => cmd::core::setup_command(),