Skip to content

Commit

Permalink
systemd 用サービスファイルの追加
Browse files Browse the repository at this point in the history
RGRB を systemd で制御するためのサービスファイルと、そのドキュメントを追加した。
また、追加したドキュメントへのリンクを README.md に追記した。
  • Loading branch information
koi-chan committed Mar 15, 2015
1 parent c63ebb4 commit 4c8f777
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ cd /path/to/rgrb
bin/rgrb-ircbot -c /path/to/config_file
```

systemd による制御を行なう場合は [systemd](doc/system/systemd.md) を参照してください。

開発者向けドキュメントの生成
----------------------------

Expand Down
18 changes: 18 additions & 0 deletions doc/system/rgrb.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=RGRB - Internet Relay Chat bot
Documentation=http://www.cre.ne.jp/services/irc/bots/rgrb
After=network.target

[Service]
User=irc
Group=irc
Type=simple
PIDFile=/home/irc/rgrb/rgrb.pid
WorkingDirectory=/home/irc/rgrb
ExecStart=/home/irc/rgrb/bin/rgrb-ircbot -c config/rgrb.yaml
#ExecReload=/usr/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/kill $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target
18 changes: 18 additions & 0 deletions doc/system/rgrb@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=RGRB - Internet Relay Chat bot
Documentation=http://www.cre.ne.jp/services/irc/bots/rgrb
After=network.target

[Service]
User=irc
Group=irc
Type=simple
PIDFile=/home/irc/rgrb/%I.pid
WorkingDirectory=/home/irc/rgrb
ExecStart=/home/irc/rgrb/bin/rgrb-ircbot -c config/%I.yaml
#ExecReload=/usr/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/kill $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target
54 changes: 54 additions & 0 deletions doc/system/systemd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
systemd 用サービスファイル
==========================

ファイル目次
------------

* rgrb.service
通常のサービスファイルです。
* rgrb@.service
テンプレートサービスファイルです。

使い方
------

以下の項目を前提としてサービスファイルを作成しています。

* RGRB を専用ユーザー"irc"のホームディレクトリにインストールする
* 専用ユーザーの権限で実行する
* 何らかの要因で終了した場合、自動的に再起動する

各システムの定められた場所に、上記のサービスファイルをコピーします。
例えば CentOS7 では、`/etc/systemd/system` です。

### サービスファイルに指定する設定値

1つの RGRB を運用するだけでしたら、通常のサービスファイルで十分でしょう。
通常のサービスファイル (rgrb.service) を上記ディレクトリにコピーします。

お使いのシステムにあわせて *[Service]* 内にある各項目の設定値を書き換えます。

| 項目名 | 設定値 |
| ------ | ------ |
|User|プロセスの実行ユーザー|
|Group|プロセスの実行グループ|
|PIDFile|プロセスの PID を保存するファイル|
|WorkingDirectory|RGRB のルートディレクトリ|
|ExecStart|フルパスで RGRB の起動ファイルとオプション|
|ExecReload|現在、RGRB はリロードに対応していないためコメントアウト|
|ExecStop|終了するためのコマンド|
|Restart|*always* を設定すると自動再起動有効|

*ExecXXXX* に指定するコマンドは、すべてフルパスで記述します。
RGRB に与えるオプションのうち、設定ファイルは *WorkingDirectory* からの相対パスを利用することができます。

複数の RGRB の設定ファイルを用意し、同時並行で利用する場合でしたら、テンプレートサービスファイルを使うことをお勧めします。
テンプレートサービスファイルを利用する場合、```systemctl``` コマンドに与えるサービス名が、*<サービス名>@<識別名>* という書式になります。
テンプレートサービスファイル内では、設定値内の *%I* がサービス起動時に与える *<識別名>* に置換されてコマンドが実行されます。
デフォルト設定では、 ```config/``` ディレクトリ以下に置いた設定ファイルの(拡張子を除いた)ファイル名が *<識別名>* になるように書かれています。

参考文献
--------

1. [Linux女子部 systemd徹底入門](http://www.slideshare.net/enakai/linux-27872553)
1. [systemd.exec](http://www.freedesktop.org/software/systemd/man/systemd.exec.html)

0 comments on commit 4c8f777

Please sign in to comment.