Commit 3141296 1 parent 345261a commit 3141296 Copy full SHA for 3141296
File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
+ default-run = " torrust-tracker"
2
3
name = " torrust-tracker"
3
4
readme = " README.md"
4
5
Original file line number Diff line number Diff line change
1
+ //! Minimal `curl` or `wget` to be used for container health checks.
2
+ //!
3
+ //! It's convenient to avoid using third-party libraries because:
4
+ //!
5
+ //! - They are harder to maintain.
6
+ //! - They introduce new attack vectors.
7
+ use std:: { env, process} ;
8
+
9
+ #[ tokio:: main]
10
+ async fn main ( ) {
11
+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
12
+ if args. len ( ) != 2 {
13
+ eprintln ! ( "Usage: cargo run --bin health_check <HEALTH_URL>" ) ;
14
+ eprintln ! ( "Example: cargo run --bin http_health_check http://localhost:1212/api/v1/stats?token=MyAccessToken" ) ;
15
+ std:: process:: exit ( 1 ) ;
16
+ }
17
+
18
+ println ! ( "Health check ..." ) ;
19
+
20
+ let url = & args[ 1 ] . clone ( ) ;
21
+
22
+ match reqwest:: get ( url) . await {
23
+ Ok ( response) => {
24
+ if response. status ( ) . is_success ( ) {
25
+ println ! ( "STATUS: {}" , response. status( ) ) ;
26
+ process:: exit ( 0 ) ;
27
+ } else {
28
+ println ! ( "Non-success status received." ) ;
29
+ process:: exit ( 1 ) ;
30
+ }
31
+ }
32
+ Err ( err) => {
33
+ println ! ( "ERROR: {err}" ) ;
34
+ process:: exit ( 1 ) ;
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments