Configurable config files

Discuss issues related to PS3 Media Server development (only for programmers)

Configurable config files

Postby freman » Tue Apr 20, 2010 8:32 am

Hi there,

I run 2 PS3 Media Server instances on one box (one for each network interface, one has more than the other, etc) and I wanted to set them up to boot with an init script.

Not having a configurable config location makes it a little more difficult to do dynamically, so I patched it.

Below is a really simple patch that checks the environment for a config file before using the default

Code: Select all
diff -ur ps3mediaserver/PMS.sh ps3mediaserver.new/PMS.sh
--- ps3mediaserver/PMS.sh       2010-04-20 16:22:13.000000000 +1000
+++ ps3mediaserver.new/PMS.sh   2010-04-20 16:31:18.000000000 +1000
@@ -2,6 +2,9 @@

 DIRNAME=`dirname $0`

+# Optional path to configuration file
+# PMSCONF="/path/to/pms.conf"
+# WEBCONF="/path/to/web.conf"

 # OS specific support (must be 'true' or 'false').
 cygwin=false;
diff -ur ps3mediaserver/net/pms/PMS.java ps3mediaserver.new/net/pms/PMS.java
--- ps3mediaserver/net/pms/PMS.java     2010-04-20 16:19:43.000000000 +1000
+++ ps3mediaserver.new/net/pms/PMS.java 2010-04-20 16:11:03.000000000 +1000
@@ -480,7 +480,7 @@
                getRootFolder(renderer).browse(files);


-               File webConf = new File("WEB.conf"); //$NON-NLS-1$
+               File webConf = new File(System.getenv("WEBCONF") == null ? "WEB.conf" : System.getenv("WEBCONF")); //$NON-NLS-1$
                if (webConf.exists()) {
                        try {
                                LineNumberReader br = new LineNumberReader(new InputStreamReader(new FileInputStream(webConf), "UTF-8")); //$NON-NLS-1$
diff -ur ps3mediaserver/net/pms/configuration/PmsConfiguration.java ps3mediaserver.new/net/pms/configuration/PmsConfiguration.java
--- ps3mediaserver/net/pms/configuration/PmsConfiguration.java  2010-04-20 16:19:43.000000000 +1000
+++ ps3mediaserver.new/net/pms/configuration/PmsConfiguration.java      2010-04-20 16:04:46.000000000 +1000
@@ -141,7 +141,7 @@

        private static final int MAX_MAX_MEMORY_BUFFER_SIZE = 600;

-       private static final String CONFIGURATION_FILENAME = "PMS.conf";
+       private static final String CONFIGURATION_FILENAME = System.getenv("PMSCONF") == null ? "PMS.conf" : System.getenv("PMSCONF");
        private static final String CONFIGURATION_PATH_MAC = System.getProperty("user.home") + "/Library/Application Support/PS3 Media Server/";
        private static final char LIST_SEPARATOR = ',';
        private static final String KEY_FOLDERS = "folders";
freman
 
Posts: 3
Joined: Tue Apr 20, 2010 8:05 am

Re: Configurable config files

Postby shagrath » Tue Apr 20, 2010 11:10 pm

Thanks for the patch ! I'll merge it
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: Configurable config files

Postby chocolateboy » Sat Apr 30, 2011 9:06 pm

chocolateboy
Project Member
 
Posts: 2580
Joined: Wed Sep 16, 2009 10:05 am

Re: Configurable config files

Postby tomeko » Sat Apr 30, 2011 10:13 pm

Second instance should have different UUID than first one (some renderers use uuid only to recognize servers).
tomeko
Project Member
 
Posts: 154
Joined: Sat Jun 06, 2009 11:02 am

Re: Configurable config files

Postby chocolateboy » Sat Apr 30, 2011 10:14 pm

Patch(es) welcome :-)
chocolateboy
Project Member
 
Posts: 2580
Joined: Wed Sep 16, 2009 10:05 am

Re: Configurable config files

Postby tomeko » Sun May 01, 2011 9:50 am

Something like this (i can't create proper patch file at this moment):
Code: Select all
--- PMS.java   (wersja 566)
+++ PMS.java   (kopia robocza)
 
    public String usn() {
      if (uuid == null) {
         boolean uuidBasedOnMAC = false;
         NetworkInterface ni = null;
         try {
            if (getConfiguration().getServerHostname() != null && getConfiguration().getServerHostname().length() > 0) {
               try {
                  ni = NetworkInterface.getByInetAddress(InetAddress.getByName(getConfiguration().getServerHostname()));
               } catch (Exception e) {
               }
            } else if (get().getServer().getNi() != null) {
               ni = get().getServer().getNi();
            }
            if (ni != null) {

               byte[] addr = PMSUtil.getHardwareAddress(ni); // return null when java.net.preferIPv4Stack=true
               if (addr != null) {
-                  uuid = UUID.nameUUIDFromBytes(addr).toString();
+                  uuid = UUID.nameUUIDFromBytes(ArrayUtils.addAll(addr,getConfiguration().getProfileName().getBytes())).toString();
                  uuidBasedOnMAC = true;
               } else {
                  minimal("Unable to retrieve MAC address for UUID creation: using a random one..."); //$NON-NLS-1$
               }
            }
         } catch (Throwable e) {
            minimal("Switching to random UUID cause there's an error in getting UUID from MAC address: " + e.getMessage()); //$NON-NLS-1$
         }

         if (!uuidBasedOnMAC) {
            if (ni != null && (ni.getDisplayName() != null || ni.getName() != null)) {
-               uuid = UUID.nameUUIDFromBytes((ni.getDisplayName() != null ? ni.getDisplayName() : (ni.getName() != null ? ni.getName() : "dummy")).getBytes()).toString(); //$NON-NLS-1$
+               uuid = UUID.nameUUIDFromBytes((ni.getDisplayName() != null ? ni.getDisplayName() : (ni.getName() != null ? ni.getName() : "dummy") + getConfiguration().getProfileName()).getBytes()).toString(); //$NON-NLS-1$
            } else {
               uuid = UUID.randomUUID().toString();
            }
         }
         minimal("Using the following UUID: " + uuid); //$NON-NLS-1$
      }
      return "uuid:" + uuid; //$NON-NLS-1$ //$NON-NLS-2$
      //return "uuid:1234567890TOTO::";
   }
tomeko
Project Member
 
Posts: 154
Joined: Sat Jun 06, 2009 11:02 am


Return to Developers

Who is online

Users browsing this forum: Bing [Bot] and 2 guests