2018年12月29日土曜日

gogsの移動

以前から少しずつやっている自宅サーバーの環境移行。

gitリポジトリ保存用にgogsを使っているのだけど、これを移動させたいと思う。gogsやmariadbバージョンが移行前後で随分違うからすごくハマった。

移行元の環境

かなり昔に構築したため、詳細は全く覚えていない。

  1. gitというユーザーがある

  2. /home/gitにgogsとgogs-repositoriesがある

  3. インストールしていたバージョンは「gogs_v0.9.13_linux_386.tar.gz」みたい。。

  4. /etc/systemd/system/gogs.serviceがある

  5. DBはMariaDB 5.5.45を使用

上記から、おそらく

https://gogs.io/docs/intro/faqs#how-do-i-run-gogs-at-startup-with-systemd%3F

あたりを参考にインストールしたのではないかと思う。

データの引き継ぎについて

このあたりに詳しく書いてあった。コピペでできるのか・・

https://gogs.io/docs/upgrade/upgrade_from_binary

移行先での作業

ユーザー作成

ここでいうユーザーはgogsを起動するユーザー。

gogsのページだとgitになっている。


adduser git

gogsのダウンロード

https://dl.gogs.io/0.11.79/gogs_0.11.79_linux_amd64.zip

/home/gitに展開する。

所有者をgitにしておく。

DBサーバーの準備

mariaDB 10.1.34を使用することにした


apt-get install mariadb-server

apt-get install mariadb-client

rootのパスワード忘れたぁOrz

やれやれ・・・。

https://qiita.com/y1row/items/994ecf8b478b7aac4c7d

https://ips.nekotype.com/3426/

https://better-coding.com/solved-xterm-256color-unknown-terminal-type/

gogs用のデータベースとユーザーの作成


create user 'gogs'@'localhost' identified by '<password>';

create database gogs_git;

grant all on gogs_git.* to 'gogs'@'localhost';

データの移行

先述のデータの引き継ぎ方法にしたがって作業を行う

gogsとgogs-repositoriesを移行元からコピー

移行元から移行先にコピー


scp -r gogs git@移行先:/home/git/gogs_old

scp -r gogs-repositories git@移行先:/home/git/

続いて移行先で


cp -R gogs_old/custom gogs/

cp -R gogs_old/data gogs/

cp -R gogs_old/log gogs/

DBの移行

移行元で


mysqldump -u root -p gogs_git > gogs_bkup.dump.sql

移行先で


mysql -u gogs -p gogs_git < gogs_bkup.dump.sql

これでコピー完了。

テスト起動

コピーが終わったので、テストで起動してみる

gitユーザーで


./gogs web

でlocalhost:3000にアクセス・・・あれタイムアウト。。

切り分け

そもそもデータを引き継がない場合に、ちゃんと起動するか

起動自体はしたが、インストール画面で

Error 1071: Specified key was too long; max key length is 767 bytes

な、なんだこれ???

あーめんどくせー。ぐぐってみたら

https://github.com/gogs/gogs/issues/4992

この通りやってみたら、とりあえずログイン画面まで行けた。

ということは、データを引き継いだ場合もこの手順でいけるのかな?

ということで、同じ手順でやってみたらログイン画面・ログイン後のダッシュボードなどなど行けた。

自動起動設定

移行元の設定と同じような記載があったので、この通りにやってみる。

https://gogs.io/docs/intro/faqs#how-do-i-run-gogs-at-startup-with-systemd%3F


# cat /etc/systemd/system/gogs.service

  

[Unit]

Description=Gogs (Go Git Service)

After=syslog.target

After=network.target

After=mysqld.service

  

[Service]

# Modify these two values and uncomment them if you have

# repos with lots of files and get an HTTP error 500 because

# of that

###

#LimitMEMLOCK=infinity

#LimitNOFILE=65535

Type=simple

User=git

Group=git

WorkingDirectory=/home/git/gogs

ExecStart=/home/git/gogs/gogs web

Restart=always

Environment=USER=git HOME=/home/git

  

[Install]

WantedBy=multi-user.target

自動起動テスト


systemctl enable gogs

>Created symlink /etc/systemd/system/multi-user.target.wants/gogs.service → /etc/systemd/system/gogs.service.

systemctl start gogs

systemctl status gogs

● gogs.service - Gogs (Go Git Service)

Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: ena

Active: active (running) since Sat 2018-12-29 00:46:16 JST; 9s ago

Main PID: 6978 (gogs)

Tasks: 8 (limit: 4915)

CGroup: /system.slice/gogs.service

└─6978 /home/git/gogs/gogs web

  

12月 29 00:46:16 blackcube systemd[1]: Started Gogs (Go Git Service).

12月 29 00:46:16 blackcube gogs[6978]: 2018/12/29 00:46:16 [TRACE] Custom path:

12月 29 00:46:16 blackcube gogs[6978]: 2018/12/29 00:46:16 [TRACE] Log path: /ho

12月 29 00:46:16 blackcube gogs[6978]: 2018/12/29 00:46:16 [TRACE] Log Mode: Fil

12月 29 00:46:16 blackcube gogs[6978]: 2018/12/29 00:46:16 [ INFO] Gogs: Go Git

systemdに登録できて、起動できたので、これで移行完了!!

つかれたー。空き時間でやっていたから思い立ってから1か月もかかった。Orz.