100 // New will setup a new server struct after parsing the options.
101 func New(opts *Options) *Server {
...
123 s := &Server{
124 configFile: opts.ConfigFile,
125 info: info,
126 sl: NewSublist(),
127 opts: opts,
128 done: make(chan bool, 1),
129 start: now,
130 configTime: now,
131 }
...
157 return s
}
47 // Server is our main struct.
48 type Server struct {
49 gcid uint64
50 grid uint64
51 stats
52 mu sync.Mutex
53 info Info
54 infoJSON []byte
55 sl *Sublist
56 configFile string
57 optsMu sync.RWMutex
58 opts *Options
59 running bool
60 shutdown bool
61 listener net.Listener
62 clients map[uint64]*client
63 routes map[uint64]*client
64 remotes map[string]*client
65 users map[string]*User
66 totalClients uint64
67 done chan bool
68 start time.Time
69 http net.Listener
70 httpHandler http.Handler
71 profiler net.Listener
72 httpReqStats map[string]uint64
73 routeListener net.Listener
74 routeInfo Info
75 routeInfoJSON []byte
76 rcQuit chan bool
77 grMu sync.Mutex
78 grTmpClients map[uint64]*client
79 grRunning bool
80 grWG sync.WaitGroup // to wait on various go routines
81 cproto int64 // number of clients supporting async INFO
82 configTime time.Time // last time config was loaded
83 logging struct {
84 sync.RWMutex
85 logger Logger
86 trace int32
87 debug int32
88 }
89 }
6 // Run starts the NATS server. This wrapper function allows Windows to add a
7 // hook for running NATS as a service.
8 func Run(server *Server) error {
9 server.Start()
10 return nil
11 }
1 // +build !windows
36 func (w *winServiceWrapper) Execute(args []string, changes <-chan svc.ChangeRequest,
37 status chan<- svc.Status) (bool, uint32) {
38
39 status <- svc.Status{State: svc.StartPending}
40 go w.server.Start()
237 func (s *Server) Start() {
241 // Avoid RACE between Start() and Shutdown()
242 s.mu.Lock()
243 s.running = true
244 s.mu.Unlock()
245
246 s.grMu.Lock()
247 s.grRunning = true
248 s.grMu.Unlock()
....
259
260 // Start monitoring if needed
261 if err := s.StartMonitoring(); err != nil {
...
265
266 // The Routing routine needs to wait for the client listen
267 // port to be opened and potential ephemeral port selected.
268 clientListenReady := make(chan struct{})
270 // Start up routing as well if needed.
271 if opts.Cluster.Port != 0 {
272 s.startGoRoutine(func() {
273 s.StartRouting(clientListenReady)
274 })
275 }
276
277 // Pprof http endpoint for the profiler.
278 if opts.ProfPort != 0 {
279 s.StartProfiler()
280 }
281
282 // Wait for clients.
283 s.AcceptLoop(clientListenReady)
284 }