Documentation
¶
Overview ¶
Package session manages persistent shell sessions for the memsh HTTP server. Each session has its own virtual filesystem (afero.MemMapFs) and working directory that persist across HTTP requests when using the X-Session-ID header.
Sessions support:
- Virtual filesystem isolation between sessions
- Working directory persistence
- Automatic alias persistence
- Cron job scheduling per session
- TTL-based expiration and reaping
Index ¶
Constants ¶
const AliasesFile = "/.memsh_session_aliases"
AliasesFile is the virtual-FS path used to persist aliases across requests.
Variables ¶
This section is empty.
Functions ¶
func RestoreAliases ¶
RestoreAliases sources AliasesFile if it exists.
func SaveAliases ¶
SaveAliases writes the current alias table to AliasesFile in the virtual FS so the next shell can restore it via source.
func StartScheduler ¶
func StartScheduler(ctx context.Context, store *Store, baseOpts []shell.Option, timeout time.Duration)
StartScheduler fires cron jobs for every active session once per minute. It aligns to the next minute boundary before starting the ticker so that CronMatches is evaluated at a consistent wall-clock minute. ctx should be cancelled when the server shuts down.
Types ¶
type Entry ¶
type Entry struct {
Fs afero.Fs
Cwd string
CreatedAt time.Time
LastUse time.Time
RcLoaded bool // true after /.memshrc has been sourced for this session
CronMu sync.Mutex // serialises concurrent cron job writes to /.cron_log
}
Entry holds the persistent state (filesystem + cwd) shared across requests. Each request still creates its own shell.Shell pointing at the session's FS, so per-request I/O capture works correctly.
type Info ¶
type Info struct {
ID string `json:"id"`
Cwd string `json:"cwd"`
CreatedAt string `json:"created_at"`
LastUse string `json:"last_use"`
}
Info is one entry in the session list response.
type Snap ¶
Snap is a lightweight copy of a session's key fields for use by the cron scheduler without holding the store lock during job execution.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages persistent shell sessions keyed by an arbitrary ID.
func (*Store) Get ¶
Get returns an existing session entry or creates one. Returns (entry, true) on success, or (nil, false) if the max session limit would be exceeded by creating a new session.
func (*Store) Replace ¶
Replace creates or overwrites a session with the given filesystem and cwd. Used by the snapshot import endpoint.