Skip to content

Commit

Permalink
Add adapter socket
Browse files Browse the repository at this point in the history
Reviewed By: dkgi

Differential Revision: D20926788

fbshipit-source-id: e9380f875054ad9ef57c87f07b6cd2f6f0ff3150
  • Loading branch information
MaggieMoss authored and facebook-github-bot committed Apr 14, 2020
1 parent f0133d8 commit 19acbb9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
17 changes: 12 additions & 5 deletions command/startCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ let request_handler_thread
let serve
~socket
~json_socket
~adapter_socket
~server_configuration:({ Configuration.Server.configuration; _ } as server_configuration)
=
Version.log_version_banner ();
Expand All @@ -399,9 +400,11 @@ let serve
{
socket;
json_socket;
adapter_socket;
persistent_clients = Socket.Map.empty;
json_sockets = [];
sockets_to_close = [];
adapter_sockets = [];
};
}
in
Expand Down Expand Up @@ -429,7 +432,7 @@ let acquire_lock ~server_configuration:{ Configuration.Server.lock_path; pid_pat


type run_server_daemon_entry =
( Socket.t * Socket.t * Configuration.Server.t,
( Socket.t * Socket.t * Socket.t * Configuration.Server.t,
unit Daemon.in_channel,
unit Daemon.out_channel )
Daemon.entry
Expand All @@ -440,7 +443,9 @@ type run_server_daemon_entry =
let run_server_daemon_entry : run_server_daemon_entry =
Daemon.register_entry_point
"server_daemon"
(fun (socket, json_socket, server_configuration) (parent_in_channel, parent_out_channel) ->
(fun (socket, json_socket, adapter_socket, server_configuration)
(parent_in_channel, parent_out_channel)
->
Daemon.close_in parent_in_channel;
Daemon.close_out parent_out_channel;

Expand All @@ -452,14 +457,15 @@ let run_server_daemon_entry : run_server_daemon_entry =
| Some _ -> ()
| None -> Telemetry.reset_budget ()
in
serve ~socket ~json_socket ~server_configuration)
serve ~socket ~json_socket ~adapter_socket ~server_configuration)


let run
( {
Configuration.Server.lock_path;
socket = { path = socket_path; _ };
json_socket = { path = json_socket_path; _ };
adapter_socket = { path = adapter_socket_path; _ };
log_path;
daemonize;
configuration = { incremental_style; _ } as configuration;
Expand All @@ -483,6 +489,7 @@ let run
Log.log ~section:`Server "Creating server socket at `%a`" Path.pp socket_path;
let socket = Socket.initialize_unix_socket socket_path in
let json_socket = Socket.initialize_unix_socket json_socket_path in
let adapter_socket = Socket.initialize_unix_socket adapter_socket_path in
if daemonize then (
let stdin = Daemon.null_fd () in
let log_path = Log.rotate (Path.absolute log_path) in
Expand All @@ -492,15 +499,15 @@ let run
Daemon.spawn
(stdin, stdout, stdout)
run_server_daemon_entry
(socket, json_socket, server_configuration)
(socket, json_socket, adapter_socket, server_configuration)
in
Daemon.close handle;
Log.log ~section:`Server "Forked off daemon with pid %d" pid;
Log.info "Server starting in background";
pid )
else (
acquire_lock ~server_configuration;
serve ~socket ~json_socket ~server_configuration )
serve ~socket ~json_socket ~adapter_socket ~server_configuration )
with
| AlreadyRunning ->
Log.info "Server is already running";
Expand Down
2 changes: 2 additions & 0 deletions command/test/commandTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ module ScratchServer = struct
{
Server.State.socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
json_socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
adapter_socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
persistent_clients = Network.Socket.Map.empty;
json_sockets = [];
sockets_to_close = [];
adapter_sockets = [];
};
};
scheduler = Test.mock_scheduler ();
Expand Down
1 change: 1 addition & 0 deletions configuration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ module Server = struct
(* Server-specific configuration options *)
socket: socket_path;
json_socket: socket_path;
adapter_socket: socket_path;
lock_path: Path.t;
pid_path: Path.t;
log_path: Path.t;
Expand Down
1 change: 1 addition & 0 deletions configuration.mli
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module Server : sig
(* Server-specific configuration options *)
socket: socket_path;
json_socket: socket_path;
adapter_socket: socket_path;
lock_path: Path.t;
pid_path: Path.t;
log_path: Path.t;
Expand Down
8 changes: 8 additions & 0 deletions server/operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ let create_configuration ?(daemonize = true) ?log_path ?saved_state_action confi
path = socket_path ~create:true ~name:"json_server" configuration;
link = server_root ^| "json_server.sock";
};
adapter_socket =
{
path = socket_path ~create:true ~name:"adapter" configuration;
link = server_root ^| "adapter.sock";
};
lock_path = server_root ^| "server.lock";
pid_path = server_root ^| "server.pid";
log_path;
Expand Down Expand Up @@ -186,6 +191,7 @@ let stop
{
Configuration.Server.socket = { path = socket_path; link = socket_link; _ };
json_socket = { path = json_socket_path; link = json_socket_link; _ };
adapter_socket = { path = adapter_path; link = adapter_link; _ };
pid_path;
_;
}
Expand All @@ -195,8 +201,10 @@ let stop
(* Cleanup server files. *)
Path.remove socket_path;
Path.remove json_socket_path;
Path.remove adapter_path;
Path.remove socket_link;
Path.remove json_socket_link;
Path.remove adapter_link;
Path.remove pid_path;
Worker.killall ();
exit 0
Expand Down
2 changes: 2 additions & 0 deletions server/state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ open Network
type raw_connections = {
socket: Socket.t;
json_socket: Socket.t;
adapter_socket: Socket.t;
persistent_clients: int Socket.Map.t;
json_sockets: Socket.t list;
sockets_to_close: Socket.t list;
adapter_sockets: Socket.t list;
}

type connections = {
Expand Down
2 changes: 2 additions & 0 deletions server/state.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ open Network
type raw_connections = {
socket: Socket.t;
json_socket: Socket.t;
adapter_socket: Socket.t;
persistent_clients: int Socket.Map.t;
json_sockets: Socket.t list;
sockets_to_close: Socket.t list;
adapter_sockets: Socket.t list;
}

type connections = {
Expand Down
2 changes: 2 additions & 0 deletions server/test/serverTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ let connections persistent_clients =
{
Server.State.socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
json_socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
adapter_socket = Unix.openfile ~mode:[Unix.O_RDONLY] "/dev/null";
persistent_clients;
json_sockets = [];
sockets_to_close = [];
adapter_sockets = [];
};
}

Expand Down

0 comments on commit 19acbb9

Please sign in to comment.