| 815 | } |
| 816 | |
| 817 | func (api *API) Close() error { |
| 818 | // Replica manager should be closed first. This is because the replica |
| 819 | // manager updates the replica's table in the database when it closes. |
| 820 | // This tells other Coderds that it is now offline. |
| 821 | if api.replicaManager != nil { |
| 822 | _ = api.replicaManager.Close() |
| 823 | } |
| 824 | api.cancel() |
| 825 | if api.derpMesh != nil { |
| 826 | _ = api.derpMesh.Close() |
| 827 | } |
| 828 | |
| 829 | if api.Options.CheckInactiveUsersCancelFunc != nil { |
| 830 | api.Options.CheckInactiveUsersCancelFunc() |
| 831 | } |
| 832 | |
| 833 | // Close the connection logger to flush any remaining batched |
| 834 | // entries before shutting down the database connection. |
| 835 | if cl, ok := api.Options.ConnectionLogger.(io.Closer); ok { |
| 836 | _ = cl.Close() |
| 837 | } |
| 838 | |
| 839 | return api.AGPL.Close() |
| 840 | } |
| 841 | |
| 842 | func (api *API) updateEntitlements(ctx context.Context) error { |
| 843 | return api.Entitlements.Update(ctx, func(ctx context.Context) (codersdk.Entitlements, error) { |