Skip to content

Commit ae04c4a

Browse files
author
loki
committed
Gracefully exit when stopped by systemd or pkill
1 parent e8fadd2 commit ae04c4a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

sunshine/main.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,33 @@ int main(int argc, char *argv[]) {
187187
return fn->second(argv[0], config::sunshine.cmd.argc, config::sunshine.cmd.argv);
188188
}
189189

190+
task_pool.start(1);
191+
190192
// Create signal handler after logging has been initialized
191193
auto shutdown_event = mail::man->event<bool>(mail::shutdown);
192194
on_signal(SIGINT, [shutdown_event]() {
193195
BOOST_LOG(info) << "Interrupt handler called"sv;
194196

197+
task_pool.pushDelayed([]() {
198+
BOOST_LOG(fatal) << "10 seconds passed, yet Sunshine's still running: Forcing shutdown"sv;
199+
log_flush();
200+
std::abort();
201+
},
202+
10s);
203+
204+
shutdown_event->raise(true);
205+
});
206+
207+
on_signal(SIGTERM, [shutdown_event]() {
208+
BOOST_LOG(info) << "Terminate handler called"sv;
209+
210+
task_pool.pushDelayed([]() {
211+
BOOST_LOG(fatal) << "10 seconds passed, yet Sunshine's still running: Forcing shutdown"sv;
212+
log_flush();
213+
std::abort();
214+
},
215+
10s);
216+
195217
shutdown_event->raise(true);
196218
});
197219

@@ -226,8 +248,6 @@ int main(int argc, char *argv[]) {
226248
return 0;
227249
}
228250

229-
task_pool.start(1);
230-
231251
std::thread httpThread { nvhttp::start };
232252
std::thread configThread { confighttp::start };
233253

0 commit comments

Comments
 (0)