RhodeCodeをローカルに立て、Systemd の起動設定書いた

何かやる際、ローカルで mercurial リポジトリ管理できたら便利かなと思った。

ローカルで動かすとしたらそれようの RhodeCode という管理ツールがあると聞き、入れてみた。

環境は Fedora 19。

セットアップしよう。

RhodeCode 1.7.1 documentationInstallationSetup を参考に進めよう。特にハマらないと思う、依存関係でいろいろ入ってくる。

非同期タスク実行に Celery を利用でき、そのメッセージキューイングに Rabbitmq-server 入れると良いかも。

自動起動されると楽だよね。

例えば init script 書いておいて、システムの起動時に起動してくれると楽だよね。

Fedora 19 だと標準で Systemd ってものが入っている、今までの init script の代替。

この Systemd 、最初は init script みたく 1 ファイルでかけるかなと思って、頑張った。どうしてもうまく行かなくてふと Shell Script を書いてそれを呼ぶようにしたらうまくいった。

どんな Systemd, Shell Script かいたのか

rhodecode.sh

以下のように start/stop を引数にとると起動/停止する shell script を書いた。

PASTER が local/bin なのは、 WORK_DIR 配下に virtualenv をたてたため。

#! /bin/sh
WORK_DIR="/path/to/rhodecode"
PASTER="$WORK_DIR/local/bin/paster"
APP_INI="production.ini"
SERV_PID="$WORK_DIR/rhodecode.pid"
CLRYD_PID="$WORK_DIR/celeryd.pid"

function serve_start() {
    $PASTER serve ${APP_INI} --daemon --pid-file=${SERV_PID} start
    $PASTER celeryd ${APP_INI} --pidfile=${CLRYD_PID}
}

function serve_stop() {
    $PASTER serve --stop-daemon --pid-file=${CLRYD_PID}
    $PASTER serve --stop-daemon --pid-file=${SERV_PID}
}

if [ $1 = "start" ]; then
    serve_start
fi

if [ $1 = "stop" ]; then
    serve_stop
fi
rhodecode.service

Systemd 向けの設定ファイル。

[Unit]
Description=RhodeCode Server
After=syslog.target network.target

[Service]
Type=simple
User=hoge
Group=hoge
WorkingDirectory=/path/to/rhodecode
ExecStart=/path/to/rhodecode/rhodecode.sh start
ExecStop=/path/to/rhodecode/rhodecode.sh stop

[Install]
WantedBy=multi-user.target

使い方

以下のように進めれば動く。

$ cd /etc/systemd/system/
$ sudo ln -s /path/to/rhodecode/rhodecode.service .
$ sudo systemctl load rhodecode.service
$ sudo systemctl enable rhodecode.service
$ sudo systemctl start rhodecode.service