Administration, packages and schedules

List the services

List the services whose name matches a pattern.

services /nginx/
nginx

Restart a service

Restart a service.

services name: "nginx" |> restart
nginx
systemctl restart nginx
Restart-Service nginx

Enable a service at boot

Enable a service so that it starts at boot.

services name: "nginx" |> enable
nginx

Query WMI classes

Read a CIM class on Windows.

windows.cim "Win32_OperatingSystem" properties: ["Caption", "Version"]
Caption
Get-CimInstance -ClassName Win32_OperatingSystem

Read a registry value

Read a value of the Windows registry as a path.

read "registry:/HKCU/Software/Example/Mode"
Mode

List the installed packages

List the packages that have a newer version.

package.list outdated: true
package

Search a package

Search the package manager for a program.

package.search "ripgrep"
ripgrep

Install a package

Install a package with the package manager of the host.

package.install ["ripgrep"]
ripgrep
apt install ripgrep

Upgrade the packages

Upgrade all packages of the host.

package.upgrade
package

Schedule a daily job

Run a backup program every day at 03:00.

schedule.create "backup" cron: "0 3 * * *" action: (run ["backup"] cwd: "/home/user")
backup
(crontab -l; echo '0 3 * * * cd /home/user && backup') | crontab -

List the schedules

List the active schedules.

schedule.list state: active
backup

Pause a schedule

Pause a schedule without removing it.

schedule.pause "s4"
s4

Run a schedule now

Run the action of a schedule once, outside its time.

schedule.run "s4"
s4

Show the history of a schedule

Show the last runs of a schedule.

schedule.history "s4" limit: 10
s4

Find a program for a task

Search the programs and packages for a task.

program.search "ocr pdf" limit: 3
ocr

Stop a service

Stop a service and wait for it to exit.

services name: "nginx" |> stop grace: 10s
nginx
systemctl stop nginx
Stop-Service nginx

Disable a service at boot

Prevent a service from starting at boot.

services name: "cups" |> disable
cups
systemctl disable cups

Start a service and wait for it

Start a service and wait up to 30 seconds for it to run.

services name: "postgresql" |> start wait: 30s
postgresql

List the services of the current user

List the services of the user manager instead of the system manager.

services scope: user
service
systemctl --user list-units --type=service

Query the running Windows services

Read two properties of the running services through CIM.

windows.cim "Win32_Service" where: "State = 'Running'" properties: ["Name", "State"]
Name
Get-CimInstance -ClassName Win32_Service -Filter "State = 'Running'"

Install a package in a given version

Install an exact version of a package with a chosen package manager.

package.install ["nodejs"] version: "20.11.0" manager: apt
nodejs

Remove a package

Remove a package with the package manager of the host.

package.remove ["ripgrep"]
ripgrep
apt remove ripgrep

Upgrade selected packages

Upgrade two packages and leave the others unchanged.

package.upgrade ["openssl", "curl"]
openssl

Schedule a job at an interval

Run a cleanup program every six hours.

schedule.create "cleanup" every: 6h action: (run ["cleanup"] cwd: "/home/user")
cleanup

Schedule a weekly job with a time zone

Run a report every Monday at 08:00 in a given time zone, at most twelve times.

schedule.create "report" cron: "0 8 * * 1" timezone: "Europe/Warsaw" max_runs: 12 action: (run ["report"] cwd: "/home/user")
report

Resume a paused schedule

Resume a schedule that was paused.

schedule.resume "s4"
s4

Remove a schedule

Remove a schedule that is no longer needed.

schedule.remove ["s4"]
s4

Locate a program

Show where a program is installed and its version.

program.find ["git"] versions: true
git
command -v git && git --version

Source file on GitHub: docs/cookbook/administration.md