userd 0.2.0

A user daemon, managing services and regular running of jobs, in user space.
userd
=====

`userd` is a user daemon, managing services and regular running of jobs, in user space.

Installation
------------

Install with cargo:

```bash
cargo install userd
```

Then the daemon can be stareted with `userd`.

Configuration
-------------

`userd` is configured in a YAML file, located at `~/.config/userd/config`. The configuration file has two root entries:

* `tasks` for running tasks based on different condition (such as every fix interval of time, or when a file is modified, etc.).
   A task is defined by:
   * `triggers`: a list of conditions to trigger the task.
   * `command`: the commands to run.
* `services` for running background processes services. They can be enabled and disabled based on conditions, and restarted on regular intervals, or based on other conditions.
   A task is defined by:
   * `conditions`: a list of conditions to enable the task.
   * `restart_triggers`: a list of conditions to trigger the task.
   * `command`: the commands to run.

Triggers and Restart Triggers
-----------------------------

List of supported triggers:

* `!every`: run the task every `duration` time. Require a `duration`.

Condition
---------

List of supported conditions:

* `!file`: monitor for files changes and check the content of the file.

Commands
--------

Commands is a [nushell](https://www.nushell.sh/) script.

Example
-------

This run a task every 10 minutes, to update a git repository. And run a llama-cpp service, if the AC is connected and a configuration file contains true, it also restart the service every 10 minutes.

```yaml
tasks:
  - name: Update src master
    triggers:
      - !every
        duration: "10m"
    command: |
      cd src/master
      git pull
      echo "was updated"
services:
  - name: llama (for vscode)
    conditions:
      - !file
        filename: /home/myuser/.config/userd/services/llama_vscode
        check:
          !contains
            value: "true"
      - !file
        filename: /sys/class/power_supply/BAT0/status
        negate: true
        check:
          !contains
            value: "Discharging"
        update_check:
          !every
          duration: "1m"
    restart_triggers:
      - !every
        duration: "10m"
    command: |
      /home/myuser/tools/llama.cpp/build/bin/llama-server --hf-repo ggml-org/Qwen2.5-Coder-1.5B-Q8_0-GGUF --port 8012
```