インストール
まず、ghost-cli
をインストールする。完了するとghost
コマンドが利用できるようになる。
> npm install ghost-cli -g
余計なアプリのインストールなどは一切せず、ghostのみをインストールする。
ghost install \
--no-stack \
--no-start \
--no-setup-nginx \
--no-setup-ssl \
--no-setup-linux-user \
--no-setup-mysql \
--no-setup-systemd \
--no-setup-migrate \
--pname ghost-blog \
--dir /home/web/temp/hoge \
--url http://www.xxx.com \
--port 3011 \
--ip 192.168.1.99 \
--db sqlite3 \
--dbpath content/data/huga.db
✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
ℹ Checking operating system compatibility [skipped]
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v2.0.3
✔ Finishing install process
✔ Configuring Ghost
✔ Setting up instance
ℹ Setting up Nginx [skipped]
Task ssl depends on the 'nginx' stage, which was skipped.
ℹ Setting up SSL [skipped]
ℹ Setting up Systemd [skipped]
指定した場所にファイル一式がダウンロード&構築される。直下にconfigファイルがあり、コマンドで指定したパラメータがここに反映される。coreフォルダ以下のconfigファイルはデフォルトのままだった。
> ls hoge
config.production.json content current versions
> cat hoge/config.production.json
{
"url": "http://www.xxx.com",
"server": {
"port": 3011,
"host": "192.168.1.99"
},
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/huga.db"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/home/web/temp/hoge/content"
}
}
ghost コマンドについて
ghost-cli
をインストールすると、コンソールでghost
コマンドが利用できる
> ghost help
ghost [コマンド]
コマンド:
ghost buster Who ya gonna call?
ghost config [key] [value] Configure a Ghost instance
ghost doctor [categories..] Check the system for any potential hiccups when installing/updating
Ghost
ghost install [version] Install a brand new instance of Ghost
ghost log [name] View the logs of a Ghost instance
ghost ls View running ghost processes
ghost migrate Run system migrations on a Ghost instance
ghost restart Restart the Ghost instance
ghost run Run a Ghost instance directly (used by process managers and for
debugging)
ghost setup [stages..] Setup an installation of Ghost (after it is installed)
ghost start Start an instance of Ghost
ghost stop [name] Stops an instance of Ghost
ghost uninstall Remove a Ghost instance and any related configuration files
ghost update [version] Update a Ghost instance
ghost version Prints out Ghost-CLI version (and Ghost version if one exists)
オプション:
--help ヘルプを表示 [真偽]
-d, --dir Folder to run command in
-D, --development Run in development mode [真偽]
-V, --verbose Enable verbose output [真偽]
--prompt [--no-prompt] Allow/Disallow UI prompting [真偽] [デフォルト: true]
--color [--no-color] Allow/Disallow colorful logging [真偽] [デフォルト: true]
For more information, see our docs at https://docs.ghost.org/v1/docs/ghost-cli
ghost ls
コマンドを実行すると、pm2のような画面が表示される(おそらくPM2)
> ghost ls
Running sudo command: systemctl is-active ghost_ghost-blog-1
┌──────────────┬─────────────────────┬─────────┬─────────┬─────┬──────┬─────────────────┐
│ Name │ Location │ Version │ Status │ URL │ Port │ Process Manager │
├──────────────┼─────────────────────┼─────────┼─────────┼─────┼──────┼─────────────────┤
│ ghost-blog-1 │ /home/web/temp/hoge │ 2.0.3 │ stopped │ n/a │ n/a │ n/a │
└──────────────┴─────────────────────┴─────────┴─────────┴─────┴──────┴─────────────────┘
ちなみにghost
コマンドが上記の情報をユーザフォルダ以下の.ghost
で保持している模様
> cd ~/.ghost
> cat config
{
"instances": {
"ghost-blog-1": {
"cwd": "/home/web/temp/hoge"
}
}
}
systemdでデーモン化して使うのが一般的らしいので、登録すると、/lib/systemd/system/
以下にghostの設定ファイルが作成される。
> ghost setup linux-user
> ghost setup systemd
✔ Creating systemd service file at /home/hoge/system/files/ghost_hoge-blog.service
Running sudo command: ln -sf /home/web/hoge/system/files/ghost_hoge-blog.service /lib/systemd/system/ghost_hoge-blog.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
内容はこんな感じ
[Unit]
Description=Ghost systemd service for blog: hoge
Documentation=https://docs.ghost.org
[Service]
Type=simple
WorkingDirectory=/home/web/hoge
User=994
Environment="NODE_ENV=production"
ExecStart=/usr/local/bin/node /usr/local/bin/ghost run
Restart=always
[Install]
WantedBy=multi-user.target
実際に起動してみる
ghost start
Running sudo command: systemctl is-active ghost_hoge-blog
Running sudo command: systemctl reset-failed ghost_hoge-blog
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
Running sudo command: systemctl is-active ghost_hoge-blog
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_hoge-blog
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_hoge-blog
Running sudo command: systemctl enable ghost_hoge-blog --quiet
✔ Enabling Ghost instance startup on server boot
You can access your publication at http://www.xxx.com
Your admin interface is located at http://www.xxx.com/ghost/
> ghost ls
Running sudo command: systemctl is-active ghost_ghost2-blog
┌────────────────────────┬─────────┬──────────────────────┬────────────────────┬──────┬─────────────────┐
│ Name │ Location │ Version │ Status │ URL │ Port │ Process Manager │
├───────────┼────────────┼─────────┼──────────────────────┼────────────────────┼──────┼─────────────────┤
│ hoge-blog │ /home/hoge │ 2.0.3 │ running (production) │ http://www.xxx.com │ 1234 │ systemd │
└───────────┴────────────┴─────────┴──────────────────────┴────────────────────┴──────┴─────────────────┘
実際にURLからアクセスして表示できればOK
Ghost1.xからGhost2.xへのデータ移行
ダメ元で、1.xのDBデータをそのまま2.xに持ってきても起動できなかった。
1.xのときはghost-cliを使ってなかったので、コマンド一発で移行する方法がわからなかったので、一旦1.xでログインして投稿をエクスポートして、そのファイルを2.xでインポートしたらいくつかワーニングが出ていたものの、正常にインポートできた。画像などは、フォルダごと移動するだけで問題なさそう。ちなみにファイルのパーミッションは664でないとだめらしく、起動時にチェックが入る。
sudo find ./ ! -path "./versions/*" -type f -exec chmod 664 {} \;
カスタムテーマに関しては、1.xで動作していれば、ワーニング等は出なかった模様(0.xから1.xは大幅修正があった。。)