-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a lexer for systemd unit files. These unit files can have multiple extensions but this commit only supports the `*.service` file glob at this stage. Co-authored-by: Michael Camilleri <mike@inqk.net>
- Loading branch information
1 parent
2d4976c
commit f039145
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Unit] | ||
Description=Snap Daemon | ||
Requires=snapd.socket | ||
OnFailure=snapd.failure.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
module Rouge | ||
module Lexers | ||
class SystemD < RegexLexer | ||
tag 'systemd' | ||
aliases 'unit-file' | ||
filenames '*.service' | ||
mimetypes 'text/x-systemd-unit' | ||
desc 'A lexer for systemd unit files' | ||
|
||
state :root do | ||
rule %r/\s+/, Text | ||
rule %r/[;#].*/, Comment | ||
rule %r/\[.*?\]$/, Keyword | ||
rule %r/(.*?)(=)(.*)(\\\n)/ do | ||
groups Name::Tag, Punctuation, Text, Str::Escape | ||
push :continuation | ||
end | ||
rule %r/(.*?)(=)(.*)/ do | ||
groups Name::Tag, Punctuation, Text | ||
end | ||
end | ||
|
||
state :continuation do | ||
rule %r/(.*?)(\\\n)/ do | ||
groups Text, Str::Escape | ||
end | ||
rule %r/(.*)'/, Text, :pop! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
describe Rouge::Lexers::SystemD do | ||
let(:subject) { Rouge::Lexers::SystemD::new } | ||
|
||
describe 'guessing' do | ||
include Support::Guessing | ||
|
||
it 'guesses by filename' do | ||
assert_guess :filename => 'unit.service' | ||
end | ||
|
||
it 'guesses by mimetype' do | ||
assert_guess :mimetype => 'text/x-systemd-unit' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[Unit] | ||
Description=Snap Daemon | ||
Requires=snapd.socket | ||
OnFailure=snapd.failure.service | ||
# This is handled by snapd | ||
# X-Snapd-Snap: do-not-start | ||
|
||
[Service] | ||
# Disabled because it breaks lxd | ||
# (https://bugs.launchpad.net/snapd/+bug/1709536) | ||
#Nice=-5 | ||
OOMScoreAdjust=-900 | ||
ExecStart=/usr/lib/snapd/snapd | ||
EnvironmentFile=-/etc/environment | ||
Restart=always | ||
WatchdogSec=5m | ||
Type=notify | ||
SuccessExitStatus=42 | ||
RestartPreventExitStatus=42 | ||
KillMode=process | ||
|
||
[Install] | ||
WantedBy=multi-user.target |