WordPress

How to properly migrate a WordPress site

Intro

WordPress store URLs of the pages, articles, media and all other content in database as absolute paths.

This mean that you need to update URLs when the site address changes, the simple database copy may lead to errors or increased load time, because of increased number of load requests.

For a proper migration, you have to copy the files to the new location and migrate the database. To copy the files you can use the hosting panel File Manager (if available), FTP or SSH. For the database migration – check the instructions bellow. Continue reading How to properly migrate a WordPress site

Rocket.Chat

Watchdog and start scripts for Rocket.Chat application

I installed recently Rocket.Chat on a server. The next day I checked it – the service was not running. So I wrote a small script that checks if the application port 3000 is in use and run another script if not.

The scrip is quite simple. The core utility nc is used to check the port availability and set the value for the parameter PORTCHECK depending on the state. Next it uses an if statement to just echo a message if the port is in use, otherwise it run the Rocket.Chat starting script.

Here is the code on that script /opt/rocketwatchdog.sh:
#!/bin/sh
PORTCHECK=$(nc -z -w 3 localhost 3000; echo $?)
DATESTAMP=$(date +”%Y-%m-%d-%T”)
if [ “$PORTCHECK” = 0 ]; then
echo “RocketChat server is already running”
echo “$DATESTAMP App is running.” >> /var/log/watchdog.log
else
echo “RocketChat server is not running. Will try to start it.”
echo “$DATESTAMP RocketChat is not running, restart it.” >> /var/log/watchdog.log
/bin/sh /opt/rocketchat.sh
fi

You should add a cronjob that will check each minute is the server is running. Enter crontab -e to open cron jobs list, add at the end:
* * * * * /bin/sh /opt/rocketwatchdog.sh

Here is the script to start Rocket.Chat /opt/rocketchat.sh:
#!/bin/sh
export PORT=3000
export ROOT_URL=https://chat.mydomain.com/
export MONGO_URL=mongodb://localhost:27017/rocketchat
cd /opt/rocket/
nohup /usr/local/bin/node main.js > /var/log/rocketchat.log 2>&1 &

jenkins

Recover access to Jenkins

Have you lost the password for Jenkins? Or maybe you changed some security settings and now you cant log in?

You need to recover access. This is quite simple. The strategy will be to disable security for Jenkins,  login and reset user’s password (you can also create a new user), re-enable security.

By default in Linux, Jenkins is installed into location /var/lib/jenkins. you will need to edit the configuration file here: config.xml and change <useSecurity>true</useSecurity> to <useSecurity>false</useSecurity> then restart Jenkins service: service jenkins restart
Open Jenkins WEB console, go to People, click on the username, Configure, set the new password and save changes.

You now have access to Jenkins!

PS: I presume you have SSH access to server. It worked for me with Ubuntu 14.04/Debian 8.5 and Jenkins 2.7.2