forge
Explore
Log in

Don't you dare go Hollow

Builder → Server → Process → Restart server (confirm). The server closes every connection with a new 'server restarting' code, drains for up to 2s and execs itself in place (same PID/terminal, picks up a rebuilt binary)

Browse files at this commit

b3f134e795f006408e4609c1ecc5d950e0e14e27Ahmet Kaan GümüşParent: cd8e27c
  • feat
    • Builder → Server → Process → Restart server (confirm). The server closes every connection with a new 'server restarting' code, drains for up to 2s and execs itself in place (same PID/terminal, picks up a rebuilt binary)
    • clients reconnect on their normal backoff. Wire: RestartServer call, Close::Restart, ALPN yumush/5
Show full message
✨ feat: Builder → Server → Process → Restart server (confirm). The server closes every connection with a new 'server restarting' code, drains for up to 2s and execs itself in place (same PID/terminal, picks up a rebuilt binary); clients reconnect on their normal backoff. Wire: RestartServer call, Close::Restart, ALPN yumush/5
crates/client/lang/en/builder_server.txtmodified+3 -0
@@ -23,3 +23,6 @@ rate_limits = Rate limits
23 zero_unlimited = 0 = unlimited23 zero_unlimited = 0 = unlimited
24 zero_off = 0 = off24 zero_off = 0 = off
25 invalid_number = Invalid number25 invalid_number = Invalid number
26+process = Process
27+restart = Restart server
28+restart_hint = Everyone reconnects in a few seconds
crates/client/lang/tr/builder_server.txtmodified+3 -0
@@ -23,3 +23,6 @@ rate_limits = Hız sınırları
23 zero_unlimited = 0 = sınırsız23 zero_unlimited = 0 = sınırsız
24 zero_off = 0 = kapalı24 zero_off = 0 = kapalı
25 invalid_number = Geçersiz sayı25 invalid_number = Geçersiz sayı
26+process = Süreç
27+restart = Sunucuyu yeniden başlat
28+restart_hint = Herkes birkaç saniye içinde yeniden bağlanır
crates/client/src/gui/builder/server.rsmodified+44 -2
@@ -1,12 +1,21 @@
1 use crate::gui::glyph::Fill as _;1 use crate::gui::glyph::Fill as _;
2-use common::{call::UpdateServerSettings, model::ServerSettings};2+use common::{
3+ call::{RestartServer, UpdateServerSettings},
4+ model::ServerSettings,
5+};
3 use gpui_kit::{6 use gpui_kit::{
4 AnyElement, App, Context, Entity, IntoElement, Window,7 AnyElement, App, Context, Entity, IntoElement, Window,
5 component::{WindowExt, input::InputState, notification::Notification},8 component::{WindowExt, input::InputState, notification::Notification},
6 };9 };
7 10
8 use super::ui::{field_row, list_card, number, to_bytes, to_units};11 use super::ui::{field_row, list_card, number, to_bytes, to_units};
9-use crate::gui::{KB, MB, Palette, Yumush, notify_error, settings_page::segmented, widget::field};12+use crate::gui::{
13+ KB, MB, Palette, Yumush,
14+ chat::Armed,
15+ notify_error,
16+ settings_page::{delete_control, segmented},
17+ widget::field,
18+};
10 use crate::lang::w;19 use crate::lang::w;
11 20
12 fn input_text(input: &Entity<InputState>, cx: &App) -> String {21 fn input_text(input: &Entity<InputState>, cx: &App) -> String {
@@ -143,6 +152,20 @@ impl Yumush {
143 .detach();152 .detach();
144 }153 }
145 154
155+ fn restart_server(&mut self, window: &mut Window, cx: &mut Context<Self>) {
156+ if !self.arm(Armed::RestartServer, cx) {
157+ return;
158+ }
159+ let network = self.network.clone();
160+ cx.spawn_in(window, async move |this, cx| {
161+ if let Err(error) = network.call(RestartServer).await {
162+ notify_error(&this, cx, error);
163+ }
164+ })
165+ .detach();
166+ cx.notify();
167+ }
168+
146 pub(super) fn server_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {169 pub(super) fn server_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {
147 let general = vec![170 let general = vec![
148 field_row(171 field_row(
@@ -260,6 +283,25 @@ impl Yumush {
260 list_card(Some(w().builder_server.limits), limits, "", palette).into_any_element(),283 list_card(Some(w().builder_server.limits), limits, "", palette).into_any_element(),
261 list_card(Some(w().builder_server.storage), storage, "", palette).into_any_element(),284 list_card(Some(w().builder_server.storage), storage, "", palette).into_any_element(),
262 list_card(Some(w().builder_server.rate_limits), rate, "", palette).into_any_element(),285 list_card(Some(w().builder_server.rate_limits), rate, "", palette).into_any_element(),
286+ list_card(
287+ Some(w().builder_server.process),
288+ vec![field_row(
289+ w().builder_server.restart,
290+ Some(w().builder_server.restart_hint),
291+ delete_control(
292+ "restart_server",
293+ w().update.restart,
294+ self.armed(Armed::RestartServer),
295+ entity,
296+ palette,
297+ Yumush::restart_server,
298+ ),
299+ palette,
300+ )],
301+ "",
302+ palette,
303+ )
304+ .into_any_element(),
263 ]305 ]
264 }306 }
265 }307 }
crates/client/src/gui/chat.rsmodified+1 -0
@@ -90,6 +90,7 @@ pub enum Armed {
90 DeleteUser(Id),90 DeleteUser(Id),
91 DeleteAccount,91 DeleteAccount,
92 DeleteCommunity,92 DeleteCommunity,
93+ RestartServer,
93 }94 }
94 95
95 #[derive(Debug, Clone, PartialEq, Eq)]96 #[derive(Debug, Clone, PartialEq, Eq)]
crates/common/src/call.rsmodified+4 -0
@@ -653,6 +653,9 @@ pub struct FollowStats {
653 #[derive(Debug, Clone, Encode, Decode)]653 #[derive(Debug, Clone, Encode, Decode)]
654 pub struct GetServerStats;654 pub struct GetServerStats;
655 655
656+#[derive(Debug, Clone, Encode, Decode)]
657+pub struct RestartServer;
658+
656 #[derive(Debug, Clone, Encode, Decode)]659 #[derive(Debug, Clone, Encode, Decode)]
657 pub struct PushStats {660 pub struct PushStats {
658 pub stats: Stats,661 pub stats: Stats,
@@ -791,4 +794,5 @@ calls! {
791 FollowStats: Builder -> Option<Stats>;794 FollowStats: Builder -> Option<Stats>;
792 PushStats: User -> ();795 PushStats: User -> ();
793 GetServerStats: Builder -> Stats;796 GetServerStats: Builder -> Stats;
797+ RestartServer: Builder -> ();
794 }798 }
crates/common/src/transport.rsmodified+5 -2
@@ -13,7 +13,7 @@ use quinn::{
13 use quinn_proto::RttEstimator;13 use quinn_proto::RttEstimator;
14 use socket2::{Domain, Protocol, Socket, Type};14 use socket2::{Domain, Protocol, Socket, Type};
15 15
16-pub const ALPN: &[u8] = b"yumush/4";16+pub const ALPN: &[u8] = b"yumush/5";
17 17
18 const IDLE_TIMEOUT: Duration = Duration::from_secs(10);18 const IDLE_TIMEOUT: Duration = Duration::from_secs(10);
19 pub const KEEP_ALIVE: Duration = Duration::from_secs(1);19 pub const KEEP_ALIVE: Duration = Duration::from_secs(1);
@@ -174,10 +174,11 @@ pub enum Close {
174 Maintenance = 4,174 Maintenance = 4,
175 Slow = 5,175 Slow = 5,
176 Protocol = 6,176 Protocol = 6,
177+ Restart = 7,
177 }178 }
178 179
179 impl Close {180 impl Close {
180- pub const ALL: [Self; 7] = [181+ pub const ALL: [Self; 8] = [
181 Self::Normal,182 Self::Normal,
182 Self::SignedOut,183 Self::SignedOut,
183 Self::Revoked,184 Self::Revoked,
@@ -185,6 +186,7 @@ impl Close {
185 Self::Maintenance,186 Self::Maintenance,
186 Self::Slow,187 Self::Slow,
187 Self::Protocol,188 Self::Protocol,
189+ Self::Restart,
188 ];190 ];
189 191
190 pub fn of(code: VarInt) -> Option<Self> {192 pub fn of(code: VarInt) -> Option<Self> {
@@ -200,6 +202,7 @@ impl Close {
200 Self::Maintenance => "maintenance",202 Self::Maintenance => "maintenance",
201 Self::Slow => "slow",203 Self::Slow => "slow",
202 Self::Protocol => "protocol error",204 Self::Protocol => "protocol error",
205+ Self::Restart => "server restarting",
203 }206 }
204 }207 }
205 208
crates/server/src/call/admin.rsmodified+16 -2
@@ -4,8 +4,9 @@ use common::{
4 DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetStorageUsage,4 DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetStorageUsage,
5 ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, ListInviteCodes,5 ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, ListInviteCodes,
6 ListServerBans, ListUsers, Logout, PurgeUser, RemoveServerBan, RenameUser, ResetPassword,6 ListServerBans, ListUsers, Logout, PurgeUser, RemoveServerBan, RenameUser, ResetPassword,
7- RevokeSessions, SearchCommunity, SearchMessages, SetCommunityVoice, SetGhost, StorageUsage,7+ RestartServer, RevokeSessions, SearchCommunity, SearchMessages, SetCommunityVoice,
8- SuspendUser, TimeoutUser, TransferOwnership, UpdateServerSettings, WatchCommunity,8+ SetGhost, StorageUsage, SuspendUser, TimeoutUser, TransferOwnership, UpdateServerSettings,
9+ WatchCommunity,
9 },10 },
10 error::Error,11 error::Error,
11 event::Event,12 event::Event,
@@ -685,6 +686,19 @@ impl Handle for SetCommunityVoice {
685 }686 }
686 }687 }
687 688
689+impl Handle for RestartServer {
690+ async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {
691+ let me = me.user()?;
692+ tracing::info!("restart requested by {}", me.username);
693+ let restart = cx.sh.services.restart.clone();
694+ tokio::spawn(async move {
695+ tokio::time::sleep(std::time::Duration::from_millis(300)).await;
696+ restart.notify_one();
697+ });
698+ Ok(())
699+ }
700+}
701+
688 impl Handle for SetGhost {702 impl Handle for SetGhost {
689 async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {703 async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> {
690 let me = me.user()?;704 let me = me.user()?;
crates/server/src/call/mod.rsmodified+1 -0
@@ -213,6 +213,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> {
213 Request::GetStorageUsage(call) => serve(call, cx).await,213 Request::GetStorageUsage(call) => serve(call, cx).await,
214 Request::GetDailyStats(call) => serve(call, cx).await,214 Request::GetDailyStats(call) => serve(call, cx).await,
215 Request::SetGhost(call) => serve(call, cx).await,215 Request::SetGhost(call) => serve(call, cx).await,
216+ Request::RestartServer(call) => serve(call, cx).await,
216 Request::CreateBackup(call) => serve(call, cx).await,217 Request::CreateBackup(call) => serve(call, cx).await,
217 Request::ListBackups(call) => serve(call, cx).await,218 Request::ListBackups(call) => serve(call, cx).await,
218 Request::DeleteBackup(call) => serve(call, cx).await,219 Request::DeleteBackup(call) => serve(call, cx).await,
crates/server/src/lib.rsmodified+1 -1
@@ -65,7 +65,7 @@ fn sibling_directory(database_path: &str, name: &str) -> Result<PathBuf, ServerE
65 Ok(directory)65 Ok(directory)
66 }66 }
67 67
68-pub async fn showtime() -> Result<(), ServerError> {68+pub async fn showtime() -> Result<network::Exit, ServerError> {
69 let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();69 let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
70 70
71 let config = load_config()?;71 let config = load_config()?;
crates/server/src/main.rsmodified+10 -2
@@ -1,5 +1,6 @@
1 use common::model::Role;1 use common::model::Role;
2-use server::{set_role, showtime};2+use server::{network::Exit, set_role, showtime};
3+use std::os::unix::process::CommandExt;
3 4
4 #[tokio::main]5 #[tokio::main]
5 async fn main() -> Result<(), server::error::ServerError> {6 async fn main() -> Result<(), server::error::ServerError> {
@@ -16,7 +17,14 @@ async fn main() -> Result<(), server::error::ServerError> {
16 {17 {
17 ["builder", username] => set_role(username, Role::Builder).await?,18 ["builder", username] => set_role(username, Role::Builder).await?,
18 ["unbuilder", username] => set_role(username, Role::User).await?,19 ["unbuilder", username] => set_role(username, Role::User).await?,
19- _ => return showtime().await,20+ _ => {
21+ if let Exit::Restart = showtime().await? {
22+ let mut args = std::env::args_os();
23+ let program = args.next().unwrap_or_default();
24+ return Err(std::process::Command::new(program).args(args).exec().into());
25+ }
26+ return Ok(());
27+ }
20 }28 }
21 29
22 println!("ok");30 println!("ok");
crates/server/src/network.rsmodified+23 -5
@@ -32,6 +32,12 @@ use crate::{
32 };32 };
33 33
34 const HELLO_DEADLINE: Duration = Duration::from_secs(5);34 const HELLO_DEADLINE: Duration = Duration::from_secs(5);
35+const RESTART_DRAIN: Duration = Duration::from_secs(2);
36+
37+pub enum Exit {
38+ Stopped,
39+ Restart,
40+}
35 41
36 #[derive(Clone, Default)]42 #[derive(Clone, Default)]
37 pub struct Services {43 pub struct Services {
@@ -40,6 +46,7 @@ pub struct Services {
40 pub rate_limit: RateLimit,46 pub rate_limit: RateLimit,
41 pub stats: Follows,47 pub stats: Follows,
42 pub machine: Machine,48 pub machine: Machine,
49+ pub restart: Arc<tokio::sync::Notify>,
43 }50 }
44 51
45 #[derive(Clone)]52 #[derive(Clone)]
@@ -65,7 +72,7 @@ pub async fn serve(
65 directory: PathBuf,72 directory: PathBuf,
66 backups: PathBuf,73 backups: PathBuf,
67 releases: crate::update::Releases,74 releases: crate::update::Releases,
68-) -> Result<(), ServerError> {75+) -> Result<Exit, ServerError> {
69 let endpoint = transport::endpoint(76 let endpoint = transport::endpoint(
70 server_address.parse()?,77 server_address.parse()?,
71 quinn::EndpointConfig::default(),78 quinn::EndpointConfig::default(),
@@ -84,11 +91,22 @@ pub async fn serve(
84 91
85 tokio::spawn(retention::collect(shared.clone()));92 tokio::spawn(retention::collect(shared.clone()));
86 93
87- while let Some(incoming) = endpoint.accept().await {94+ let restart = shared.services.restart.clone();
88- tokio::spawn(handle_connection(incoming, shared.clone()));95+ loop {
96+ tokio::select! {
97+ incoming = endpoint.accept() => match incoming {
98+ Some(incoming) => {
99+ tokio::spawn(handle_connection(incoming, shared.clone()));
100+ }
101+ None => return Ok(Exit::Stopped),
102+ },
103+ _ = restart.notified() => break,
104+ }
89 }105 }
90-106+ info!("restarting");
91- Ok(())107+ endpoint.close(Close::Restart.code(), Close::Restart.reason().as_bytes());
108+ let _ = tokio::time::timeout(RESTART_DRAIN, endpoint.wait_idle()).await;
109+ Ok(Exit::Restart)
92 }110 }
93 111
94 async fn handle_connection(incoming: Incoming, shared: Shared) {112 async fn handle_connection(incoming: Incoming, shared: Shared) {