prodarwin
Posts: 16
Joined: Thu Oct 10, 2013 11:34 pm

Run ghost as service on Pi?

Sun Oct 20, 2013 3:15 pm

I'm still a Linux noob, but I've been screwing with the Pi for about a week. It took my 6 or 7 tries to get Ghost installed on my Pi and working as each tutorial I followed had the wrong syntax somewhere, was missing a step, etc.

I now have it installed and I followed this tutorial: http://www.exploringdatascience.com/1/p ... ry-pi.html The only difference is I used ghost-0.3.2.

Now I'm trying to get it to run in the background as a service so I can leave it running when I close the SSH window. Ideally, I would like to do this with an init script, as I would probably need one for a dynamic dns service as well. I'm not having any luck though. (I also tried Forever and Supervisor and failed at both: http://docs.ghost.org/installation/deploy/

Ghost is located in /opt/ghost
Node.js is in /opt/node

Could someone help me with an init script that would start ghost when the Pi boots up?

exhibit_a
Posts: 9
Joined: Sun Oct 20, 2013 7:53 pm

Re: Run ghost as service on Pi?

Sun Oct 20, 2013 8:09 pm

Apparently it seems like you can install a package to npm called supervisor

for more info check: http://docs.ghost.org/installation/deploy/ :D

prodarwin
Posts: 16
Joined: Thu Oct 10, 2013 11:34 pm

Re: Run ghost as service on Pi?

Sun Oct 20, 2013 11:39 pm

I tried that, but it doesn't work. See above.

prodarwin
Posts: 16
Joined: Thu Oct 10, 2013 11:34 pm

Re: Run ghost as service on Pi?

Mon Oct 21, 2013 3:27 am

I was able to modify a startup script I found online to start ghost on system startup:
#! /bin/sh
# /etc/init.d/ghost

### BEGIN INIT INFO
# Provides: ghost
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which wi$
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting ghost"
# run application you want to start
/opt/node/bin/npm start /opt/ghost
;;
stop)
echo "Stopping ghost"
# kill application you want to stop
/opt/node/bin/npm stop /opt/ghost
;;
*)
echo "Usage: /etc/init.d/ghost {start|stop}"
exit 1
;;
esac
Problem is, it doesn't STOP it when I try :

Code: Select all

service /etc/init.d/ghost stop
or

Code: Select all

sudo service /etc/init.d/ghost stop

ghans
Posts: 7878
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Run ghost as service on Pi?

Mon Oct 21, 2013 6:32 am

Either use the service command or call the script directly , but not both.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

exhibit_a
Posts: 9
Joined: Sun Oct 20, 2013 7:53 pm

Re: Run ghost as service on Pi?

Mon Oct 21, 2013 7:08 am

Do you have a different web server installed on you RPI?

The command:

Code: Select all

NODE_ENV=production forever start index.js
Did not work for me as well, as I had lighttpd installed on the RPI. I removed it completely and then re-installed Ghost using your link.

Afterwards I installed forever using this manual: http://www.howtoinstallghost.com/how-to ... h-forever/. Alternatively, you might want to try out this link http://www.howtoinstallghost.com/how-to ... -on-linux/ - but I haven't tried this one.

I have Ghost running on RPI using your link and forever. :D <--- NOT TRUE ANYMORE

It seems like installing forever crashed my installation... :(

exhibit_a
Posts: 9
Joined: Sun Oct 20, 2013 7:53 pm

Re: Run ghost as service on Pi?

Tue Oct 22, 2013 2:46 pm

OK - I've come a step closer to get Ghost running automatically. :geek:

I followed this tutorial: http://www.howtoinstallghost.com/how-to ... pberry-pi/ the actual compiling took quite some time. I'd assume it took an hour or so. I ran make before I left for school, so the exact time is unknown to me.

When it was compiled make install too only a few minutes or so to install it.

A very important piece of information not described on the tutorial site: If you want to change the listening port from 2368 to 80, you must run is as sudo npm start in order to start it properly.

Failing to do so, might give you an output similar to this:

Code: Select all

[email protected] ~/ghost $ npm start

> [email protected] start /home/pi/ghost
> node index


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
    at listen (net.js:1061:10)
    at net.js:1135:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)
npm ERR! weird error 8
npm ERR! not ok code 0
Further, I also made the forever script work - by using this tutorial: http://www.howtoinstallghost.com/how-to ... h-forever/.

Remember, if you have changed the listening port to 80, you must run forever as sudoer i.e. sudo forever start index.js and again if you wish to stop the script you need to do it like this sudo forever start index.js

Everything above works so far for me - the only problem I still have I'm still having issues getting Ghost to run as a start up server. The command NODE_ENV=production forever start index.js does not seem to be working for me - yet. :|

I will have to start it manually every time I reboot my RPI - but it's ok for now. As long as I Ghost now runs as a service... yay! :mrgreen:

prodarwin
Posts: 16
Joined: Thu Oct 10, 2013 11:34 pm

Re: Run ghost as service on Pi?

Tue Oct 22, 2013 6:53 pm

For some reason that tutorial didn't work well for me at all. The installation of ghost didn't work.

One thing that I found weird is that it says nothing about sqlite3 and the installation guide here says to do it before installing ghost: http://www.exploringdatascience.com/1/p ... ry-pi.html

zproc
Posts: 31
Joined: Mon Sep 03, 2012 12:05 pm

Re: Run ghost as service on Pi?

Fri Jan 10, 2014 10:04 pm

I tried a bunch of things today.

node.JS/Ghost runs well as "host: '0.0.0.0'" in config.js

" sudo forever start index.js" works

but "sudo NODE_ENV=production forever start index.js" doesn't work
nor "forever start index.js"

My ghost install is in /opt/ghost. I tried putting the files later as owned by www-data:www-data

and i tried running Nginx as a proxy (having Ghost running as sudo with 127.0.0.1 in config.js) with the following Nginx config in /etc/nginx/sites-avaiable/default, or its own file, linked in sites-enabled :

Code: Select all

server {
     listen 80;
     server_name ghost.mydomain.fr;

     location / {
             proxy_pass http://127.0.0.1:2368/;
             proxy_set_header Host $host;
             proxy_buffering off;

     }
 }
as seen on the Ghost website

but I only get my domain page "/" page. i don't reach the subdomain... anyone has an idea? should I give you my "default" nginx config file? I already have ownCloud configured.

Thanks. :)

Return to “Networking and servers”