Systemd

Parses systemd unit files.

Author: Dominic Cleal dcl.nosp@m.eal@redha.nosp@m.t.com

Summary
SystemdParses systemd unit files.
ReferenceThis lens tries to keep as close as possible to systemd.unit(5) and systemd.service(5) etc where possible.
LicenseThis file is licenced under the LGPL v2+, like the rest of Augeas.
Lens UsageTo be documented
Configuration filesThis lens applies to /lib/systemd/system/* and /etc/systemd/system/*.
USEFUL PRIMITIVES
eol
eol_commentAn IniFile.comment entry for standalone comment lines (; or #)
eol_commentAn IniFile.comment entry for end of line comments (# only)
sepAn IniFile.sep entry
entry_single_kw
entry_command_kw
entry_env_kw
entry_multi_kw
value_single_re
sto_value_singleSupport multiline values with a backslash
sto_value
value_sepMulti-value entries separated by whitespace or backslash and newline
value_cmd_re
env_key
ENTRIES
entry_fnPrototype for our various key=value lines, with optional comment
entry_valueStore a value that doesn’t contain spaces
entry_singleEntry that takes a single value containing spaces
entry_commandEntry that takes a space separated set of values (the default)
entry_command_flagsExec* flags “@” and “-”.
entry_commandEntry that takes a command, arguments and the optional prefix flags
entry_envEntry that takes a space separated set of ENV=value key/value pairs
LENS
entryAn IniFile.entry
includeIncludes another file at this position
titleAn IniFile.title
recordAn IniFile.record
lnsAn IniFile.lns
filter

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/*.  See filter.

USEFUL PRIMITIVES

eol

let eol = Util.eol

eol_comment

An IniFile.comment entry for standalone comment lines (; or #)

eol_comment

let eol_comment = IniFile.comment "#" "#"

An IniFile.comment entry for end of line comments (# only)

sep

let sep = IniFile.sep "=" "="

An IniFile.sep entry

entry_single_kw

let entry_single_kw = "Description"

entry_command_kw

let entry_command_kw = /Exec[A-Za-z][A-Za-z0-9._-]+/

entry_env_kw

let entry_env_kw = "Environment"

entry_multi_kw

let entry_multi_kw = let forbidden = entry_single_kw | entry_command_kw | entry_env_kw in /[A-Za-z][A-Za-z0-9._-]+/ - forbidden

value_single_re

let value_single_re = /[^# \t\n\\][^#\n\\]*[^# \t\n\\]|[^# \t\n\\]/

sto_value_single

let sto_value_single = Util.del_opt_ws "" . store (value_single_re . (/\\\\\n/ . value_single_re)*)

Support multiline values with a backslash

sto_value

let sto_value = store /[^# \t\n]*[^# \t\n\\]/

value_sep

let value_sep = del /[ \t]+|[ \t]*\\\\[ \t]*\n[ \t]*/ " "

Multi-value entries separated by whitespace or backslash and newline

value_cmd_re

let value_cmd_re = /[^#@ \t\n\\-][^#@ \t\n\\-][^# \t\n\\]*/
Don’t parse @ andprefix flags

env_key

let env_key = /[A-Za-z0-9_]+(\[[0-9]+\])?/

ENTRIES

entry_fn

let entry_fn (kw:regexp) (val:lens) = [ key kw . sep . val . (eol_comment|eol) ]

Prototype for our various key=value lines, with optional comment

entry_value

let entry_value = [ label "value" . sto_value ]

Store a value that doesn’t contain spaces

entry_single

let entry_single = entry_fn entry_single_kw [ label "value" . sto_value_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

let entry_command_flags = let exit = [ label "ignoreexit" . Util.del_str "-" ] in let arg0 = [ label "arg0" . Util.del_str "@" ] in exit? . arg0?

Exec* flags “@” and “-”.  Order is important, see systemd.service(8)

entry_command

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

entry_env

let entry_env = let envkv (env_val:lens) = key env_key . Util.del_str "=" . env_val

Entry that takes a space separated set of ENV=value key/value pairs

LENS

entry

let entry = entry_single | entry_multi | entry_command | entry_env | comment

An IniFile.entry

include

let include = [ key ".include" . Util.del_ws_spc . sto_value . (eol_comment|eol) ]

Includes another file at this position

title

let title = IniFile.title IniFile.record_re

An IniFile.title

record

let record = IniFile.record title (entry|include)

An IniFile.record

lns

let lns = IniFile.lns record (comment|include)

An IniFile.lns

filter

let eol = Util.eol
let comment (pat:regexp) (default:string) = Util.comment_generic_seteol (Rx.opt_space . pat . Rx.opt_space) default eol
Map comments into “#comment” nodes
let eol_comment = IniFile.comment "#" "#"
An IniFile.comment entry for end of line comments (# only)
let sep = IniFile.sep "=" "="
An IniFile.sep entry
let sep (pat:regexp) (default:string) = Sep.opt_space . del pat default
Generic separator
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\\]/
let sto_value_single = Util.del_opt_ws "" . store (value_single_re . (/\\\\\n/ . value_single_re)*)
Support multiline values with a backslash
let sto_value = store /[^# \t\n]*[^# \t\n\\]/
let value_sep = del /[ \t]+|[ \t]*\\\\[ \t]*\n[ \t]*/ " "
Multi-value entries separated by whitespace or backslash and newline
let value_cmd_re = /[^#@ \t\n\\-][^#@ \t\n\\-][^# \t\n\\]*/
let env_key = /[A-Za-z0-9_]+(\[[0-9]+\])?/
let entry_fn (kw:regexp) (val:lens) = [ key kw . sep . val . (eol_comment|eol) ]
Prototype for our various key=value lines, with optional comment
let entry_value = [ label "value" . sto_value ]
Store a value that doesn’t contain spaces
let entry_single = entry_fn entry_single_kw [ label "value" . sto_value_single ]?
Entry that takes a single value containing spaces
let entry_command_flags = let exit = [ label "ignoreexit" . Util.del_str "-" ] in let arg0 = [ label "arg0" . Util.del_str "@" ] in exit? . arg0?
Exec* flags “@” and “-”.
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 entry_env = let envkv (env_val:lens) = key env_key . Util.del_str "=" . env_val
Entry that takes a space separated set of ENV=value key/value pairs
let entry = entry_single | entry_multi | entry_command | entry_env | comment
An IniFile.entry
let entry (kw:regexp) (sep:lens) (comment:lens) = entry_generic (key kw) sep comment_re comment
Generic INI File entry
let include = [ key ".include" . Util.del_ws_spc . sto_value . (eol_comment|eol) ]
Includes another file at this position
let title = IniFile.title IniFile.record_re
An IniFile.title
let title (kw:regexp) = Util.del_str "[" . key kw . Util.del_str "]". eol
Title for record.
let record = IniFile.record title (entry|include)
An IniFile.record
let record (title:lens) (entry:lens) = record_noempty title ( entry | empty )
Generic INI File record
let lns = IniFile.lns record (comment|include)
An IniFile.lns
let lns (record:lens) (comment:lens) = lns_noempty record (comment|empty)
Generic INI File lens
Close