Skip to content

Commit 15629f7

Browse files
bridgetwu33tylerharter
authored andcommitted
Edited UDS to be implemented in worker, undoed changes to boss and config files
1 parent 4273fe9 commit 15629f7

5 files changed

Lines changed: 7 additions & 69 deletions

File tree

go/boss/boss.go

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import (
55
"fmt"
66
"io"
77
"log/slog"
8-
"net"
98
"net/http"
109
"os"
1110
"os/signal"
12-
"path/filepath"
1311
"strconv"
1412
"strings"
1513
"syscall"
@@ -192,48 +190,7 @@ func BossMain() (err error) {
192190
os.Exit(0)
193191
}()
194192

195-
if config.BossConf.Transport == "unix" {
196-
sockPath := config.BossConf.Boss_socket
197-
// ensure directory exists
198-
os.MkdirAll(filepath.Dir(sockPath), 0700)
199-
// remove stale socket if it exists
200-
os.Remove(sockPath)
201-
202-
l, err := net.Listen("unix", sockPath)
203-
slog.Info("boss config", "transport", config.BossConf.Transport, "boss_socket", config.BossConf.Boss_socket, "boss_port", config.BossConf.Boss_port)
204-
if err != nil {
205-
return fmt.Errorf("failed to listen on unix socket %s: %w", sockPath, err)
206-
}
207-
fmt.Printf("Listen on unix socket %s\n", sockPath)
208-
return http.Serve(l, nil)
209-
}
210-
211-
if config.BossConf.Transport != "unix" {
212-
return fmt.Errorf("boss admin must run on unix socket; set transport=unix")
213-
}
214-
215-
sockPath := config.BossConf.Boss_socket
216-
217-
if err := os.MkdirAll(filepath.Dir(sockPath), 0700); err != nil {
218-
return fmt.Errorf("make socket dir: %w", err)
219-
}
220-
_ = os.Remove(sockPath)
221-
222-
ln, err := net.Listen("unix", sockPath)
223-
slog.Info("boss config", "transport", config.BossConf.Transport, "boss_socket", config.BossConf.Boss_socket, "boss_port", config.BossConf.Boss_port)
224-
if err != nil {
225-
return fmt.Errorf("failed to listen on unix socket %s: %w", sockPath, err)
226-
}
227-
if err := os.Chmod(sockPath, 0600); err != nil {
228-
return fmt.Errorf("chmod socket: %w", err)
229-
}
230-
231-
slog.Info("boss config",
232-
"transport", config.BossConf.Transport,
233-
"boss_socket", config.BossConf.Boss_socket,
234-
"boss_port", config.BossConf.Boss_port,
235-
)
236-
237-
fmt.Printf("Listen on unix socket %s\n", sockPath)
238-
return http.Serve(ln, nil)
193+
port := fmt.Sprintf(":%s", config.BossConf.Boss_port)
194+
fmt.Printf("Listen on port %s\n", port)
195+
return http.ListenAndServe(port, nil) // should never return if successful
239196
}

go/boss/config/config.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@ type Config struct {
1717
Worker_Cap int `json:"worker_cap"`
1818
Gcp GcpConfig `json:"gcp"`
1919
Local LocalPlatConfig `json:"local"`
20-
Transport string `json:"transport"`
21-
Boss_socket string `json:"boss_socket"`
2220
}
2321

2422
func LoadDefaults() error {
2523
BossConf = &Config{
2624
Platform: "local",
2725
Scaling: "manual",
2826
API_key: "abc", // TODO: autogenerate a random key
29-
Boss_port: "",
27+
Boss_port: "5000",
3028
Worker_Cap: 4,
3129
Gcp: GetGcpConfigDefaults(),
3230
Local: GetLocalPlatformConfigDefaults(),
33-
Transport: "unix",
34-
Boss_socket: "/run/openlambda/boss.sock",
3531
}
3632

3733
return checkConf()

go/common/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ type Config struct {
2727
// port the worker server listens to
2828
Worker_port string `json:"worker_port"`
2929

30-
// sock file the worker server interacts with
31-
Worker_socket string `json:"worker_socket`
32-
3330
// log output of the runtime and proxy?
3431
Log_output bool `json:"log_output"`
3532

@@ -228,7 +225,6 @@ func getDefaultConfigForPatching(olPath string) (*Config, error) {
228225
Server_mode: "lambda",
229226
Worker_url: "localhost",
230227
Worker_port: "5000",
231-
Worker_socket: "",
232228
// Registry URL with file:// prefix required by gocloud blob backend abstraction.
233229
// The gocloud library uses URL schemes to route to appropriate storage drivers:
234230
// file:// for local filesystem, s3:// for AWS S3, gs:// for Google Cloud Storage.

go/worker/commands.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ func upCmd(ctx *cli.Context) error {
132132

133133
var pingErr error
134134

135-
sockPath := common.Conf.Worker_socket
136-
if sockPath == "" {
137-
sockPath = filepath.Join("/run/openlambda", "pid.sock")
138-
}
135+
const sockPath = "/run/openlambda/ol.sock"
139136

140137
tr := &http.Transport{}
141138
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
@@ -161,9 +158,6 @@ func upCmd(ctx *cli.Context) error {
161158
}
162159

163160
// is it reachable?
164-
// url := fmt.Sprintf("http://localhost:%s/pid", common.Conf.Worker_port)
165-
// response, err := http.Get(url)
166-
167161
response, err := client.Get("http://unix/pid")
168162

169163
if err != nil {

go/worker/event/server.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,8 @@ func Main() (err error) {
314314
shutdown(pidPath, s)
315315
}()
316316

317-
port := fmt.Sprintf("%s:%s", common.Conf.Worker_url, common.Conf.Worker_port)
318-
319317
// socket path uses config value, otherwise make a new worker.sock file
320-
sockPath := common.Conf.Worker_socket
321-
if sockPath == "" {
322-
sockPath = filepath.Join("/run/openlambda", "pid.sock")
323-
}
318+
const sockPath = "/run/openlambda/ol.sock"
324319

325320
// ensure directory exists and stale socket is gone
326321
if err := os.MkdirAll(filepath.Dir(sockPath), 0700); err != nil {
@@ -358,7 +353,7 @@ func Main() (err error) {
358353
// remove socket on exit
359354
defer func() { _ = os.Remove(sockPath) }()
360355

361-
356+
port := fmt.Sprintf("%s:%s", common.Conf.Worker_url, common.Conf.Worker_port)
362357
err = http.ListenAndServe(port, nil)
363358

364359
// if ListenAndServer returned, there must have been some issue

0 commit comments

Comments
 (0)