Parses systemd unit files.
Author: Dominic Cleal dcl@redha t.com eal
Systemd | Parses systemd unit files. |
Reference | This lens tries to keep as close as possible to systemd.unit(5) and systemd.service(5) etc where possible. |
License | This file is licenced under the LGPL v2+, like the rest of Augeas. |
Lens Usage | To be documented |
Configuration files | This lens applies to /lib/systemd/system/* and /etc/systemd/system/*. |
USEFUL PRIMITIVES | |
eol | |
eol_comment | An IniFile.comment entry for standalone comment lines (; or #) |
eol_comment | An IniFile.comment entry for end of line comments (# only) |
sep | An IniFile.sep entry |
entry_single_kw | |
entry_command_kw | |
entry_env_kw | |
entry_multi_kw | |
value_single_re | |
sto_value_single | Support multiline values with a backslash |
sto_value | |
value_sep | Multi-value entries separated by whitespace or backslash and newline |
value_cmd_re | |
env_key | |
ENTRIES | |
entry_fn | Prototype for our various key=value lines, with optional comment |
entry_value | Store a value that doesn’t contain spaces |
entry_single | Entry that takes a single value containing spaces |
entry_command | Entry that takes a space separated set of values (the default) |
entry_command_flags | Exec* flags “@” and “-”. |
entry_command | Entry that takes a command, arguments and the optional prefix flags |
entry_env | Entry that takes a space separated set of ENV=value key/value pairs |
LENS | |
entry | An IniFile.entry |
include | Includes another file at this position |
title | An IniFile.title |
record | An IniFile.record |
lns | An IniFile.lns |
filter |
This lens applies to /lib/systemd/system/* and /etc/systemd/system/*. See filter.
An IniFile.comment entry for standalone comment lines (; or #)
let eol_comment = IniFile.comment "#" "#"
An IniFile.comment entry for end of line comments (# only)
let sep = IniFile.sep "=" "="
An IniFile.sep entry
let entry_command = let cmd = [ label "command" . store value_cmd_re ] in let arg = [ seq "args" . sto_value ] in let args = [ counter "args" . label "arguments" . (value_sep . arg)+ ] in entry_fn entry_command_kw ( entry_command_flags . cmd . args? )?
Entry that takes a command, arguments and the optional prefix flags
let lns = IniFile.lns record (comment|include)
An IniFile.lns
let eol = Util.eol
Map comments into “#comment” nodes
let comment (pat:regexp) (default:string) = Util.comment_generic_seteol (Rx.opt_space . pat . Rx.opt_space) default eol
An IniFile.comment entry for end of line comments (# only)
let eol_comment = IniFile.comment "#" "#"
An IniFile.sep entry
let sep = IniFile.sep "=" "="
Generic separator
let sep (pat:regexp) (default:string) = Sep.opt_space . del pat default
let entry_single_kw = "Description"
let entry_command_kw = /Exec[A-Za-z][A-Za-z0-9._-]+/
let entry_env_kw = "Environment"
let entry_multi_kw = let forbidden = entry_single_kw | entry_command_kw | entry_env_kw in /[A-Za-z][A-Za-z0-9._-]+/ - forbidden
let value_single_re = /[^# \t\n\\][^#\n\\]*[^# \t\n\\]|[^# \t\n\\]/
Support multiline values with a backslash
let sto_value_single = Util.del_opt_ws "" . store (value_single_re . (/\\\\\n/ . value_single_re)*)
let sto_value = store /[^# \t\n]*[^# \t\n\\]/
Multi-value entries separated by whitespace or backslash and newline
let value_sep = del /[ \t]+|[ \t]*\\\\[ \t]*\n[ \t]*/ " "
let value_cmd_re = /[^#@ \t\n\\-][^#@ \t\n\\-][^# \t\n\\]*/
let env_key = /[A-Za-z0-9_]+(\[[0-9]+\])?/
Prototype for our various key=value lines, with optional comment
let entry_fn (kw:regexp) (val:lens) = [ key kw . sep . val . (eol_comment|eol) ]
Store a value that doesn’t contain spaces
let entry_value = [ label "value" . sto_value ]
Entry that takes a single value containing spaces
let entry_single = entry_fn entry_single_kw [ label "value" . sto_value_single ]?
Exec* flags “@” and “-”.
let entry_command_flags = let exit = [ label "ignoreexit" . Util.del_str "-" ] in let arg0 = [ label "arg0" . Util.del_str "@" ] in exit? . arg0?
Entry that takes a command, arguments and the optional prefix flags
let entry_command = let cmd = [ label "command" . store value_cmd_re ] in let arg = [ seq "args" . sto_value ] in let args = [ counter "args" . label "arguments" . (value_sep . arg)+ ] in entry_fn entry_command_kw ( entry_command_flags . cmd . args? )?
Entry that takes a space separated set of ENV=value key/value pairs
let entry_env = let envkv (env_val:lens) = key env_key . Util.del_str "=" . env_val
An IniFile.entry
let entry = entry_single | entry_multi | entry_command | entry_env | comment
Generic INI File entry
let entry (kw:regexp) (sep:lens) (comment:lens) = entry_generic (key kw) sep comment_re comment
Includes another file at this position
let include = [ key ".include" . Util.del_ws_spc . sto_value . (eol_comment|eol) ]
An IniFile.title
let title = IniFile.title IniFile.record_re
Title for record.
let title (kw:regexp) = Util.del_str "[" . key kw . Util.del_str "]". eol
An IniFile.record
let record = IniFile.record title (entry|include)
Generic INI File record
let record (title:lens) (entry:lens) = record_noempty title ( entry | empty )
An IniFile.lns
let lns = IniFile.lns record (comment|include)
Generic INI File lens
let lns (record:lens) (comment:lens) = lns_noempty record (comment|empty)