Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ExeName string ExeBaseName string ExePath string ExePathHash string ExeDirectory string UserHomeDir = sync.OnceValue(func() string { homeDir, err := os.UserHomeDir() if err != nil { log.Fatal().Err(err).Msg("failed to get user home directory") } return homeDir }) ShareDirectory = sync.OnceValue(func() string { return filepath.Join(UserHomeDir(), ".local/share/system-link") }) PortableMode = sync.OnceValue(func() bool { return FileExists(filepath.Join(ExeDirectory, "config.yaml")) }) ConfigPath = sync.OnceValue(func() string { if PortableMode() { return filepath.Join(ExeDirectory, "config.yaml") } if env := os.Getenv("SYSTEM_LINK_CONFIG"); env != "" { return env } return filepath.Join(UserHomeDir(), ".config/system-link/config.yaml") }) ConfigDirectory = sync.OnceValue(func() string { return filepath.Dir(ConfigPath()) }) LogsPath = sync.OnceValue(func() string { if PortableMode() { return filepath.Join(ExeDirectory, ExeBaseName+".log") } logName := ExeBaseName + "." + ExePathHash + ".log" if env := os.Getenv("SYSTEM_LINK_LOGS_DIR"); env != "" { return filepath.Join(env, logName) } return filepath.Join(ShareDirectory(), logName) }) LockPath = sync.OnceValue(func() string { if PortableMode() { return ExePath + ".lock" } lockName := ExeBaseName + "." + ExePathHash + ".lock" if env := os.Getenv("SYSTEM_LINK_LOCKS_DIR"); env != "" { return filepath.Join(env, lockName) } if env := os.Getenv("SYSTEM_LINK_LOGS_DIR"); env != "" { return filepath.Join(env, lockName) } return filepath.Join(ShareDirectory(), lockName) }) )
Functions ¶
func FileExists ¶ added in v1.10.0
func GetDefaultShell ¶
func GetDefaultShell() []string
func RestartSelf ¶ added in v1.2.0
func RestartSelf() error
Types ¶
type CommandConfig ¶
type CommandResult ¶ added in v1.4.0
type CommandResult struct {
Stdout []byte `json:"stdout"`
Stderr []byte `json:"stderr"`
Combined []byte `json:"combined"`
Code int `json:"code"`
}
func RunCommand ¶
func RunCommand(cfg CommandConfig) (CommandResult, error)
RunCommand runs a specified command, if Detached is true the command result will be empty
type InstanceLock ¶
type InstanceLock struct {
// contains filtered or unexported fields
}
func LockAndKill ¶
func LockAndKill() *InstanceLock
func NewInstanceLock ¶
func NewInstanceLock() InstanceLock
func (InstanceLock) KillLockedPid ¶
func (l InstanceLock) KillLockedPid() error
KillLockedPid kills the process with the pid in the lock file
func (InstanceLock) Lock ¶
func (l InstanceLock) Lock() error
Lock writes the current process id to the lock file
func (InstanceLock) LockedPid ¶
func (l InstanceLock) LockedPid() (int, error)
LockedPid returns the pid in the lock file
func (InstanceLock) LockedProcess ¶
func (l InstanceLock) LockedProcess() (*process.Process, int, error)
LockedProcess returns the process with the pid in the lock file can return os.ErrNotExist or process.ErrorProcessNotRunning
Source Files
¶
Click to show internal directories.
Click to hide internal directories.