Richard Bucker


Posted at — Jan 12, 2015

Inspired by man 1 flock I have decided to build my own flock utility in golang. After creating a public git repo on bitbucket I started thinking about the details. (a) use stdlib only (b) keep it simple (c) offer a command line and a package.Nothing new there, but then…Now the question becomes; should I always have a lock file? Every time I run any application should I have a lock file? Should that lock file prevent multiple instances of THIS version of the tool or any version of the tool. Or should the lock file act as a sort of semaphore indicating that there is an application of this type running?I ended up with a few choices:$ myapp -pidlockfileUse the program name arg[0] and the current pid.$ myapp -buildlockfileUse the program name and CI build number.$ myapp -lockfileUse the program name prevent multiple instances of the same application on the same machine$ myapp -nolockfileDo not use a lock file.One thing to keep in mind is that if you use fleet to launch your containers, and in turn your applications, then this feature is not really¬†needed. It’s not likely that you’ll launch multiple instances… but then again it’s not going to cost you anything to combine them. Also, fleet will handle the instance generation over the network instead of a single machine.