Gitlab 500/502 Error After Upgrade

Here is what happen, i got either a 500 or 502 error after an upgrade using Omnibus method. And got the error message "Gitlab is not responding"

40TPT

The first thing i did was to look for what could have happen. And the first place to see that is on the log file located at

/var/log/gitlab/gitlab-rails/production.log

And the log basically just give me an error as shown below,

Started GET "/users/sign_in" for 175.144.6.68 at 2015-12-12 23:48:54 +0800
Processing by SessionsController#new as HTML
Completed 500 Internal Server Error in 98ms (ActiveRecord: 10.8ms)

NoMethodError (undefined method `push_events=' for #<GitlabCiService:0x0000000463dba8>):
  app/models/project.rb:809:in `builds_enabled='
  app/controllers/application_controller.rb:194:in `add_gon_variables'

But when i do a status check, it gives me this

[root@git gitlab-rails]# gitlab-ctl status
run: gitlab-workhorse: (pid 4934) 1009s; run: log: (pid 4147) 1227s
run: logrotate: (pid 4942) 1008s; run: log: (pid 296) 3434s
run: nginx: (pid 4948) 1008s; run: log: (pid 299) 3434s
run: postgresql: (pid 4957) 1007s; run: log: (pid 301) 3434s
run: redis: (pid 4965) 1007s; run: log: (pid 294) 3434s
run: sidekiq: (pid 4972) 1005s; run: log: (pid 302) 3434s
run: unicorn: (pid 4990) 1004s; run: log: (pid 305) 3434s

I have pretty much no idea what is going on. But after trying out different ways, it seems to boil down to the following,

1. Check what is going on

Firing the following command should give you an idea what is going on with your configure.

sudo gitlab-rake gitlab:check

After that you could try see what is causing it.

2. Forget to turn on postgres before upgrade

Well, because gitlab said to shutdown gitlab before upgrading, hence i did this,

gitlab-ctl stop

which stops everything including postgres. Hence, database migration wasn't possible. Therefore, i fire the following command and see whether that helps

gitlab-rake db:migrate

Now, after this i still got a 502 error but at least i'm not stuck with 500 error!

3. Forget to reconfigure after an upgrade

Well, if its not database migration, then every time you did a migration, remember to do a reconfigure!

gitlab-ctl reconfigure

Once i did this. Wait a while, and puff! The screen is back up!

Screen Shot 2015-12-13 at 12.00.47 AM

I'm just grateful everything is ok! Just remember to back up your VM image before doing all these upgrades!

Dell Powerconnect 6224 reset but no internet connection

Things to take note on the dell powerconnect 6224 configuration. Upon reloading with your serial connection, it will prompt you to reset your web interface, once you configure the network, you will be able to access your web management interface. However, your whole switch won't have access to the internet even if you have reset your Dell Powerconnect 6224 switch!

If you try to ping anywhere around the world within the console, you will get a "DNS LOOKUP FAILING" and all your servers won't get any internet connection! You'll need to go to the web interface or in the console, but for my case, i did it on web interface, add the following dns into your router

Screen Shot 2015-05-04 at 2.23.26 AM

and remember to enable http server so that you could access your web management

enable
config 
ip http server

Once you done all these, save your configuration!

copy running-config startup-config

and you are as good as new!

whmcs additional domain fields

Need additional domain fields on your WHMCS software for special domain name? Like the one show below?
Screen Shot 2015-03-13 at 8.56.00 PM
You can actually add them on whmcs path below

whmcs/includes/additionaldomainfields.php

well, i have just did a Malaysia .my ones, if anyone needs it, grab it here.

// .MY
$additionaldomainfields[".com.my"][] = array("Name" => "Registrant Type", "Description" => "Domain can be registered under Malaysian Company /Organisation, If you do not have all the above, you can request a Proxy Service to register on behalf, Fees are optional for Proxy. However if you plan to reserve the domain and no intention of using it, we an register on behalf, and keep inactive , there are no additional charges, but domain remain unuseable until you transfer to another party/activate proxy services.","LangVar" => "mytldregtype", "Type" => "dropdown", "Options" => "Malaysian Company or Organisation,I do not have the required. Please quote me Proxy Service,Reserve the domain but inactive. Will transfer out in the future", "Default" => "Malaysian Company or Organisation",);
$additionaldomainfields[".com.my"][] = array("Name" => "Company Name", "DisplayName" => "Company Name", "Description" => "Please Provide a Malaysian Company Name", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);
$additionaldomainfields[".com.my"][] = array("Name" => "Company Registration number", "DisplayName" => "Company Registration number", "Description" => "Provide only SSM or any Orgational Reference / Cert such as Barcouncil Registation / Architect Firm / Local Org or etc", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Defa
ult" => "", "Required" => true,);

$additionaldomainfields[".my"][] = array("Name" => "Registrant Type", "Description" => "Domain can be registered under Malaysian Company or Malaysian IC, Or Foreigner with Proof Living in Malaysia such as Visa/Immigresen Document, If you do not have all the above, you can request a Proxy Service to register on behalf, Fees are optional for Proxy. However if you plan to reserve the domain and no intention of using it, we an register on behalf, and keep inactive , there are no additional charges, but domain remain unuseable until you transfer to another party/activate proxy services.","LangVar" => "mytldregtype", "Type" => "dropdown", "Options" => "Malaysian Company or Organisation,Malaysian Identity Card,Foreigner Living in Malaysia,I do not have the required. Please quote me Proxy Service,Reserve the domain but inactive. Will transfer out in the future", "Default" => "Malaysian Identity Card",);
$additionaldomainfields[".my"][] = array("Name" => "Name or Company Name", "DisplayName" => "Name or Company Name", "Description" => "Please Provide a Malaysian Company Name", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);
$additionaldomainfields[".my"][] = array("Name" => "IC / Passport / Company Registration number", "DisplayName" => "IC / Passport / Company Registration number", "Description" => "Provide only Reg No if under Malaysian Company , or IC / Passport Number under private registration", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);
$additionaldomainfields["edu.my"][] = array("Name" => "Registrant Type", "Description" => "Domain can be registered under Malaysian Malaysia Educational Institution Holders only, If you are not, you should not proceed.","LangVar" => "mytldregtype", "Type" => "dropdown", "Options" => "Malaysia Educational Institution", "Default" => "Malaysia Educational Institution",);
$additionaldomainfields["edu.my"][] = array("Name" => "Name of the Educational Institution", "DisplayName" => "Name of the Educational Institution", "Description" => "Fu
ll Name of your Educational Institution", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);$additionaldomainfields["edu.my"][] = array("Name" => "SSM or Other Registration Number", "DisplayName" => "SSM or Other Registration Number", "Description" => "Registration number together with supporting document to apply this document are required. Please email using our ticket system payment has been made successfully", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);

$additionaldomainfields["name.my"][] = array("Name" => "Registrant Type", "Description" => "Domain can be registered under Malaysian Identity Card Holders only, You cannot apply if you are not a Malaysian","LangVar" => "mytldregtype", "Type" => "dropdown", "Options" => "Malaysian Identity Card", "Default" => "Malaysian Identity Card",);
$additionaldomainfields["name.my"][] = array("Name" => "Full Name", "DisplayName" => "Full Name", "Description" => "Full Name on IC number", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);
$additionaldomainfields["name.my"][] = array("Name" => "Malaysia Identity Card Number", "DisplayName" => "Malaysia Identity Card Number", "Description" => "A valid Malaysia Identity Card is required.", "LangVar" => "mytldrcbid", "Type" => "text", "Size" => "30", "Default" => "", "Required" => true,);


$additionaldomainfields[".net.my"] = $additionaldomainfields[".com.my"];
$additionaldomainfields[".org.my"] = $additionaldomainfields[".com.my"];
// $additionaldomainfields[".gov.my"] = $additionaldomainfields[".my"];

It does save you some time, for sure.

Setup Linux MySQL, PHP, nginx, php-fpm, varnish and APC on Centos (LEMP)

LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx, MySQL, and PHP. In short, people who are looking into nginx is really looking for better web server as compare to apache which nginx perform better in many aspect although apache is still the most usage web server around due to its stability!

Requirement

Before we can start with all the installation for our fresh installed Centos server, we will need to download and install 2 extra repositories to our server. Below is a 32 bits Centos 6 installation

sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

64 bits Centos 6 installation you will need to fire the below command,

sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

We will need to do this in order to get nginx and php-fpm off our centos machine since its not available on our fresh Centos installation.

Install Nginx on Centos

Firstly we will need to install our Nginx web server by firing the below command,

sudo yum install nginx -y

now we will need to update our nginx configuration at /etc/nginx/nginx.conf to the following

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              nginx;
worker_processes  4;
worker_rlimit_nofile 8192;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
        # Only for Linux 2.6 or >
        use epoll;
        # Accept as many connections as possible
        multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
        tcp_nodelay                     on;

    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
        client_body_timeout             30;
        client_header_timeout           30;
        send_timeout                    30;
        client_max_body_size            8M;
        reset_timedout_connection       on;

        # Gzip module configuration
        gzip                    on;
        gzip_disable            "MSIE [1-6].(?!.*SV1)";
        gzip_vary               on;
        gzip_comp_level         3;
        gzip_proxied            any;
        gzip_buffers            16 8k;

    #gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

}

The Above configuration allows nginx web server configuration to be setup properly with gzip enabled. Next we need to edit /etc/nginx/conf.d/default.conf to the following

server {
        listen       80 default_server;
        server_name  server.hungred.com;
        root /usr/share/nginx/html; 
        error_log /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;

        location / {
                root   /usr/share/nginx/html;
                index  index.html index.htm index.php;
        }

        error_page  404              /404.html;
        location = /404.html {
                root   /usr/share/nginx/html;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /usr/share/nginx/html;
        }

        location ~ \.php$ {
                root           /usr/share/nginx/html;
                try_files $uri =404;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_intercept_errors on;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

}

The above setup our default directory for this server so if you fire up your server hostname, you will reach the directory as written on the default conf file. Now, we will need to test our nginx configuration before starting it,

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once this is done, our nginx web server has been setup and we will need to make sure that it will starts itself every times when it restart by setting up on chkconfig

sudo chkconfig --levels 235 nginx on

All done, we'll need to start up nginx

service nginx start

and we are good to go, you should be able to test whether this is working by firing up your ip address. And you can know your ip address by doing this

ifconfig eth0 | grep inet | awk '{ print $2 }'

But you should know 😉

Install PHP on Centos

Next, we will need to install php by firing

sudo yum install php-cli php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

Now edit php.ini file and find "cgi.fix_pathinfo" section then set it to 0 and save it.

Install APC on Centos

Next, we will need to install php-apc by firing

sudo yum install php-apc -y

We will need to update our php.ini file so that apc.so is enabled and is working fine. Edit the file at /etc/php.d/apc.ini and make sure that apc.so is enabled

; Enable apc extension module
extension = apc.so

Now we will need to install php-fpm

Install PHP-FPM on Centos

In order for php-fpm to work, we'll need to install it by running

yum install php-fpm -y

Once php-fpm is installed, we will need to configure it. Open up the file at /etc/php-fpm.d/www.conf and look for the following lines

; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

and change it to

; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

we are doing this because we are running nginx instead of apache. Next we will need to setup chkconfig so that it will starts itself when our server restart

sudo chkconfig --levels 235 php-fpm on

Lastly we need to start php-fpm

service php-fpm restart

And we are good to go!

Install MySQL on Centos

We will begin installing MySQL server into our machine,

sudo yum install mysql mysql-server 

Once the installation is completed, we will need to secure it!

sudo /usr/bin/mysql_secure_installation

It will prompt and ask you for your current root password.

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

At the end, MySQL will reload and implement the changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

we need to setup chkconfig so that mysql will start itself upon reboot,

sudo chkconfig --levels 235 mysqld on

Next we start our database!

service mysqld restart

And we are good here.

Install Varnish on Centos

First off, install varnish!

sudo yum install varnish

Then we will configure varnish to act as the middle man between our visitors and our web server! Open up varnish configure file at /etc/sysconfig/varnish and change the port from

# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=8080

to

# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80

this is to ensure that our varnish will be listening to port 80 which is what our nginx server is currently doing! So we will need to update our nginx configuration so that it will listen to other port. This is my blog nginx virtual host which is listening to port 8080 instead of 80, you'll need to change that from the original 80 to 8080 so that it won't crash with varnish!

server {
    listen       8080;
    server_name  hungred.com www.hungred.com;
    root   /var/www;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    }

}

P.S: i have alter a bit on the configuration to avoid unnecessary headache lol. Once this is done you will still have to configure varnish! Open up the file at /etc/varnish/default.vcl and make sure that your server ip and port is correctly updated.

backend default {
.host = "127.0.0.1";
.port = "80";
}

to

backend default {
  .host = "12.23.18.1";
  .port = "8080";
}

The above means that all request from varnish that it doesn't have cache on will redirect to port 8080 which is where our nginx server lies! Ok, so same stuff here, we will need to make sure varnish starts itself or else all our web sites on this web server will die if it got rebooted!

chkconfig varnish on

Finally, reboot both nginx and varnish in this sequence!

service nginx restart

this will change nginx listening port from 80 to 8080 and varnish from 8080 to 80! And we are done!

Summary

Ok to be honest, this tutorial was setup using the same exact same steps as how i've setup for this website and also prove whatever is written here works pretty well! So try it out and let me know if you faced any issue with your installation!

Facebook Graph api delete group or page post

Here is something interesting that i recently found out when i was working on my social media site, toolbox.my. I was trying to delete post that was sent out from this app but there wasn't any documentation written on it and after some investigation and testing i finally got it right!

Deleting User Post

Before i go into how group post is being deleted, if we look at facebook graph api, it stated under "Deleting" that

An app can delete a post if it published it

Which means that a post can only delete by the person who creates it. Therefore, if this is a post created by an app, only the app can deleted it although the user created it using the app. On the other hand, if the user create a post in app and tries to use the app to delete, it won't work.

Now, if we look at the php sample code from the graph api, its pretty straight forward.

/* make the API call */
$request = new FacebookRequest(
  $session,
  'DELETE',
  '/{post-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */

but but but, if it said there isn't such method (which usually will), this is most likely because you will also need to indicated who's post this is by doing this,

/* make the API call */
$request = new FacebookRequest(
  $session,
  'DELETE',
  '/{user-id}_{post-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */

and it should delete it properly

Deleting Group or Page Post

If you did read what i wrote on deleting user post, you might have guessed how this could apply to all other post created from other section. All you really need to do to delete group post is to do this

/* make the API call */
$request = new FacebookRequest(
  $session,
  'DELETE',
  '/{group-id}_{post-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */

while page post you would do this

/* make the API call */
$request = new FacebookRequest(
  $session,
  'DELETE',
  '/{page-id}_{post-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */

Basically its the same and the trick here is to tell the delete restful api that you are going to delete a particular object post and these object can be either user, page or groups.

Deleting Post Using Facebook api

In Summary, i would say if you are deleting using facebook api, make sure that the post that you are deleting is created by the app itself and not by the user and since you are using facebook graph api, it is most likely you are using an app to delete a post that was created by your facebook api. Just take note that you can only delete anything created by your app and you won't be able to delete any post by the user although the user is logged into your app (but the app is deleting the user post so it wont work).