wpkg --database-is-locked
Options | Comments |
---|---|
--admindir | Define the administration directory, where the database of the installed packages resides. |
--debug | Define a set of flags of things to print out for debug purposes. |
--instdir | Define the installation directory, where the data files are installed on the target. |
--quiet | Request for warning messages to not be displayed. |
--root | Define the installation root path. |
--verbose | Display log information of level INFO. |
wpkg makes use of a database which cannot be shared between multiple processes. To avoid problems (when running two wpkg processes in parallel) the tool creates a lock file in its database.
The --database-is-locked command is used to check whether that lock file exists. If it does exist it means a wpkg process is running.
Note that it is possible to do work on the wpkg database with other tools or scripts using the --create-database-lock and the --remove-database-lock commands and then make sure that you don't walk on your own feet (i.e. prevent two instances of that other tool to manipulate the database simultaneously) using the --database-is-locked test.
The following is a very basic example of a shell script using these commands, note that this example doesn't handle the case where the user would use Ctrl-C to break execution (because in that case you probably want to make sure the database is in a clean state and then --remove-database-lock is used.)
#!/bin/sh if wpkg --database-is-locked then echo "error: Sorry! The wpkg database is currently in use. Try again later." exit 1; fi if ! wpkg --create-database-lock then echo "error: Sorry! The wpkg database could not be locked properly." exit 1; fi [... DO YOUR WORK ...] wpkg --remove-database-lock
The reason why the --create-database-lock may fail is because another process may lock the database between the time we check with --database-is-locked and the time we create the lock with --create-database-lock.