lockfile

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2016 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

lockfile

Handle locking via pid files.

Build Status Unix Build status Windows

install

Install Go 1, either from source or with a prepackaged binary. For Windows suport, Go 1.4 or newer is required.

Then run

go get github.com/nightlyone/lockfile

LICENSE

BSD

documentation

package documentation at godoc.org

install

go get github.com/nightlyone/lockfile

contributing

Contributions are welcome. Please open an issue or send me a pull request for a dedicated branch. Make sure the git commit hooks show it works.

git commit hooks

enable commit hooks via

    cd .git ; rm -rf hooks; ln -s ../git-hooks hooks ; cd ..

Documentation

Overview

Handle pid file based locking.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrBusy        = errors.New("Locked by other process") // If you get this, retry after a short sleep might help
	ErrNeedAbsPath = errors.New("Lockfiles must be given as absolute path names")
	ErrInvalidPid  = errors.New("Lockfile contains invalid pid for system")
	ErrDeadOwner   = errors.New("Lockfile contains pid of process not existent on this system anymore")
)

Functions

This section is empty.

Types

type Lockfile

type Lockfile string
Example
lock, err := New(filepath.Join(os.TempDir(), "lock.me.now.lck"))
if err != nil {
	fmt.Printf("Cannot init lock. reason: %v\n", err)
	panic(err)
}
err = lock.TryLock()

// Error handling is essential, as we only try to get the lock.
if err != nil {
	fmt.Printf("Cannot lock \"%v\", reason: %v\n", lock, err)
	panic(err)
}

defer lock.Unlock()

fmt.Println("Do stuff under lock")
Output:
Do stuff under lock

func New

func New(path string) (Lockfile, error)

Describe a new filename located at path. It is expected to be an absolute path

func (Lockfile) GetOwner

func (l Lockfile) GetOwner() (*os.Process, error)

Who owns the lockfile?

func (Lockfile) TryLock

func (l Lockfile) TryLock() error

Try to get Lockfile lock. Returns nil, if successful and and error describing the reason, it didn't work out. Please note, that existing lockfiles containing pids of dead processes and lockfiles containing no pid at all are deleted.

func (Lockfile) Unlock

func (l Lockfile) Unlock() error

Release a lock again. Returns any error that happend during release of lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL