]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/app-template.hh
import quincy beta 17.1.0
[ceph.git] / ceph / src / seastar / include / seastar / core / app-template.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 */
21 #pragma once
22
23 #include <boost/program_options.hpp>
24 #include <functional>
25 #include <seastar/core/future.hh>
26 #include <seastar/core/smp.hh>
27 #include <seastar/core/sstring.hh>
28 #include <seastar/util/program-options.hh>
29 #include <seastar/core/metrics_api.hh>
30 #include <seastar/core/scollectd.hh>
31 #include <seastar/util/log-cli.hh>
32 #include <chrono>
33
34 namespace seastar {
35
36 namespace alien {
37
38 class instance;
39
40 }
41
42 class app_template {
43 public:
44 struct config {
45 /// The name of the application.
46 ///
47 /// Will be used in the --help output to distinguish command line args
48 /// registered by the application, as opposed to those registered by
49 /// seastar and its subsystems.
50 sstring name = "App";
51 /// The description of the application.
52 ///
53 /// Will be printed on the top of the --help output. Lines should be
54 /// hard-wrapped for 80 chars.
55 sstring description = "";
56 std::chrono::duration<double> default_task_quota = std::chrono::microseconds(500);
57 /// \brief Handle SIGINT/SIGTERM by calling reactor::stop()
58 ///
59 /// When true, Seastar will set up signal handlers for SIGINT/SIGTERM that call
60 /// reactor::stop(). The reactor will then execute callbacks installed by
61 /// reactor::at_exit().
62 ///
63 /// When false, Seastar will not set up signal handlers for SIGINT/SIGTERM
64 /// automatically. The default behavior (terminate the program) will be kept.
65 /// You can adjust the behavior of SIGINT/SIGTERM by installing signal handlers
66 /// via reactor::handle_signal().
67 bool auto_handle_sigint_sigterm = true;
68 /// Specifies the default value for linux-aio I/O control blocks. This translates
69 /// to the maximum number of sockets the shard can handle.
70 unsigned max_networking_aio_io_control_blocks = 10000;
71 config() {}
72 };
73
74 /// Seastar configuration options
75 struct seastar_options : public program_options::option_group {
76 /// The name of the application.
77 ///
78 /// Will be used in the --help output to distinguish command line args
79 /// registered by the application, as opposed to those registered by
80 /// seastar and its subsystems.
81 sstring name = "App";
82 /// The description of the application.
83 ///
84 /// Will be printed on the top of the --help output. Lines should be
85 /// hard-wrapped for 80 chars.
86 sstring description = "";
87 /// \brief Handle SIGINT/SIGTERM by calling reactor::stop()
88 ///
89 /// When true, Seastar will set up signal handlers for SIGINT/SIGTERM that call
90 /// reactor::stop(). The reactor will then execute callbacks installed by
91 /// reactor::at_exit().
92 ///
93 /// When false, Seastar will not set up signal handlers for SIGINT/SIGTERM
94 /// automatically. The default behavior (terminate the program) will be kept.
95 /// You can adjust the behavior of SIGINT/SIGTERM by installing signal handlers
96 /// via reactor::handle_signal().
97 bool auto_handle_sigint_sigterm = true;
98 /// Configuration options for the reactor.
99 reactor_options reactor_opts;
100 /// Configuration for the metrics sub-system.
101 metrics::options metrics_opts;
102 /// Configuration options for the smp aspect of seastar.
103 smp_options smp_opts;
104 /// Configuration for the scollectd sub-system.
105 scollectd::options scollectd_opts;
106 /// Configuration for the logging sub-system.
107 log_cli::options log_opts;
108
109 seastar_options();
110 };
111
112 using configuration_reader = std::function<void (boost::program_options::variables_map&)>;
113 private:
114 // unique_ptr to avoid pulling in alien.hh.
115 std::unique_ptr<alien::instance> _alien;
116 // reactor destruction is asynchronous, so we must let the last reactor
117 // destroy the smp instance
118 std::shared_ptr<smp> _smp;
119 seastar_options _opts;
120 boost::program_options::options_description _app_opts;
121 boost::program_options::options_description _seastar_opts;
122 boost::program_options::options_description _opts_conf_file;
123 boost::program_options::positional_options_description _pos_opts;
124 std::optional<boost::program_options::variables_map> _configuration;
125 configuration_reader _conf_reader;
126
127 configuration_reader get_default_configuration_reader();
128 public:
129 struct positional_option {
130 const char* name;
131 const boost::program_options::value_semantic* value_semantic;
132 const char* help;
133 int max_count;
134 };
135 public:
136 explicit app_template(seastar_options opts);
137 explicit app_template(config cfg = config());
138 ~app_template();
139
140 const seastar_options& options() const;
141
142 boost::program_options::options_description& get_options_description();
143 boost::program_options::options_description& get_conf_file_options_description();
144 boost::program_options::options_description_easy_init add_options();
145 void add_positional_options(std::initializer_list<positional_option> options);
146 boost::program_options::variables_map& configuration();
147 int run_deprecated(int ac, char ** av, std::function<void ()>&& func) noexcept;
148
149 void set_configuration_reader(configuration_reader conf_reader);
150
151 /// Obtains an alien::instance object that can be used to send messages
152 /// to Seastar shards from non-Seastar threads.
153 alien::instance& alien() { return *_alien; }
154
155 // Runs given function and terminates the application when the future it
156 // returns resolves. The value with which the future resolves will be
157 // returned by this function.
158 int run(int ac, char ** av, std::function<future<int> ()>&& func) noexcept;
159
160 // Like run() which takes std::function<future<int>()>, but returns
161 // with exit code 0 when the future returned by func resolves
162 // successfully.
163 int run(int ac, char ** av, std::function<future<> ()>&& func) noexcept;
164 };
165
166 }