Skip to content

Commit bfd8a58

Browse files
committed
triggers(5): add documentation for per package triggers
1 parent 4b9ba49 commit bfd8a58

File tree

1 file changed

+73
-10
lines changed

1 file changed

+73
-10
lines changed

docs/pkg-triggers.5

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88
.\" notice, this list of conditions and the following disclaimer in the
99
.\" documentation and/or other materials provided with the distribution.
1010
.\"
11-
.Dd December 12, 2025
11+
.Dd March 4, 2026
1212
.Dt PKG-TRIGGERS 5
1313
.Os
1414
.Sh NAME
1515
.Nm triggers
1616
.Nd trigger file format
1717
.Sh DESCRIPTION
18-
Package triggers define commands to be executed at the end of a
19-
.Xr pkg 8
20-
transaction when particular files are installed, modified, or removed.
21-
Triggers can be used, for example, to update a database or index of files based
22-
on files installed by other packages.
23-
Triggers are always executed at the end of the transaction, after all changes
24-
to files have been committed to disk.
25-
They are only executed once even if they have been triggered multiple times.
18+
Package triggers define commands to be executed when particular files are
19+
installed, modified, or removed by
20+
.Xr pkg 8 .
21+
Triggers can be used, for example, to update a database or index of files
22+
based on files installed by other packages.
23+
.Pp
24+
There are two kinds of triggers:
25+
.Bl -tag -width "Per-package"
26+
.It Sy Per-transaction
27+
Executed once at the end of the transaction, after all packages have been
28+
processed and all file changes committed to disk.
29+
Even if multiple packages match the same trigger, it is executed only once
30+
and receives the combined list of matched paths.
31+
.It Sy Per-package
32+
Executed individually for each package as it is being installed or removed.
33+
Per-package triggers run at a specific phase of the operation
34+
.Pq pre-install, post-install, pre-deinstall, or post-deinstall .
35+
Their failure is non-blocking: the package operation continues even if the
36+
trigger fails.
37+
.El
2638
.Pp
2739
Triggers are searched for in the list of directories configured by the
2840
.Ev PKG_TRIGGERS_DIR
@@ -34,6 +46,8 @@ and
3446
Triggers are in UCL format and should have a
3547
.Va .ucl
3648
extension.
49+
.Ss Per-transaction triggers
50+
Per-transaction trigger files are placed directly in a trigger directory.
3751
.Pp
3852
The format is the following:
3953
.Bl -tag -width xxxxxxxxxxx
@@ -78,7 +92,7 @@ When disabled, the script has full system access including
7892
.It Cm trigger
7993
An object which represents the script to execute at the end of the transaction
8094
if a pattern has been matched.
81-
This object requires the following fields:
95+
This object is required and has the following fields:
8296
.Bl -tag -width xxxxxxx
8397
.It Cm type
8498
The type of the script to be executed.
@@ -100,6 +114,55 @@ When disabled, the script has full system access including
100114
.Fn pkg.exec .
101115
.El
102116
.El
117+
.Ss Per-package triggers
118+
Per-package trigger files are placed in a subdirectory of a trigger directory
119+
named after the phase at which they should execute:
120+
.Bl -tag -width "post_deinstall/" -compact
121+
.It Pa pre_install/
122+
Before the package files are extracted.
123+
.It Pa post_install/
124+
After the package files have been extracted and post-install scripts have run.
125+
.It Pa pre_deinstall/
126+
Before the package files are removed.
127+
.It Pa post_deinstall/
128+
After the package files have been removed and post-deinstall scripts have run.
129+
.El
130+
.Pp
131+
For example, a trigger that should run after each package installation would be
132+
placed in:
133+
.Pp
134+
.Pa <localbase>/share/pkg/triggers/post_install/mytrigger.ucl
135+
.Pp
136+
The file format is the same as for per-transaction triggers.
137+
The
138+
.Cm path , path_glob ,
139+
and
140+
.Cm path_regexp
141+
fields are used to match the files and directories of the individual package.
142+
The
143+
.Cm trigger
144+
object contains the script to execute.
145+
.Pp
146+
Per-package triggers are reloaded from disk before processing each package,
147+
so a trigger installed by an earlier package in the same transaction will
148+
be active for subsequent packages.
149+
.Pp
150+
In addition to the
151+
.Va arg
152+
table containing matched paths, per-package trigger scripts have access to
153+
the following Lua global variables:
154+
.Bl -tag -width "pkg_version"
155+
.It Va pkg_name
156+
The name of the package being processed.
157+
.It Va pkg_version
158+
The version of the package being processed.
159+
.It Va pkg_upgrade
160+
A boolean set to
161+
.Cm true
162+
if the operation is part of an upgrade, or
163+
.Cm false
164+
for a fresh installation or a standalone removal.
165+
.El
103166
.Sh SEE ALSO
104167
.Xr pkg_create 3 ,
105168
.Xr pkg_printf 3 ,

0 commit comments

Comments
 (0)