SonarQubeをインストール

  • 久しぶりにSonarQubeをインストールしようと思ったらいろいろ忘れていてハマりました。
    • 特に公式ドキュメントにDBのつくりかたちゃんと書いてないし・・・

Installing the Server - SonarQube Documentation - SonarQube

DB作成

postgres=# CREATE USER sonarqube WITH PASSWORD 'sonarqube';
CREATE ROLE

postgres=# ALTER ROLE sonarqube CREATEDB;
ALTER ROLE

postgres=# CREATE DATABASE sonar WITH ENCODING 'UTF-8' OWNER=sonarqube;
CREATE DATABASE

postgres=# grant all privileges on database sonar to sonarqube;
GRANT

postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 sonarqube | Create DB                                      | {}

postgres=# \l
                                   List of databases
   Name    |   Owner   | Encoding |   Collate   |    Ctype    |    Access privileges
-----------+-----------+----------+-------------+-------------+-------------------------
 postgres  | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 sonar     | sonarqube | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =Tc/sonarqube          +
           |           |          |             |             | sonarqube=CTc/sonarqube
 template0 | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres            +
           |           |          |             |             | postgres=CTc/postgres
 template1 | postgres  | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres            +
           |           |          |             |             | postgres=CTc/postgres
(4 rows)
  • このままだとサーチパスが想定と違うので以下のようなエラーになります。
org.jruby.rack.RackInitializationException: ActiveRecord::JDBCError: ERROR: no schema has been selected to create in: CREATE TABLE "schema_migrations" ("version" varchar(10485760) NOT NULL) 
  • なのでサーチパスの設定をします。

kashi.way-nifty.com

postgres=# ALTER USER sonarqube SET search_path to public;
ALTER ROLE

モジュールのインストール

  • いつの間にかLTSができていたのでちょっと古いけどLTSにしました。
$ cd /usr/local/src
$ wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-4.5.6.zip
$ cd ..
$ unzip src/sonarqube-4.5.6.zip
$ ln -s sonarqube-4.5.6 sonar

設定

  • DBの設定
$ cd sonar/conf
$ vi sonar.properties

#sonar.jdbc.username=sonar
#sonar.jdbc.password=sonarsonar.jdbc.username=sonarqube
sonar.jdbc.password=sonarqube

#----- PostgreSQL 8.x/9.x
#sonar.jdbc.url=jdbc:postgresql://localhost/sonarsonar.jdbc.url=jdbc:postgresql://localhost/sonar
$ vi conf/sonar.properties

#---------------------------------------------------------
# LDAP Plugin
#---------------------------------------------------------

# his property must be defined to ask the Sonar server to use first the LDAP plugin when trying to authenticate a user.
sonar.security.realm=LDAP
# URL of the LDAP server. Note that if you are using ldaps, then you should install server certificate into java truststore.
ldap.url=ldap://ldap.example.com:389
# Bind DN is the username of an LDAP user to connect (or bind) with. Leave blank for anonymous access to the LDAP directory.
ldap.bindDn=cn=user,dc=ldap,dc=example,dc=com
# Bind Password is the password of the user to connect with. Leave blank for anonymous access to the LDAP directory.
ldap.bindPassword=xxxxxxxxxxx

# Distinguished Name (DN) of the root node in LDAP from which to search for users.
ldap.user.baseDn=ou=Users,dc=ldap,dc=example,dc=com
# Attribute in LDAP holding the user’s real name.
ldap.user.realNameAttribute=displayName
  • Proxyの設定
    • 上のLDAPプラグインを入れようとすると、プラグインのダウンロードに失敗する
    • 普通に設定しようとするとエラーが出るのでstackoverflowを参考に設定する

stackoverflow.com

Fail to download the plugin (csharp, version 5.0) from https://sonarsource.bintray.com/Distribution/sonar-csharp-plugin/sonar-csharp-plugin-5.0.jar (error is : Fail to download: https://sonarsource.bintray.com/Distribution/sonar-csharp-plugin/sonar-csharp-plugin-5.0.jar (no proxy))


↓だめ
https.proxyHost=proxy.example.com
https.proxyPort=8080

OK
sonar.web.javaAdditionalOpts=-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=8080

これで動いた

UbuntuのDISK容量がいつの間にか逼迫していた

前提条件

  • 確認しているバージョンはUbuntu 14.04.4 LTSです。
  • Jenkinsのマスターサーバなので一定のDISK空き容量がないと上手く動かなくなるプラグインがある。

対応

  • $ sudo du -sh /*して、でかいディレクトリを調べる
    • どうやら/lib/modulesが肥大化しているらしい
$ cd /lib/modules
$ ll
drwxr-xr-x  5 root root 4096  4月  6  2015 3.13.0-48-generic/
drwxr-xr-x  5 root root 4096  6月  8  2015 3.13.0-53-generic/
drwxr-xr-x  5 root root 4096  1月  4 11:35 3.13.0-74-generic/
drwxr-xr-x  5 root root 4096  3月 11 11:35 3.13.0-79-generic/
drwxr-xr-x  5 root root 4096  3月 30 09:53 3.13.0-83-generic/

$ du -sh *
184M    3.13.0-48-generic
184M    3.13.0-53-generic
184M    3.13.0-74-generic
184M    3.13.0-79-generic
185M    3.13.0-83-generic
  • なにやらでかいkernelモジュールらしきものがいっぱいある
$ sudo aptitude search 3.13.0-48-generic
p   linux-cloud-tools-3.13.0-48-generic                                          - Linux kernel version specific cloud tools for version 3.13.0-48
i A linux-headers-3.13.0-48-generic                                              - Linux kernel headers for version 3.13.0 on 64 bit x86 SMP
p   linux-headers-3.13.0-48-generic:i386                                         - Linux kernel headers for version 3.13.0 on 32 bit x86 SMP
i A linux-image-3.13.0-48-generic                                                - Linux kernel image for version 3.13.0 on 64 bit x86 SMP
p   linux-image-3.13.0-48-generic:i386                                           - Linux kernel image for version 3.13.0 on 32 bit x86 SMP
i A linux-image-extra-3.13.0-48-generic                                          - Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
p   linux-image-extra-3.13.0-48-generic:i386                                     - Linux kernel extra modules for version 3.13.0 on 32 bit x86 SMP
p   linux-signed-image-3.13.0-48-generic                                         - Signed kernel image generic
p   linux-tools-3.13.0-48-generic                                                - Linux kernel version specific tools for version 3.13.0-48
p   linux-tools-3.13.0-48-generic:i386                                           - Linux kernel version specific tools for version 3.13.0-48
  • ほうほう。さくっと消してみるか。
$ sudo aptitude remove linux-headers-3.13.0-48-generic linux-image-3.13.0-48-generic linux-image-extra-3.13.0-48-generic

他の古いバージョンも消してみたらごっそり空いた。

2017/6/29追記

なんと、apt-get autoremoveでさくっと消せることが判明。こんな感じです。

$ sudo apt-get autoremove
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージは「削除」されます:
  linux-headers-4.4.0-77 linux-headers-4.4.0-77-generic linux-image-4.4.0-77-generic linux-image-extra-4.4.0-77-generic
アップグレード: 0 個、新規インストール: 0 個、削除: 4 個、保留: 3 個。
この操作後に 297 MB のディスク容量が解放されます。
続行しますか? [Y/n] Y
(データベースを読み込んでいます ... 現在 131730 個のファイルとディレクトリがインストールされています。)
linux-headers-4.4.0-77-generic (4.4.0-77.98) を削除しています ...
linux-headers-4.4.0-77 (4.4.0-77.98) を削除しています ...
linux-image-extra-4.4.0-77-generic (4.4.0-77.98) を削除しています ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-77-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-81-generic
Found initrd image: /boot/initrd.img-4.4.0-81-generic
Found linux image: /boot/vmlinuz-4.4.0-78-generic
Found initrd image: /boot/initrd.img-4.4.0-78-generic
Found linux image: /boot/vmlinuz-4.4.0-77-generic
Found initrd image: /boot/initrd.img-4.4.0-77-generic
done
linux-image-4.4.0-77-generic (4.4.0-77.98) を削除しています ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-77-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-77-generic /boot/vmlinuz-4.4.0-77-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-81-generic
Found initrd image: /boot/initrd.img-4.4.0-81-generic
Found linux image: /boot/vmlinuz-4.4.0-78-generic
Found initrd image: /boot/initrd.img-4.4.0-78-generic
done

普段使っている aptitude には autoremove が無かった・・・。

Jenkins Pipeline PluginでWindows Batch Scriptを使うと文字化けする

  • またまた、Workflow PluginあらためPipeline Pluginの話です。
  • まあ、さもありなんとは思います。
    • build jobとかbatではないところは当然文字化けてません。
    • UTF-8にしてあげればいいんでしょうねと。
      • chcp 65001してあげることにした。
node('Windows') {
    build job: 'foo', parameters: [new StringParameterValue("branch", branch)]
    
    step ([$class: 'CopyArtifact',
        projectName: "foo",
        filter: "build/libs/*.jar",
        target: "foo/webapps/bar/WEB-INF/lib",
        fingerprintArtifacts: true,
        flatten: true
    ])
    
    bat 'chcp 65001'
    dir('webapp') {
        dirs = ["css", "images", "js"]
        dirs.each {
            bat "xcopy /Y /E /I .\\${it} ..\\foo\\webapps\\bar\\${it}"
        }
    }

これでchcp以降のxcopy等全てのbatが文字化しなくなりました。(なぜか英語で表示されるけど・・・)

Jenkins Pipeline PluginでRobocopyを使うと成功したのにFAILUREで返ってくる

  • Workflow PluginあらためPipeline Pluginを使い始めてます。便利だわー。Groovyだし。

実行したScript

node('Windows') {
    def snapshot = "${env.BUILD_TAG}"
    echo "$snapshot"
    bat "robocopy /E .\\foo \\\\server\\build\\Product\\${snapshot}\\foo"
}
  • これでrobocopyは成功してるのにFAILUREになってしまう。

修正

  • どうやらRobocopyは戻り値が0じゃないらしい

d.hatena.ne.jp

  • とりあえず0で返すようにしました。
node('Windows') {
    def snapshot = "${env.BUILD_TAG}"
    echo "$snapshot"
    bat """robocopy /E .\\foo \\\\server\\build\\Product\\${snapshot}\\foo
                if errorlevel 1 exit /b 0
                if errorlevel 0 exit /b 0"""
}

まあ、こんなもんか。

JIRAのグラフが文字化け(お豆腐)

おそらく日本語フォントだろう

  • ぐぐるとまさにズバリなのがあった

www.ricksoft.jp

対応

  • JIRAはJREを同梱しているのでインストールしたディレクトリのJREをいじる
    • fontconfig.btc, fontconfig.properties.srcには日本語設定が入っていないので以下のように対応した
$ cd /usr/local/jira/jre/lib
$ mv fontconfig.bfc fontconfig.bfc.org
$ mv fontconfig.properties.src fontconfig.properties.src.org
$ ln -s fontconfig.RedHat.6.bfc fontconfig.bfc
$ ln -s fontconfig.RedHat.6.properties.src fontconfig.properties.src
$ sudo aptitude search kochi
$ sudo aptitude install ttf-kochi-gothic ttf-kochi-mincho

上の記事はCentOS前提で、自分の環境はUbuntuだけどとりあえず文字化け直りました。(JIRAの再起動はいるけど)

Ubuntu 14.04 LTSで久々にaptitude使ったらppaのキーでエラーがでた

  • JIRAのインストールするのにまずaptitude updateしたら以下のようなエラーが出る。
W: GPG エラー: http://ppa.launchpad.net trusty InRelease: 公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY A123456789012345

対策

  • ぐぐると以下のようにキーをインポートしなさいというのが出るがうまくいかない。
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.c5xClbKCDL --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpgkeys: key A123456789012345 can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
  • どうやらkeyserverはデフォルトでは80番以外を使うので80番を指定するらしい。あとproxyサーバを指定するがうまくいかない。
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.R94qsVmLPa --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpgkeys: key A123456789012345 can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
  • 手当たり次第にキーサーバのミラーを試してみたらうまくいった。何なんだ・・・。
$ sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.aaFL8YVkoC --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://pgp.mit.edu:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server pgp.mit.edu
gpg: key EEA14886: public key "Launchpad VLC" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

JIRAをインストール(DBをPostgreSQLに作成)

JIRAのDBをPostgreSQLに作る

  • DB作るところは公式ドキュメントと若干変えているので忘れないようにメモ

PostgreSQLにユーザ(ROLE)を作る

  • ロールの作り方は公式ドキュメントに書いてなかったけどBitbucket Server(旧Stash)に合わせて作った。
postgres=# CREATE ROLE jiradbuser WITH PASSWORD 'xxxxxxxxxxxx';
CREATE ROLE
postgres=# ALTER ROLE jiradbuser LOGIN;
ALTER ROLE
postgres=# \du
                              List of roles
 Role name  |                   Attributes                   | Member of
------------+------------------------------------------------+-----------
 jiradbuser |                                                | {}
 postgres   | Superuser, Create role, Create DB, Replication | {}
 stash      |                                                | {}

PostgreSQLにデータベースを作る

  • 公式ドキュメントだとownerを指定してないけどせっかくロールを作ったので指定しておく。
postgres=# CREATE DATABASE jiradb WITH ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0 OWNER=jiradbuser;
CREATE DATABASE
postgres=# \l
                                   List of databases
   Name    |   Owner    | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+------------+----------+-------------+-------------+-----------------------
 jiradb    | jiradbuser | UTF8     | C           | C           |
 postgres  | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 stash     | stash      | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 template0 | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |            |          |             |             | postgres=CTc/postgres
 template1 | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |            |          |             |             | postgres=CTc/postgres
(5 rows)

参考