How to test if a server is a DH server

software development

#1

Hello!

I a nearly finished with my first CGI script, powered by Python! It is a simple script that will display basic information about the server, and the user that is running the script. I’d like it to work on as many environments as possible. However, I’d like the script to be able to “know” if it is on a DH server, so It can use things like the DH API. Is there a way to do this?

Thanks.


#2

Probably the easiest way is to test for the existence of the /dh folder. You’ll still need a DreamHost API key to use the API, though.


#3

From command line, ‘dnsdomainname’ (or ‘hostname -d’) tells you the domain, which is dreamhost.com. Dunno if Python can make this call. Or you can parse for the hostname in /etc/hosts which also has hostname.dreamhost.com on the same line.


#4

Thanks Scott!

Based on your suggestion I came up with the following bit of code:

import commands

#Assume the server is not a DH server
isDHServer=False
isDHPS=False

#Test if it is a shared server
if commands.getoutput("hostname -d") == "dreamhost.com":
     isDHServer=True
else:
    isDHServer=False
    #If it is not a shared server, maybe it is a PS?
    if commands.getoutput("hostname -d") == "dreamhostps.com":
        isDHPS=True
    else:
        isDHPS=False    

#added print lines as proof-of-concept
print "isDHServer: "+str(isDHServer)
print "isDHPS: "+str(isDHPS)

It works well.


#5

That won’t actually work for all DreamHost servers. Most have domains set to either dreamhost.com or dreamhostps.com, but there are a couple of special machines with other domains. Testing for the existence of a /dh directory should be more reliable.


#6

Ok, good to know. is the dreamhostps.com domain at least a a good method of determining if a server is a PS?[hr]
Based on the above, here is my modified, simplified code:

#import needed modules
import os
import commands

#Assume the server is not a DH server
isDHServer=False
isDHPS=False

#Test if it is a DH server
if os.path.exists("/dh"):
    isDHServer=True
    #If it is a DH server, is it a PS?
    if commands.getoutput("hostname -d") == "dreamhostps.com":
        isDHPS=True

#added print lines as proof-of-concept
print "isDHServer: "+str(isDHServer)
print "isDHPS: "+str(isDHPS)

#7

Best way to check for a PS is to test for the presence of both /dh and /proc/self/vinfo. The latter is a bit of an implementation detail, but isn’t expected to change anytime soon.


#8

Ok, third time’s a charm:

[code]
#import needed modules
import os

#Assume the server is not a DH server
isDHServer=False
isDHPS=False

#Test if it is a DH server
if os.path.exists("/dh"):
isDHServer=True
#If it is a DH server, is it a PS?
if os.path.exists("/proc/self/vinfo"):
isDHPS=True

#Print lines as a proof-of-concept
print "isDHServer: "+str(isDHServer)
print "isDHPS: "+str(isDHPS)[/code]

Thanks.