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

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

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:


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:


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.


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

grep /var/cpanel/users/*

grep -R /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


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

# 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.


date +"%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)
%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
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
And if you’re a bash lover:
$ for i in {1..3};do curl -s -w "%{time_total}\n" -o /dev/null; done
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:
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
time_total: %{time_total}\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
            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
  • -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
  • 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
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,
Benchmarking (be patient).....done
Server Software: gws
Server Hostname:
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

Posting JSON data

curl --request POST --data "{ \"ip\": \"\", \"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\" }" --header "Content-Type: application/json"

Posting JSON data from a file

curl --request POST --data @filename --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

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 :
  • (Ports: 53, 110)
  • (Ports: 53, 110, DNSSEC)
  • (Ports: 53, 110,DNSSEC) 
  • (Ports: 53, 110, HTTPS-DNS, DNSSEC)
  • (Ports: 53, 110, DNSSEC)
Level 3 Communications :
  • (Queensland, Australia)
  • (Queensland, Australia)
  • (Victoria, Australia)
  • (Germany)
  • (New Zealand)
  • (United Kingdom)
  • (Colorado, United States)
  • 2001:470:8388:10:0:100:53:20 (Colorado, United States)
  • (New Jersey, United States)
  • (New Jersey, United States)
  • (New York, United States)
  • (Indiana, United States)
  • 2001:470:1f10:c6::2 (Indiana, United States)
  • (Texas, United States)
  • 2001:470:1f0f:48e::2 new (Texas, United States)
  • (Texas, United States)
  • 2a00:1508:0:4::9

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 :
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