This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch debian9-systemvmtemplate
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/debian9-systemvmtemplate by 
this push:
     new 0773fd0  apache2 and secondary storage improvement, use systemctl and 
favour www-data ownership on folders
0773fd0 is described below

commit 0773fd06ecda55879379bf7582979234b0d4b4ea
Author: Rohit Yadav <[email protected]>
AuthorDate: Thu Dec 21 17:32:30 2017 +0530

    apache2 and secondary storage improvement, use systemctl and favour 
www-data ownership on folders
    
    Signed-off-by: Rohit Yadav <[email protected]>
---
 .../resource/NfsSecondaryStorageResource.java      | 10 ++--
 .../storage/template/DownloadManagerImpl.java      | 28 +++++-----
 .../storage/template/UploadManagerImpl.java        | 60 +++++-----------------
 systemvm/debian/opt/cloud/bin/setup/common.sh      |  5 +-
 4 files changed, 39 insertions(+), 64 deletions(-)

diff --git 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 54c6b99..305f3a4 100644
--- 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -235,8 +235,7 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
             String nfsVersionParam = (String)params.get("nfsVersion");
             try {
                 nfsVersion = Integer.valueOf(nfsVersionParam);
-            }
-            catch (NumberFormatException e){
+            } catch (NumberFormatException e){
                 s_logger.error("Couldn't cast " + nfsVersionParam + " to 
integer");
                 return null;
             }
@@ -2269,9 +2268,10 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
         if (!_inSystemVM) {
             return;
         }
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -f /etc/init.d/ssh ]; then service ssh restart; else 
service sshd restart; fi ");
+        //Check whether the Apache server is running
+        Script command = new Script("/bin/systemctl", s_logger);
+        command.add("restart");
+        command.add("ssh");
         String result = command.execute();
         if (result != null) {
             s_logger.warn("Error in starting sshd service err=" + result);
diff --git 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
index 833ef09..112c8b3 100644
--- 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
+++ 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
@@ -1070,10 +1070,10 @@ public class DownloadManagerImpl extends ManagerBase 
implements DownloadManager
     }
 
     private void startAdditionalServices() {
-
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 stop; else 
service httpd stop; fi ");
+        //Check whether the Apache server is running
+        Script command = new Script("/bin/systemctl", s_logger);
+        command.add("stop");
+        command.add("apache2");
         String result = command.execute();
         if (result != null) {
             s_logger.warn("Error in stopping httpd service err=" + result);
@@ -1088,21 +1088,25 @@ public class DownloadManagerImpl extends ManagerBase 
implements DownloadManager
 
         result = command.execute();
         if (result != null) {
-            s_logger.warn("Error in opening up httpd port err=" + result);
+            s_logger.warn("Error in opening up apache2 port err=" + result);
             return;
         }
 
-        command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else 
service httpd start; fi ");
+        command = new Script("/bin/systemctl", s_logger);
+        command.add("start");
+        command.add("apache2");
         result = command.execute();
         if (result != null) {
-            s_logger.warn("Error in starting httpd service err=" + result);
+            s_logger.warn("Error in starting apache2 service err=" + result);
             return;
         }
-        command = new Script("mkdir", s_logger);
-        command.add("-p");
-        command.add("/var/www/html/copy/template");
+
+        command = new Script("/bin/su", s_logger);
+        command.add("-s");
+        command.add("/bin/bash");
+        command.add("-c");
+        command.add("mkdir -p /var/www/html/copy/template");
+        command.add("www-data");
         result = command.execute();
         if (result != null) {
             s_logger.warn("Error in creating directory =" + result);
diff --git 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
index a8ed9a8..29eb4b1 100644
--- 
a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
+++ 
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadManagerImpl.java
@@ -266,9 +266,12 @@ public class UploadManagerImpl extends ManagerBase 
implements UploadManager {
         }
         // Create the directory structure so that its visible under apache 
server root
         String extractDir = "/var/www/html/userdata/";
-        Script command = new Script("mkdir", s_logger);
-        command.add("-p");
-        command.add(extractDir);
+        Script command = new Script("/bin/su", s_logger);
+        command.add("-s");
+        command.add("/bin/bash");
+        command.add("-c");
+        command.add("mkdir -p " + extractDir);
+        command.add("www-data");
         String result = command.execute();
         if (result != null) {
             String errorString = "Error in creating directory =" + result;
@@ -278,15 +281,6 @@ public class UploadManagerImpl extends ManagerBase 
implements UploadManager {
 
         // Create a random file under the directory for security reasons.
         String uuid = cmd.getExtractLinkUUID();
-        command = new Script("touch", s_logger);
-        command.add(extractDir + uuid);
-        result = command.execute();
-        if (result != null) {
-            String errorString = "Error in creating file " + uuid + " ,error: 
" + result;
-            s_logger.warn(errorString);
-            return new CreateEntityDownloadURLAnswer(errorString, 
CreateEntityDownloadURLAnswer.RESULT_FAILURE);
-        }
-
         // Create a symbolic link from the actual directory to the template 
location. The entity would be directly visible under 
/var/www/html/userdata/cmd.getInstallPath();
         command = new Script("/bin/bash", s_logger);
         command.add("-c");
@@ -501,46 +495,20 @@ public class UploadManagerImpl extends ManagerBase 
implements UploadManager {
     }
 
     private boolean checkAndStartApache() {
-
         //Check whether the Apache server is running
-        Script command = new Script("/bin/bash", s_logger);
-        command.add("-c");
-        command.add("if [ -d /etc/apache2 ] ; then service apache2 status | 
grep pid; else service httpd status | grep pid; fi ");
+        Script command = new Script("/bin/systemctl", s_logger);
+        command.add("is-active");
+        command.add("apache2");
         String result = command.execute();
 
         //Apache Server is not running. Try to start it.
-        if (result != null) {
-
-            /*s_logger.warn("Apache server not running, trying to start it");
-            String port = 
Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
-            String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
-
-            command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            command.add("iptables -D INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + port + " -j DROP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + port + " -j HTTP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + "443" + " -j DROP;" +
-                        "iptables -D INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + "443" + " -j HTTP;" +
-                        "iptables -F HTTP;" +
-                        "iptables -X HTTP;" +
-                        "iptables -N HTTP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + port + " -j DROP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + "443" + " -j DROP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + port + " -j HTTP;" +
-                        "iptables -I INPUT -i " + intf + " -p tcp -m state 
--state NEW -m tcp --dport " + "443" + " -j HTTP;");
-
-            result = command.execute();
-            if (result != null) {
-                s_logger.warn("Error in opening up httpd port err=" + result );
-                return false;
-            }*/
-
-            command = new Script("/bin/bash", s_logger);
-            command.add("-c");
-            command.add("if [ -d /etc/apache2 ] ; then service apache2 start; 
else service httpd start; fi ");
+        if (result != null && !result.equals("active")) {
+            command = new Script("/bin/systemctl", s_logger);
+            command.add("start");
+            command.add("apache2");
             result = command.execute();
             if (result != null) {
-                s_logger.warn("Error in starting httpd service err=" + result);
+                s_logger.warn("Error in starting apache2 service err=" + 
result);
                 return false;
             }
         }
diff --git a/systemvm/debian/opt/cloud/bin/setup/common.sh 
b/systemvm/debian/opt/cloud/bin/setup/common.sh
index 0622e2e..d9258f6 100755
--- a/systemvm/debian/opt/cloud/bin/setup/common.sh
+++ b/systemvm/debian/opt/cloud/bin/setup/common.sh
@@ -495,7 +495,8 @@ clean_ipalias_config() {
 
   # New
   rm -f /etc/apache2/sites-enabled/vhost-*.conf
-  rm -f /etc/apache2/sites-enabled/000-default
+  rm -f /etc/apache2/sites-enabled/000-default.conf
+  rm -f /etc/apache2/sites-enabled/default-ssl.conf
 
   rm -rf /etc/failure_config
 }
@@ -513,6 +514,8 @@ setup_apache2_common() {
 
 setup_apache2() {
   log_it "Setting up apache web server"
+  mkdir -p /var/www
+  chown www-data:www-data -R /var/www
   clean_ipalias_config
   setup_apache2_common
   local ip=$1

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to