Automate GHOST updates
Here are my scripts for automaticaly update my GHOST updates on FreeBSD. First i'm listing my rc.d script for starting it:
#!/bin/sh
# PROVIDE: ghost
# REQUIRE: DAEMON SERVERS mysql postgresql slapd
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable powerdns:
#
# ghost_enable="YES"
#
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
. /etc/rc.subr
name="ghost"
rcvar="ghost_enable"
extra_commands="status"
load_rc_config ghost
: ${ghost_enable:="NO"}
status_cmd="ghost_status"
start_cmd="ghost_start"
stop_cmd="ghost_stop"
restart_cmd="ghost_restart"
ghost="/usr/home/ghost"
log="/var/log/ghost/ghost.log"
ghost_start() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever start --minUptime 10000 --spinSleepTime 30000 -al $log current/index.js"
}
ghost_stop() {
sudo -u ghost sh -c "cd $ghost && NODE_ENV=production forever stop current/index.js"
}
ghost_status() {
sudo -u ghost sh -c "NODE_ENV=production forever list"
}
ghost_restart() {
ghost_stop;
ghost_start;
}
run_rc_command "$1"
And here is the script which can be put into the crontab
as example:
#!/usr/local/bin/bash
ghost="/usr/home/ghost"
pushd $ghost
output=`sudo -u ghost -D $ghost /usr/local/bin/ghost check-update`
if [[ "$output" == *"available:"* ]]; then
echo "Checking the permission ..."
sudo -u ghost -D $ghost /usr/bin/find ./ ! -path "./versions/*" -type f -exec chmod 664 {} \;
sudo -u ghost -D $ghost GHOST_NODE_VERSION_CHECK=false /usr/local/bin/ghost update
echo "Restarting ..."
/usr/sbin/service ghost restart
else
echo "No new version of GHOST-CMS detected."
fi
popd