Skip to content

Commit

Permalink
[ghost] switch to ghost-cli's ghost update
Browse files Browse the repository at this point in the history
  • Loading branch information
SalocinHB committed Apr 28, 2022
1 parent f9121ec commit 7ded0ad
Showing 1 changed file with 14 additions and 102 deletions.
116 changes: 14 additions & 102 deletions source/guide_ghost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ You need to change the network interface from ``127.0.0.1`` to

.. code-block:: none
[isabell@stardust ghost] ghost config --ip 0.0.0.0
[isabell@stardust ghost] ghost config --process local
[isabell@stardust ghost] ghost config --port 2368 --ip 0.0.0.0 --process local
[isabell@stardust ghost]
Expand Down Expand Up @@ -213,109 +212,22 @@ Updates

.. note:: Check the update feed_ regularly to stay informed about the newest version.

Download and unzip new version
------------------------------

Check Ghost's `releases <https://github.com/TryGhost/Ghost/releases/latest>`_ for the latest version and copy the link to the ``Ghost-23.42.1.zip`` archive. Make sure not to use the source code zip. In this example the version is 23.42.1, which of course does not exist. Change the version to the latest one in the highlighted lines.

.. code-block:: console
:emphasize-lines: 2,3
[isabell@stardust ~]$ cd ~/ghost/versions/
[isabell@stardust versions]$ wget https://github.com/TryGhost/Ghost/releases/download/v23.42.1/Ghost-23.42.1.zip
[isabell@stardust versions]$ unzip Ghost-23.42.1.zip -d 23.42.1
Archive: Ghost-23.42.1.zip
[isabell@stardust versions]$
Install the required ``node`` modules with ``yarn``
---------------------------------------------------

.. code-block:: console
:emphasize-lines: 1
[isabell@stardust ~]$ cd ~/ghost/versions/23.42.1/content
[isabell@stardust content]$ yarn install --production
[...]
Done in 121.15s.
[isabell@stardust content]$
Migrate your database
---------------------
You can use ``ghost-cli``'s built-in update mechanism. Make sure that local process manager is set to local, then stop ghost, run ``ghost update`` and restart ghost. Sometimes ``ghost update`` will overwrite the port and network interface, so make sure to set that them to 2368 and 0.0.0.0 again.

.. code-block:: console
:emphasize-lines: 2
.. code-block:: none
[isabell@stardust ~]$ cd ~/ghost
[isabell@stardust ~]$ NODE_ENV=production knex-migrator migrate --mgpath ./versions/23.42.1/
[2018-08-22 14:18:21] INFO Creating database backup
[isabell@stardust ~] supervisorctl stop ghost
[isabell@stardust ~] cd ~/ghost
[isabell@stardust ghost] ghost config --process local
[isabell@stardust ghost] ghost update
✔ Checking system Node.js version - found v16.14.2
[…]
[2018-08-22 16:18:23] INFO Finished database migration!
Replace the ``current`` symlink and link to the newest version
--------------------------------------------------------------

Again, replace the version number with the newest version.

.. code-block:: console
:emphasize-lines: 1
[isabell@stardust ~]$ ln -sfn $HOME/ghost/versions/23.42.1 $HOME/ghost/current
[isabell@stardust ~]$ supervisorctl restart ghost
ghost: stopped
ghost: started
[isabell@stardust ~]$ supervisorctl status
ghost RUNNING pid 26020, uptime 0:03:14
[isabell@stardust ~]$
If it's not in state RUNNING, check your configuration.

Update via script
-----------------

As an alternative to this manual process of updating Ghost to a new version you can also use the following script:

.. code-block:: console
:emphasize-lines: 4
#!/bin/bash
#set -v
# created by peleke.de
GHOSTDIR=~/ghost
PACKAGE_VERSION_OLD=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $GHOSTDIR/current/package.json)
CURRENT_GHOST=$(curl -s https://api.github.com/repos/TryGhost/Ghost/releases | grep tag_name | head -n 1 | cut -d '"' -f 4)
CURRENT_GHOST_DOWNLOAD=$(curl -s https://api.github.com/repos/TryGhost/Ghost/releases/latest | grep browser_download_url | cut -d '"' -f 4)
CURRENT_GHOST_FILE=$(echo $CURRENT_GHOST_DOWNLOAD | sed 's:.*/::')
echo "installed version: $PACKAGE_VERSION_OLD"
echo "available version: $CURRENT_GHOST"
cd $GHOSTDIR
if [[ $CURRENT_GHOST != $PACKAGE_VERSION_OLD ]]
then
read -r -p "Do you want to update Ghost $PACKAGE_VERSION_OLD to version $CURRENT_GHOST? [Y/n] " response
if [[ $response =~ ^([yY]|"")$ ]]
then
echo "downloading and unpacking ghost $CURRENT_GHOST ..."
cd $GHOSTDIR/versions/
curl -LOk $CURRENT_GHOST_DOWNLOAD
unzip $GHOSTDIR/versions/$CURRENT_GHOST_FILE -d $CURRENT_GHOST
rm $GHOSTDIR/versions/$CURRENT_GHOST_FILE
echo "Updating ghost ..."
cd $GHOSTDIR/versions/$CURRENT_GHOST
yarn install --production
echo "Migrating ghost database ..."
cd $GHOSTDIR
NODE_ENV=production knex-migrator migrate --mgpath $GHOSTDIR/versions/$CURRENT_GHOST
ln -sfn $GHOSTDIR/versions/$CURRENT_GHOST $GHOSTDIR/current
PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $GHOSTDIR/current/package.json)
echo "Ghost $PACKAGE_VERSION_OLD has been updated to version $PACKAGE_VERSION"
echo "Restarting Ghost. This may take a few seconds ..."
supervisorctl restart ghost
supervisorctl status
echo "If something seems wrong, please check the logs: 'supervisorctl tail ghost'"
echo "To revert to version $PACKAGE_VERSION_OLD run the following command: 'ln -sfn $GHOSTDIR/versions/$PACKAGE_VERSION_OLD $GHOSTDIR/current' and restart ghost using 'supervisorctl restart ghost'."
fi
else
echo "-> Ghost is already up-to-date, no update needed."
fi
✔ Fetched release notes
✔ Downloading and updating Ghost to v4.45.0
✔ Linking latest Ghost and recording versions
ℹ Removing old Ghost versions [skipped]
[isabell@stardust ghost] ghost config --port 2368 --ip 0.0.0.0
[isabell@stardust ghost] supervisorctl start ghost
.. _Ghost: https://ghost.org
Expand Down

0 comments on commit 7ded0ad

Please sign in to comment.