Ghost advanced script integration

Install and configure Forever for Ghost

 

Despite the fact that it is not a must have feature to run Ghost, having Forever installed might be a good idea. Forever is a small and simple CLI tool for ensuring that a specific process is running and respawn it in case it exit unexpectedly. In short, it is a good way to keep your Ghost blog running.

 

Further reading:

Ghost Management Tutorial

 
 
 

Ghost Backup and Restore Tutorial

 



If you already have Node.js installed on your system you can easily install Forever using the following command:



/usr/local/bin/npm install -g forever

When you have Forever installed, please stop your Ghost process so we can start it via Forever. This can be done using the following command:

/usr/local/bin/forever -a -l /var/log/ghost start --sourceDir /var/www/ghost index.js

You should replace the two underlined paths to match your current Ghost installation directory and the desired log folder for your Ghost process. When the above command is executed you should see the following output:

warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: index.js

And the following processes should be running on your server:

root 1609 1.8 2.2 661144 23052 ? Ssl 12:17 0:00 /usr/local/bin/node /usr/local/lib/node_modules/forever/bin/monitor index.js
root 1611 5.2 6.7 984856 68524 ? Sl 12:17 0:02 \_ /usr/local/bin/node /var/www/ghost/index.js

This indicates that Forever is monitoring the Ghost processes and will restart it in case it exit.

Forever has a few simple usage options which can help you to manage your Forever monitored processes via the CLI: start, stop, stopall, list:

usage: forever [start | stop | stopall | list] [options] SCRIPT [script options]
options:
tart start SCRIPT as a daemon
stop stop the daemon SCRIPT
stopall stop all running forever scripts
list list all running forever scripts

For example, to see your Ghost blog process please use 'forever list' command:

[root@ghost ghost]# forever list
info: Forever processes running
data: uid command script forever pid logfile uptime
data: [0] 1StY /usr/local/bin/node index.js 1635 1637 /var/log/ghost 0:0:0:6.162

To stop the process you can directly pass the Ghost uid to forever:

[root@ghost ghost]# forever stop 1StY
info: Forever stopped process:
data: uid command script forever pid logfile uptime
[0] 1StY /usr/local/bin/node index.js 1635 1637 /var/log/ghost 0:0:1:10.397

This will command Forever to terminate the process.

 

Further reading:

Ghost Management Tutorial

 
 
 

Ghost Backup and Restore Tutorial

 

How to Create a Start/Stop Script for your Ghost

 

In this tutorial we will show you how to create a simple start up script for your Ghost blog and configure your Ghost installation to start on server boot. Additionally, we will use Forever to monitor the Ghost process to make sure that it runs constantly and does not exit unexpectedly.

First, we will need to install Forever on your server. In case you have not already done this, please following our tutorial on How to install and use Forever with Ghost.

Next, lets create a simple bash script to start your Ghost process upon execution. You can simply copy and paste the following code example into a file called ghost-start.sh:

#!/bin/bash
export PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cd /var/www/ghost
export NODE_ENV=production
NODE_ENV=production /usr/local/bin/forever -a -l /var/log/ghost start --sourceDir /var/www/ghost index.js

Please make sure that the above paths are correct and replace any paths that do not match your local Ghost installation. For example, you might need to change the /var/www/ghost and /var/log/ghost if you have your Ghost installed into a different directory or if you would like to have your Ghost input/output log stored under a different directory. When you are ready simply save the file and exit the text editor.

If you give executable permissions to your file (executing chmod 755 ghost-start.sh should be sufficient) you should be able to run the script and start your Ghost blog now.

Now, let's make sure that your Ghost blog starts upon server reboot. There are different ways to achieve this but the simplest one is to use your operation system cron tab. To achieve this, simply edit your crontab and add the following line:

@reboot /usr/local/bin/ghost-start.sh

Make sure to change the path to your ghost-start.sh script to match your server actual path to the script. You can access your user crontab using the following command:

crontab -e

which will open your use crontab with the default text editor for you to input the needed line.

 

Further reading:

Ghost Management Tutorial

 
 
 

Ghost Backup and Restore Tutorial

 

How to integrate Disqus Comments with Ghost

 

In this tutorial we will show you how to integrate Disqus comments with your Ghost blog. By default, Ghost does not support post comments but you can easily integrate the third party service Disqus comments.

To add Disqus comments to your Ghost blog, you will need to follow these steps:

Step 1: Create a Disqus Account
Step 2: Integrate the Disqus Code

 

Create a Disqus Account

First, you will need to create a Disqus Account. Simply input the desired username, your password and email address to create a free Disqus Account.

On the next page, fill in your Ghost blog name and select a category which best match your blog content. When you are ready, click on the Finish Registration button.

On the next page, you will be displayed with several integration options. In order to integrate Disqus with your Ghost blog you will need to obtain the Disqus integration code by clicking on the Universal Code icon.

From the Setup Instructions you will need to copy the Disqus code.

 

Integrate the Disqus Code

 

When you obtain the Disqus code, the next step will be to integrate the code into your Ghost post.hbs file. The post.hbs is located under your Ghost theme folder. In this guide we will provide instructions on integrating the Disqus code into the default Ghost Casper theme. Most other themes use similar post.hbs syntax thus you should be able to integrate Disqus into any theme.

To access the post.hbs file either edit it directly on your server via any text editor or download it on your local computer with your favorite FTP client. The post.hbs file should be located under:

[YourGhostDir]/content/themes/casper/

Copy the Disqus code and paste it to your post.hbs between {{/post}} and </article> tags. You can see an example of post.hbs with Disqus code integrated here.Please make sure to change.

var disqus_shortname = 'myblogghost'

to your actual shortname provided by Disqus.

When you are ready save your post.hbs file and upload it to your server by overwriting the original file if you have edited the post.hbs locally on your computer. To apply the changes restart your Ghost blog process and the Disqus comment section should be displayed under your posts.

By default Disqus uses the URL as identifier to differentiate posts. Still, this might be problematic because two different URLs might lead to one and the same post such as:

https://www.exampleblog.com/my-post/ and https://exampleblog.com/my-post/

However, Disqus will display different comments depending on the URL. To resolve this you may add an additional line into your Disqus code just after your Disqus short name:

var disqus_shortname = ' yourdisqusshortname '
var disqus_identifier = '{{post.id}}'

Congratulations, you have successfully integrated the Disqus Comment System to your Ghost blog.

 

Further reading:

Ghost Management Tutorial

 
 
 

Ghost Backup and Restore Tutorial

 

How to Transfer your WordPress Posts to Ghost

 

In this guide we will show you how to transfer your WordPress posts to your Ghost blog. To achieve this you will need to install WordPress Ghost Plugin into your WordPress blog.

First, log into your WordPress Admin Dashboard and refer to Plugins ? Add New.

Input the WordPress Ghost Plugin name into the Search field and install the Ghost plugin.

Activate the plugin after the installation by clicking on the Activate Plugin link available on the installation page.

When you have the Ghost plugin installed and activated refer to the Tools ? Export Ghost menu from the main navigation on the left. From the Ghost export plugin page click on the Download Ghost File button.

When you have your WordPress posts exported to a file stored on your local computer, please refer to your Ghost blog admin dashboard debug section. You can access the Ghost admin debug section using the following URL:

http://example.com/ghost/debug/

Please replace example.com with your actual domain or IP address to access your Ghost Admin Dashboard.

From the debug page click on the Choose File button next to the import option and select the file exported from your WordPress blog and click the Import button.

Your WordPress posts should be visible in your Ghost blog now.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Basic Features of the Ghost CMS

Todhost web hosting supports Ghost installation. You can easily setup your website with Ghost...

How to migrate your website from WordPress to Ghost

The Ghost project is led by John O'Nolan and Hannah Wolfe, both of whom have been involved with...

Ghost Installation Tutorial

In this tutorial, we look at the various means to install the Ghost CMS. The options are to...

Ghost Configuration Tutorial

By default Ghost uses sqlite3 database. Still, if you would like to have your Ghost Blog...

Ghost Management Tutorial

How to use the Ghost Publishing Platform   In order to make it easier for users to deploy and...

Powered by WHMCompleteSolution