@@ -79,10 +79,18 @@ import { cheapLoadUserData, setupFileStructure } from "./databaseHandler"
7979import { getFlag , saveFlags } from "./flags"
8080import { initializePeacockMenu } from "./menus/settings"
8181import { ConfigRouteParams } from "./types/gameSchemas"
82+ import { getSocketActivationFileDescriptors } from "./socketActivation"
8283
8384const host = process . env . HOST || "0.0.0.0"
8485const port = process . env . PORT || 80
8586
87+ const listenFds = getSocketActivationFileDescriptors ( )
88+ let listenFd : number | null = null
89+
90+ if ( listenFds !== null && listenFds . length > 0 ) {
91+ listenFd = listenFds [ 0 ]
92+ }
93+
8694function uncaught ( error : Error ) : void {
8795 if (
8896 ( error . message || "" ) . includes ( "EADDRINUSE" ) ||
@@ -577,9 +585,19 @@ export async function startServer(options: {
577585
578586 const httpServer = http . createServer ( app )
579587
580- log ( LogLevel . INFO , `Listening on ${ host } :${ port } ...` )
581- // @ts -expect-error Non-matching method sig
582- httpServer . listen ( port , host )
588+ if ( listenFd !== null ) {
589+ log ( LogLevel . INFO , `Listening on systemd://${ listenFd } ...` )
590+ httpServer . listen ( {
591+ fd : listenFd ,
592+ } )
593+ } else {
594+ log ( LogLevel . INFO , `Listening on ${ host } :${ port } ...` )
595+ httpServer . listen ( {
596+ host,
597+ port,
598+ } )
599+ }
600+
583601 log ( LogLevel . INFO , "Server started." )
584602
585603 if ( getFlag ( "discordRp" ) === true ) {
0 commit comments