Yegor's blog

Small blog about system administration.

cPanel - Domain already exists error while adding a subdomain or addon domain

A very common error  when adding an addon or parked domain via cpanel. Unfortunately, the error they see is usually very generic and doesn’t provide any information such as “can not create domain”. This is usually due to the domain name existing anywhere in the cPanel configuration and checking these locations/steps out should help you find the domain that is lurking somewhere and causing the issues.

Reason 1: There is an existing zone file on the server.

1) You can use the following command to check whether zone exists or not,


# dig @server_ip domain.com

If there is a zone file exists, this will show the A record of the domain.com.

2) If there is a zone file that exists, log into the server that the zone file is pointing to and make sure the domain doesn’t exist:

/scripts/whoowns domain.com

If it does, you would need to remove this prior to adding their new addon domain. If it does not, continue on

3) Remove the zone file from the server by running the following command:

/scripts/killdns domain.com

This will remove the DNS zone and will help you add the addon or parked domain again.

Reason 2: There are old traces of the domain on the server

1) Log into the server where the customer is seeing problems adding the domain and confirm that the domain does not exist on the server.

/scripts/whoowns domain.com

2) Check Cpanel files for traces of the problem domain name

grep domain.com /var/cpanel/users/*

grep -R domain.com /var/cpanel/userdata/*

3) Edit any files that are found and remove the traces of the domain name the customer is trying to add. You also may need to remove the entire file for the domain in the /var/cpanel/userdata/USERNAME/ directory.

 4) Rebuild the user domains database

/scripts/updateuserdomains

5) Rebuild the Apache configuration and make sure apache is running with all traces of the bad domain removed.

/scripts/rebuildhttpdconf 
# service httpd restart

This should have all traces that were left behind from when this domain name was removed in the past and then will no longer cause a conflict when the customer tries to add the domain again.

No comments :

Post a Comment

HOWTO: Format date output under FreeBSD

How do I format date to display on screen on for my shell scripts as per my requirements on Linux or *BSD operating systems?

You need to use the standard date command to format date or time. You can use the same command with the shell script.

Syntax

date +"%FORMAT"
date +"%FORMAT%FORMAT"
date +"%FORMAT-%FORMAT"
Open a terminal and type the following date command:
date -j +"%Y-%m-%d %H:%M:%S"
Sample output:
2014-08-18 16:57:59

A complete list of FORMAT control characters supported by the date command

FORMAT controls the output. It can be the combination of any one of the following:
%FORMAT StringDescription
%%a literal %
%alocale's abbreviated weekday name (e.g., Sun)
%Alocale's full weekday name (e.g., Sunday)
%blocale's abbreviated month name (e.g., Jan)
%Blocale's full month name (e.g., January)
%clocale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%Ccentury; like %Y, except omit last two digits (e.g., 21)
%dday of month (e.g, 01)
%Ddate; same as %m/%d/%y
%eday of month, space padded; same as %_d
%Ffull date; same as %Y-%m-%d
%glast two digits of year of ISO week number (see %G)
%Gyear of ISO week number (see %V); normally useful only with %V
%hsame as %b
%Hhour (00..23)
%Ihour (01..12)
%jday of year (001..366)
%khour ( 0..23)
%lhour ( 1..12)
%mmonth (01..12)
%Mminute (00..59)
%na newline
%Nnanoseconds (000000000..999999999)
%plocale's equivalent of either AM or PM; blank if not known
%Plike %p, but lower case
%rlocale's 12-hour clock time (e.g., 11:11:04 PM)
%R24-hour hour and minute; same as %H:%M
%sseconds since 1970-01-01 00:00:00 UTC
%Ssecond (00..60)
%ta tab
%Ttime; same as %H:%M:%S
%uday of week (1..7); 1 is Monday
%Uweek number of year, with Sunday as first day of week (00..53)
%VISO week number, with Monday as first day of week (01..53)
%wday of week (0..6); 0 is Sunday
%Wweek number of year, with Monday as first day of week (00..53)
%xlocale's date representation (e.g., 12/31/99)
%Xlocale's time representation (e.g., 23:13:48)
%ylast two digits of year (00..99)
%Yyear
%z+hhmm numeric timezone (e.g., -0400)
%:z+hh:mm numeric timezone (e.g., -04:00)
%::z+hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::znumeric time zone with : to necessary precision (e.g., -04, +05:30)
%Zalphabetic time zone abbreviation (e.g., EDT)


No comments :

Post a Comment

Timing HTTP Requests with cURL

Sometimes you just need to quickly benchmark how fast a page can be loaded (or fetched to be more precise). For these cases, cURL is a great option for timing HTTP requests.
$ curl -s -w "%{time_total}\n" -o /dev/null http://www.google.com/
0.095
Want a few more datapoints?? Thanks to ZSH, it’s easy to just loop around it:
$ for i in {1..3}; curl -s -w "%{time_total}\n" -o /dev/null http://www.google.com/
0.507
0.077
0.077
And if you’re a bash lover:
$ for i in {1..3};do curl -s -w "%{time_total}\n" -o /dev/null http://www.google.com/; done
1.079
0.124
0.106
Default behavior on cURL is GET, but you can do POST, DELETE, PUT and more complex requests. If you’re not familiar with cURL, best place to start is the manpage.
Besides “time_total”, curl also provides other timing, like “time_namelookup”, “time_connect”, etc. Checking a post by Joseph, I remembered that curl supports formatted output. This way we can create a “template” for our HTTP timing test:
12345678910
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
view rawcurl-format hosted with ❤ by GitHub
Assuming the format file is named “curl-format”, we can execute a request:
$ curl -w "@curl-format" -o /dev/null -s http://www.google.com/
            time_namelookup:  0.416
               time_connect:  0.435
            time_appconnect:  0.000
           time_pretransfer:  0.435
              time_redirect:  0.000
         time_starttransfer:  0.488
                            ----------
                 time_total:  0.491
Where:
  • -w “@curl-format” tells cURL to use our format file
  • -o /dev/null redirects the output of the request to /dev/null
  • -s tells cURL not to show a progress bar
  • http://www.google.com/ is the URL we are requesting
The timings are DNS lookup, TCP connect, pre-transfer negotiations, start to end of transfer, redirects (in this case there were none), time to first byte, and total time (last byte), respectively.
Looking for something a bit more “complete”? You can always try Apache Benchmark:


$ ab -n 3 http://www.google.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.google.com (be patient).....done
Server Software: gws
Server Hostname: www.google.com
Server Port: 80
Document Path: /
Document Length: 10928 bytes
Concurrency Level: 1
Time taken for tests: 0.231 seconds
Complete requests: 3
Failed requests: 2
(Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors: 0
Total transferred: 35279 bytes
HTML transferred: 32984 bytes
Requests per second: 12.99 [#/sec] (mean)
Time per request: 76.999 [ms] (mean)
Time per request: 76.999 [ms] (mean, across all concurrent requests)
Transfer rate: 149.15 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 19 21 1.8 22 22
Processing: 50 56 5.3 59 61
Waiting: 46 51 4.0 53 53
Total: 73 77 5.0 79 82
Percentage of the requests served within a certain time (ms)
50% 76
66% 76
75% 82
80% 82
90% 82
95% 82
98% 82
99% 82
100% 82 (longest request)

No comments :

Post a Comment

Testing a JSON API with curl

I’ve been working a lot on JSON APIs during the past few years, and even more intensively lately. If testing GET requests is straightforward, for POST requests I often had to look at Curl documentation again for exact options names and parameter syntax for sending the desired HTTP headers
So I decided to post some quick notes on doing unauthenticated POST requests, in order to have a quickly accessible reference.
Here is a list of some relevant Curl options :
-d, --data DATA     HTTP POST data (H)
-X, --request COMMAND  Specify request command to use
-H, --header LINE   Custom header to pass to server (H)

Doing an empty POST request

curl --request POST http://127.0.0.1:8080/api/store

Posting JSON data

curl --request POST --data "{ \"ip\": \"46.19.37.108\", \"country_code\": \"NL\", \"country_code3\": \"NLD\", \"country\": \"Netherlands\", \"continent_code\": \"EU\", \"latitude\": 52.5, \"longitude\": 5.75, \"dma_code\": \"0\", \"area_code\": \"0\", \"asn\": \"AS196752\", \"isp\": \"Tilaa V.O.F.\", \"timezone\":\"Europe/Amsterdam\" }" http://127.0.0.1:8080/api/store --header "Content-Type: application/json"

Posting JSON data from a file

curl --request POST --data @filename http://127.0.0.1:8080/api/store --header "Content-Type: application/json"
This is particularly handy when working with large JSON objects.
Lastly, for a fully client-side JSON validator and formatter, check JSON.fr.

No comments :

Post a Comment

Free Public DNS Servers List

Here is a list of public DNS servers which are free for everyone to use. There are several reasons why you would want to use alternative DNS servers, such as speeding up your browsing experience and improving your security, but the most obvious one is as a backup solution when your ISP servers are down.
And because you’re most likely going to need these addresses when you can’t browse this page, you can download the following list compiled in a handy text file : http://www.yegorgavrilov.com/dns.txt
  • 8.8.8.8
  • 8.8.4.4
  • 87.118.100.175 (Ports: 53, 110)
  • 94.75.228.29 (Ports: 53, 110, DNSSEC)
  • 87.118.104.203 (Ports: 53, 110,DNSSEC) 
  • 62.141.58.13 (Ports: 53, 110, HTTPS-DNS, DNSSEC)
  • 87.118.109.2 (Ports: 53, 110, DNSSEC)
Level 3 Communications :
  • 4.2.2.1
  • 4.2.2.2
  • 4.2.2.3
  • 4.2.2.4
  • 4.2.2.5
  • 4.2.2.6
  • 58.6.115.42 (Queensland, Australia)
  • 202.83.95.227 (Queensland, Australia)
  • 119.31.230.42 (Victoria, Australia)
  • 217.79.186.148 (Germany)
  • 27.110.120.30 (New Zealand)
  • 89.16.173.11 (United Kingdom)
  • 216.87.84.211 (Colorado, United States)
  • 2001:470:8388:10:0:100:53:20 (Colorado, United States)
  • 69.164.208.50 (New Jersey, United States)
  • 69.164.211.225 (New Jersey, United States)
  • 64.0.55.201 (New York, United States)
  • 66.244.95.20 (Indiana, United States)
  • 2001:470:1f10:c6::2 (Indiana, United States)
  • 72.14.189.120 (Texas, United States)
  • 2001:470:1f0f:48e::2 new (Texas, United States)
  • 69.164.196.21 (Texas, United States)
  • 109.69.8.51
  • 2a00:1508:0:4::9
  • 205.210.42.205
  • 64.68.200.200
  • 8.26.56.26
  • 8.20.247.20
  • 156.154.70.1
  • 156.154.71.1
  • 208.67.222.222
  • 208.67.220.220

No comments :

Post a Comment

Log rotation directly within Nginx configuration file

Ever since I discovered PostgreSQL allowed to embed variables in log_filename allowing to split logs without using logrotate or cronolog, I’ve been wanting to do the same with Nginx.

As it turns out, it’s not only possible but also pretty easy to achieve, since Nginx introduced the possibility to use variables in access_log directives (added in 0.7.4), and the $time_iso8601 variable providing time in ISO 8601 format (added in 0.9.6).
Here is an example showing $time_iso8601 format :
2014-05-04T18:12:02+02:00
All there is to do is use an “if” block to split required data using a regular expression and set time variables.
For splitting logs by day, one would use the following snippet :
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
    set $year $1;
    set $month $2;
    set $day $3;
}

access_log /var/log/nginx/$year-$month-$day-access.log;
Alternatively, we can also use the Perl compatible syntax for named regular expression capture : 
if ($time_iso8601 ~ "^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})") {}

access_log /var/log/nginx/$year-$month-$day-access.log;
To also create variables for hours, minutes and seconds, we can use the following snippet :
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})")
{
    set $year $1;
    set $month $2;
    set $day $3;
    set $hour $4;
    set $minutes $5;
    set $seconds $6;
}
Lastly, and I cannot stress it enough, please make sure Nginx has proper permissions to access and write in the log directory.
This method is currently used in production on a busy Nginx server and has been running flawlessly for almost a month now. The only drawback is that buffered writes do not work when the access_log file path contain variables, so it isn’t possible to gzip logs on the fly.

No comments :

Post a Comment