notmycloud.systemd_unit

Ansible Systemd-Unit

説明

グローバルかつ個別ユーザー用のSystemd Unitファイルを生成および設定します。

一般的な使用法

systemd_units 辞書が必要です。 systemd_units の各キーはユーザー名を表し、root/etc/systemd/system にあるシステムユニットを設定します。 各ユーザー名の下で、そのユーザーが待機状態になることを許可するかどうかを指定します。デフォルトは「はい」です。 次に、ユニットの種類を含めます:unittimermount など... 各ユニットタイプに対して、ユニットの設定を含めます。

ユニット定義

config キーは、ユニットファイルのINIスタイルの設定を保持します。キーはユニットファイルオプションに対してケースセンシティブです。この方法を使用することで、ユニットファイルの任意のセクションおよびオプションを定義できます。 オプションは、オーバーライドせずに複数回入力できる配列として定義できます。

このロールは既存のユニットファイルを上書きします!

ユニットオプション

以下のオプションは、ユニット定義ごとに設定できます:

  • enabled: ユニットを起動時に有効にします
  • state: 有効な状態値、デフォルトは「started」
  • restart_on_change: ユニット定義に変更があった場合にユニットを再起動します、デフォルトは「はい」
  • backup_before_write: 定義を書く前にユニットの単一の.bakを作成します、デフォルトは「はい」
  • filepath: デフォルトのユニットファイルパスをオーバーライドすることができます。デフォルトはroot用が /etc/systemd/system、ユーザー用が ~/.config/systemd/user です
---
systemd_units:
  USERNAME: # root のユーザー名は /etc/systemd/system のシステムユニットを処理し、他のユーザーは ~/.config/systemd/user を処理します
    enable_linger: # デフォルトは「はい」
    UNIT_EXTENSION: # service, target, socket など...
      UNIT_NAME: # ユニットのファイル名
        config: # ユニットファイルを構成するオプションを含みます
          SECTION:  # Unit, Service, Install など...
            OPTION: # OPTION=value または OPTION=ARRAY(複数回リストできるオプション用)
        options: # ユニットに適用されるがユニットファイルに入らないオプション
          enabled: # デフォルトは「はい」
          state: # デフォルトは「started」、選択肢: reloaded;restarted;started;stopped.
          restart_on_change: # デフォルトは「はい」
          backup_before_write: # デフォルトは「はい」
          filepath: デフォルトはroot用が /etc/systemd/system、ユーザー用が ~/.config/systemd/user 

例:Logrotate

ファイル: /usr/lib/systemd/system/logrotate.service

[Unit]
Description=ログファイルを回転させる
Documentation=man:logrotate(8) man:logrotate.conf(5)
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf

# パフォーマンスオプション
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

# セキュリティオプション
PrivateDevices=true
PrivateTmp=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectSystem=full
RestrictRealtime=true

ファイル: /usr/lib/systemd/system/logrotate.timer

[Unit]
Description=ログファイルの毎日の回転
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true

[Install]
WantedBy=timers.target

それを構成するための変数: (注意: コメント行は書きません!)

systemd_units:
  root:
    service:
      logrotate:
        config:
          Unit:
            Description: ログファイルを回転させる
            Documentation: 'man:logrotate(8) man:logrotate.conf(5)'
            ConditionACPower: 'true'
          Service:
            Type: oneshot
            ExecStart: /usr/sbin/logrotate /etc/logrotate.conf
            Nice: 19
            IOSchedulingClass: best-effort
            IOSchedulingPriority: 7
            PrivateDevices: 'true'
            PrivateTmp: 'true'
            ProtectControlGroups: 'true'
            ProtectKernelModules: 'true'
            ProtectSystem: full
            RestrictRealtime: 'true'
        options:
          enabled: false
          filepath: /usr/lib/systemd/system/logrotate.service
    timer:
      logrotate:
        config:
          Unit:
            Description: ログファイルの毎日の回転
            Documentation: 'man:logrotate(8) man:logrotate.conf(5)'
          Timer:
            OnCalendar: daily
            AccuracySec: 12h
            Persistent: 'true'
          Install:
            WantedBy: timers.target
        options:
          filepath: /usr/lib/systemd/system/logrotate.timer

サポート

サポートが必要な場合は、以下の項目を提供して問題を報告してください

  • あなたの問題を再現するためのサンプルタスク/プレイブック
  • 作成された結果ファイル
  • 既存ファイルを変更する場合は、未変更のバージョンも提供してください。
プロジェクトについて

Generate and configure Systemd Unit files both globally and for lingering users.

インストール
ansible-galaxy install notmycloud.systemd_unit
ライセンス
mit
ダウンロード
338
所有者