2.5 KiB
name, description
| name | description |
|---|---|
| common-daemon-cli-skill | Use this skill whenever you need to implement a system daemon mode in your CLI application. |
The "daemon" Subcommand
Every CLI daemon must have a daemon subcommand with the following nested subcommands:
- logs - view logs of the active daemon
- enable - enable the daemon, copy configuration files and the executable itself to system directories
- disable - disable the daemon; if executable files or config were copied to a system directory, do not touch them
- status - show the daemon's status. Is it enabled? If it crashed, what error? The last 50 lines of logs if it crashed.
- env - allows modifying the environment variables with which the daemon runs.
- restart - restarts the daemon
For example:
myrootcommand daemon [ enable / disable / logs / status / env ]
Enabling the Daemon
Enabling the daemon must support the following operating systems:
- Linux-based
- + Systemd
- + OpenRC
- + Init.D
- FreeBSD
- Windows
- MacOS
(The method by which the application is added to autostart is displayed in status)
Enabling includes:
- Copying the configuration file and the application executable to a location where the user won't accidentally delete them. For example, to
/var/lib/*on Linux. If the--no-copyflag is provided, copying is skipped and files remain in their original locations. - Adding the application to autostart with the specified config (if there is a config at all)
- Storing information somewhere publicly accessible that the daemon is enabled.
Disabling
When disabling, check whether the daemon exists or not.
If the daemon does not exist, simply inform the user.
If the daemon is in autostart, remove it from there.
Removing Copies
Removes any copies made during enabling, if they were created.
Activated by the --remove flag.
In this case, a random number between 1000 and 2000 is generated, which must be entered into an interactive input field to confirm.
The CLI explicitly and clearly notifies the user about this.
Environment Configuration (env)
Allows editing / adding / deleting the daemon's environment variables.
Subcommands:
- add - adds a new value; overwrites the old one if it exists
- remove - removes an environment variable
- append - appends to an environment variable using the path separator — for example, on Linux:
$PATH:new_valueand so on.
myrootcommand daemon env append PATH /path/to/my/external/files
myrootcommand daemon restart