Discourse维护笔记

版本升级

cd /var/discourse
git pull
./launcher rebuild app

磁盘空间清理

每次升级discourse版本,都会build一个新的docker image,下载discourse/base的image,那么进行清理很有必要。

launcher cleanup是discourse内建的一个清理程序,安全且有效

cd /var/discourse
/var/discourse# ./launcher cleanup 

The following command will
- Delete all docker images for old containers
- Delete all stopped and orphan containers

Are you sure (Y/n): Y
Starting Cleanup (bytes free 26462384)
Finished Cleanup (bytes free 37250136)

在清理前,磁盘空间已使用19G

/var/discourse# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   19G   28G  41% /

清理后,腾出来7G的空间,对于小容量的VPS来说,相当可观。这个主要是清理掉了一些无用的docker image

/var/discourse# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   12G   36G  24% /

邮件发送

之前临时使用腾讯的企业邮件来发送discourse邮件,在用户数量略多一点之后,发送就很难成功了。可以使用mailgun代替

My hackintosh build

High Sierra 10.13.5

Components

  • i3 8100
  • ASUS h110m-k d3 MATX board (Add micro code to BIOS, support i3 8100)
  • 8G x 2 DDR3 1600 RAM (For AMD only)
  • Micron 1100 256 GB Solid State Drive
  • Huntkey SUPER 400N 300 Watt SMPS
  • Fenvi FV-T919 BCM94360 WiFi/Bluetooth PCI-E card

The build use integrated graphics Intel UHD 630. The Fenvi FV-T919 card can be driven directly without any changes. I can use my old apple keyboard and trackpad perfectly.

Update BIOS for ASUS motherboard

ASUS h110m-k d3 can’t support i3 8100 directly. But I bought the motherboard from taobao and the seller changed the BIOS to ASRock motherboard already. The motherboard can work with i3 8100 directly but many options are missed for ASUS motherboard T_T

I re-flashed another BIOS file from here. Please note: the default CPU core voltage is too high for i3 8100 in the new BIOS. I change it to 1.040 volt.

BIOS

See the section “Recommended BIOS Settings” at tonymacx86

For iGPU i3 8100, add the bios option

  • Graphics Configuration → DVMT Pre-Allocated : 128MB

The Installation

I followed the Installation Guide at tonymacx86. I used UniBeast to create a bootable High Sierra install on a 16GB USB drive to both format the internal SSD and install macOS.

Options for UniBeast:

  • PCI Devices
    • USB Ownership
    • USB InjectAll

Problem: The USB keyboard and mouse can’t work at the installation screen. I copied the USBInjectAll.kext to /EFI/CLOVER/Kexts/Other and it works again.

Post installation for MultiBeast

  • UEFI Boot mode
  • Drivers > Audio > Realtek ALCxxx > ALC887/888b
  • Drivers > Misc > FakeSMC
  • Drivers > Network > Realtek > RealtekRTL8111 v2.2.2
  • Drivers > USB > Remove XHCI USB port limit
  • Drivers > USB > USBInjectAll
  • Graphics > Intel Graphics Fixup
  • SMBIOS: 17,1

For Intel UHD 630 graphics:

I copied drivers from RehabMan

EFI/CLOVER/Kexts/Other:

  • AppleIntelKBLGraphicsFramebufferInjector_3e9x.kext
  • FakePCIID_Intel_HD_Graphics.kext
  • FakePCIID.kext
  • IntelGraphicsFixup.kext
  • Lilu.kext
  • Shiki.kext

Edit config.plist with Clover Configurator

  • Bootflag: shikigva=1
  • Devices/FakeID/IntelGFX: 0x3E928086
  • Graphics: Inject Intel – Empty ig-platform-id
  • SMBIOS: 17,1

Problem

  • Sleep: Can’t wake from sleep mode

Files

Migrate from MediaWiki to GitBook

Export data from MediaWiki

Using ‘Special:Export’ to export all pages at MediaWiki

  • Go to Special:Allpages and choose the desired article/file.
  • Copy the list of page names to a text editor
  • Put all page names on separate lines. I did this job with Vim.
  • Go to Special:Export and paste all your page names into the textbox, making sure there are no empty lines.
  • Click ‘Submit query’
  • Save the resulting XML to a file using your browser’s save facility.

Now you can use this XML file to next step

Convert MediaWiki documents to markdown format

We have a big XML file now. It contains all pages in MediaWiki. All the pages are in MediaWiki format. pandoc tool can convert the format to markdown directly. But pandoc can’t parse XML file.

I use tool MediaWiki to Markdown to do the job. It’s written in PHP. The conversion uses an XML export from MediaWiki and converts each wiki page to an individual markdown file.

The tool is easy to use. An example convert all pages to Github Flavoured Markdown format.

php convert.php --filename=mediawiki.xml --output=export --format=gfm 

Import data to GitBook

I got many md files in previous step.

  • Create two folders en and zh for multiple languages support
  • Copy all md files to the two folders. Cleanup files for each language.
  • Copy Main_Page.md to SUMMARY.md. It’s the index file for gitbook. I rewrited this file carefully.
  • Create languages file for gitbook
* [English](en/)
* [Chinese](zh/)
  • Create book file for gitbook, Content for book.json.
{
    "plugins": [
        "language-selected",
        "expandable-chapters-small", 
        "-search", 
        "-livereload", 
        "-fontsettings", 
        "-lunr", 
        "-sharing"
    ]
}
  • Install gitbook and preview

Rewrite rule for nginx

I wrote these rewrite rules for nginx. It make the new URLs compatible with original MediaWiki.

        rewrite ^/wiki/Main_Page$ /_book/index.html last;
        rewrite ^/index.html$ /_book/index.html last;
        rewrite ^/gitbook/(.+)$ /_book/gitbook/$1 last;
        rewrite ^/wiki/(.+).html$ /en/$1.html permanent;
        rewrite ^/wiki/(.+)$ /en/$1.html permanent;

        location /en/ {
                try_files $uri /_book$uri /_book$uri.html;
        }

        location /zh/ {
                try_files $uri /_book$uri /_book$uri.html;
        }

Miscs

I have many markdown files from original MediaWiki. It’s too sad gitbook can’t process markdown file outside the SUMMARY.md. You can find more peoples have same problem at the repo of Gitbook. I use the workground to resolve the problem.

DA14580 advertises to a specify channel

For BLE, Channels 37, 38, and 39 are used only for sending advertisement packets. DA14580 advertises at channel 37, 38 and 39 in the example project from Dialog. But sometimes we need it advertises to a specify channel.

Here are the channel define In the file co_bt.h

///Advertising channels enables
enum adv_channel_map
{
  ///Byte value for advertising channel map for channel 37 enable
  ADV_CHNL_37_EN = 0x01,
  ///Byte value for advertising channel map for channel 38 enable
  ADV_CHNL_38_EN,
  ///Byte value for advertising channel map for channel 39 enable
  ADV_CHNL_39_EN = 0x04,
  ///Byte value for advertising channel map for channel 37, 38 and 39 enable
  ADV_ALL_CHNLS_EN = 0x07,
  ///Enumeration end value for advertising channels enable value check
  ADV_CHNL_END
};

Here’s the code to let DA14580 advertises to channel 37

#define APP_ADV_CHMAP ADV_CHNL_37_EN

....

struct gapm_start_advertise_cmd *cmd;
....
cmd->channel_map = APP_ADV_CHMAP;

Simple script for J-Link RTT viewer

I debug NRF52 chip with JLink real time terminal. It’s pretty to use J-Link RTT viewer on my macOS. For example, I ran this command for open a RTT viewer window.

you@yourcomputer:~$JLinkExe -device nRF52 -speed 4000 -if SWD -autoconnect 1

SEGGER J-Link Commander V5.10u (Compiled Mar 17 2016 19:06:22)
DLL version V5.10u, compiled Mar 17 2016 19:06:19

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Mar 15 2016 18:03:17
Hardware version: V1.00
VTref = 3.300V


Type "connect" to establish a target connection, '?' for help

We can use JLinkRTTClient to check the RTT output. But sometimes JLinkRTTClient will not reconnect if the JLinkExe reopened. A simple script can do this job

while true; do nc localhost 19021; sleep 2; done;

I’ve written this line in my makefile.

Install extension for macOS built-in PHP

macOS High Sierra 10.13.3 ships with PHP 7.1.7. I’m trying to install an extension for the built-in PHP. I tried the pecl command but no lucky because SIP (System Integrity Protection) protection. I can’t add file under the directory /usr/lib/php that default php extension directory.

It’s a little difficult but I installed an extension success by compiling manually

Prepare

  • Install packages
brew install autoconf pcre
  • Download PHP source files for built-in PHP
xcode-select --install
  • Edit the /etc/php.ini, change the extension_dir to /usr/local/lib/php/extensions. The directory is writable. You should make the directory yourself.
  • Copy all extension files from /usr/lib/php/extensions to /usr/local/lib/php/extensions
  • Download the extension file and compile it
  • Edit /usr/bin/php-config, find line
extension_dir='/usr/local/lib/php/extensions/no-debug-non-zts-20090626'

and replace it with

extension_dir='/usr/local/lib/php/extensions'

Compile extension

For example, I compile swoole extension with these steps.

  • Download swoole-2.1.1.tgz from pecl.php.net
  • Unzip the file and compile the extension
tar xzvf swoole-2.1.1.tgz
cd swoole-2.1.1
phpize
./configure
make
make install

在macOS下用homebrew安装php 7.1以及pecl

用homebrew默认安装的php 7.1没有包含pecl命令。但是重新安装可以解决这个问题,如果出现libpng不兼容问题,可以加上-s参数

brew remove php71
brew install php71 --with-pear

MediaWiki的维护脚本

MediaWiki的 maintenance 目录下存放着维护脚本,记录一下。

createAndPromote.php

用于创建或者修改已经存在的用户。参数如下

php createAndPromote.php [--bureaucrat] [--sysop] [--bot] [--custom-groups=<group1>,<group2>] [--force] username [password]

示例

php createAndPromote.php --bureaucrat --sysop --custom-groups=developer WikiSysop mypassword

如何将git的master分支整个替换为另外一个分支

我有一个git仓库,其中master分支的代码已经落后几个月了,而另外一个blah分支却一直在持续提交。现在想把blah分支更名为master,同时也更新remote上的master。

这个操作似乎并不能用简单的git branch -m来解决。搜索发现也有不少人有类似需求,贴上解决方法。

方法一

如果blah分支能够快速merge到master分支,那么采用这个方法

git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

方法二

如果分支合并时出现了冲突,而你的remote仓库是github或者bitbucket,那么只能强上了

git branch -m master old-master
git branch -m seotweaks master
git push -f origin master

以上,我的情况只适合第二种,强上成功

配置windows上的git commit时的默认编辑器

在Win下使用github的Git Shell,每次commit时都会弹出记事本,使用不是太爽,想换成vim才顺手。操作步骤如下

  • 安装gvim
  • 将gvim的目录加入Path环境变量中,在 我的电脑 – 属性 - 高级 - 环境变量中修改
  • 配置git
git config --global core.editor gvim
  • 重启Git Shell即可生效!