Skip to content

Commit 8cec80d

Browse files
committed
feat: add systemd service and user creation
1 parent 2508217 commit 8cec80d

6 files changed

Lines changed: 30 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ edition = "2024"
1212
[package.metadata.generate-rpm]
1313
assets = [
1414
{ source = "target/release/bec_log_ingestor", dest = "/usr/local/bin/bec_log_ingestor", mode = "755" },
15+
{ source = "install/bec_log_ingestor.service", dest = "/lib/systemd/system/bec_log_ingestor.service", mode = "755" },
1516
]
17+
pre_install_script = "install/setup_user"
18+
pre_install_script_prog = ["/bin/bash"]
19+
pre_install_script_flags = 0b100
1620

1721
[dependencies]
1822
chrono = "0.4.41"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Tiny service to pull BEC logs from Redis and push them to Elastic.
66

7+
To use the systemd service as-is, a config should be created at `/etc/bec_log_ingestor.toml`, following the example in `install/example_config.toml`.
8+
79
Published RPM packages are signed by PGP, the corresponding public key is:
810

911
```

install/bec_log_ingestor.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=bec-log-ingestor service
3+
4+
[Service]
5+
Type=oneshot
6+
RemainAfterExit=yes
7+
User=bec_log_ingestor
8+
ExecStart=/usr/local/bin/bec_log_ingestor -c /etc/bec_log_ingestor.toml
9+
Restart=on-failure
10+
RestartSec=5
11+
StartLimitBurst=3
12+
StartLimitIntervalSec=120
13+
14+
[Install]
15+
WantedBy=multi-user.target

install/setup_user

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Create the user 'bec_log_ingestor' if it does not exist
2+
if id "bec_log_ingestor" &>/dev/null; then
3+
echo "User 'bec_log_ingestor' already exists."
4+
else
5+
useradd --system --create-home --shell /bin/bash bec_log_ingestor
6+
echo "User 'bec_log_ingestor' created."
7+
fi

src/elastic_push.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ fn json_from_logmsg(
2121
msg: &LogMsg,
2222
config: &ElasticConfig,
2323
) -> Result<serde_json::Value, serde_json::Error> {
24-
// dbg!(serde_json::to_value(record))
25-
dbg!(Ok(serde_json::json!({
24+
Ok(serde_json::json!({
2625
"@timestamp": msg.record.time.as_rfc3339(),
2726
"file": msg.record.file,
2827
"function": msg.record.function,
@@ -34,7 +33,7 @@ fn json_from_logmsg(
3433
"beamline_name": config.beamline_name,
3534
"proc_id": msg.record.process.id,
3635
"exception": msg.record.exception,
37-
})))
36+
}))
3837
}
3938

4039
fn make_json_body(

0 commit comments

Comments
 (0)