1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Process start-up, in the one order that works.
use Future;
use Shutdown;
/// Runs `body` with observability, a runtime, and signal handling set up.
///
/// The ordering is the point: observability on the main thread first (so the
/// Sentry hub reaches the runtime's workers), then the runtime, then one signal
/// listener whose [`Shutdown`] handle is passed to `body`, then the guard drops
/// after `body` returns — flushing errors raised during the shutdown itself.
///
/// The application still owns `main`, so it can start as many servers as it
/// likes.
///
/// It also owns the build-tool subcommands, so no project has to declare a
/// second binary or write a line of glue to reach them:
///
/// ```text
/// $ my-server gen-static-assets # icons, then hash everything but scripts
/// $ my-server gen-static-scripts # hash the built JavaScript
/// $ my-server # serve
/// ```
///
/// Those two exit before any runtime or error monitoring starts. They still
/// read `WSB_ENVIRONMENT`, because `main` resolves it before calling in — set
/// it to `local` in the build stage.
///
/// ```no_run
/// use webserver_base::{WebServer, WebServerError, bootstrap};
///
/// fn main() -> Result<(), WebServerError> {
/// bootstrap!(|shutdown| async move { WebServer::from_env()?.run(shutdown).await })
/// }
/// ```
///
/// # Errors
///
/// Whatever `body` returns. `bootstrap` adds no failure of its own.
///
/// # Panics
///
/// If the Tokio runtime cannot be built. There is no useful way to continue,
/// and no server to report it to yet.
/// Starts a server, naming the running build from the *calling* crate.
///
/// A macro rather than a function because the release string has to come from
/// the application's own `CARGO_PKG_NAME` and `CARGO_PKG_VERSION`, and those are
/// resolved where the code is written. Called from inside this library — as
/// `sentry::release_name!()` does — every project would report the same
/// release, and Sentry could not tell one site's deploys from another's.
///
/// ```no_run
/// use webserver_base::{WebServer, WebServerError, bootstrap};
///
/// fn main() -> Result<(), WebServerError> {
/// bootstrap!(|shutdown| async move { WebServer::from_env()?.run(shutdown).await })
/// }
/// ```