h-mdm / hmdm-server

Mobile Device Management System for Android: web control panel. Manage Android devices, install and update apps, get device info. See website for more features!

Home Page:https://h-mdm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to make changes to HMDM server after installation

MHShetty-AA1-1 opened this issue · comments

I'm trying to make some changes to the HMDM installation that I have done by following the given guide:
https://h-mdm.com/advanced-web-panel-installation/

The installation works fine as expected, however whenever I try to make some changes to the code and rebuild the server using the same primary install script, the changes do not reflect on the server, even after using mvn clean install to always build. (Especially when I do it only for the front-end files under the webapp directory, containing images, html files, etc.)

I tried understanding Tomcat a bit in detail and found out that updating the WAR file and restarting the server ideally should do the work and created a script for rebuilding the server.

#!/bin/bash

# We are assuming the code to have been compiled at the given location here
SERVER_WAR=./server/target/launcher.war

TOMCAT_HOME=$(ls -d /var/lib/tomcat* | tail -n1)
TOMCAT_DEPLOY_PATH="ROOT"

echo "Overwriting old war file to new file..."

# 1
cp $SERVER_WAR $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH.war

if [ $? -ne 0 ]
then
        echo ""
        echo "An unexpected error occurred while overwriting war file."
        exit 1
fi


# 2
chmod 644 $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH.war

if [ $? -ne 0 ]
then
        echo ""
        echo "An unexpected error occurred while changing permissions of war file."
        exit 1
fi

# 3
sudo service tomcat9 restart

if [ $? -ne 0 ]
then
        echo ""
        echo "An unexpected error occurred while restarting war file."
        exit 1
fi

echo "Updating resources files..."

# Copying the resources files directly to the main ROOT directory probably isn't the right way
# of updating resources, since Tomcat somehow overwrites them with the old resources.
#
# However, if it's done after a while since the server starts, it updates (at least for as long as 
# we use it). Restarting the tomcat service overwrites it although.
sudo cp -rT ./server/src/main/webapp /var/lib/tomcat9/webapps/ROOT


if [ $? -ne 0 ]
then
        echo ""
        echo "An unexpected error occurred while copying source files to generated folder..."
        exit 1
fi

echo "Updated."

echo "The changes should soon show up in a while."

However, this doesn't seem to be the right way of doing it, since it has a lot of shortcomings (as mentioned in the comments present in the script)

Could you'll please help us out with some build script (that you'll use or is expected to be used) to directly reload changes or make changes and restart the server to make sure they reflect as they are expected to (even for the front-end files)?

You are right, to apply changes you need to replace the WAR file in /var/lib/tomcat9/webapps and restart Tomcat.

Make sure you have enough permissions to replace the file. If you're running the script as a non-root user, you may get Access Denied error while copying. Consider running this script as root or using

sudo cp $SERVER_WAR $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH.war

Also, make sure the "tomcat" user can read the new WAR file.

Hi @h-mdm,

Thanks a lot for your quick response and help.

Replacing the war file and restarting the tomcat server does not immediately update the webapp related static resources. Is there any way we could automate that too reliably?

Could you'll please share a bash script or the exact commands that you'll execute to reload changes to the server?

Make sure you have enough permissions to replace the file. If you're running the script as a non-root user, you may get Access Denied error while copying. Consider running this script as root or using

The script gets run using sudo, so that most likely might not be the issue

sudo cp $SERVER_WAR $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH.war

Yes like we do copy the new war file using the new code, but how do we properly update the static front-end resources correctly.. In the flow we have now, we update the contents of directory $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH with the latest contents of $source_code_dir/server/src/main/webapp which does help as long as the server isn't restarted/is in the process of being restarted.

Also, make sure the "tomcat" user can read the new WAR file.

Tried doing this too, doesn't really help unfortunately help until I manually update the static resources using the following
command :( (the same manual updating of resources)

sudo cp -rT /home/ubuntu/main/hmdm-server/server/src/main/webapp /var/lib/tomcat9/webapps/ROOT

Could you'll please help us out with this? What would be the recommended way to contribute when hosting the app from a remote server we at the moment have SSH access to? We could try following the way you'll/your contributors work on the HMDM solution too. Would using some GUI based IDE with an RDP connection be recommended to deal with these caveats?

Actually we have been struggling to create an environment to make changes to the MDM since the last 1-2 weeks. We tried re-writing the whole script but have still failed to figure out what's overwriting those Tomcat resource files, and why certain changes get updated under certain circumstances, while not in other scenarios. It would be really of great help, if you'll could specify any minimal environment (which could be an IDE based solution)/CLI flow that's being used somewhere/by you'll, where we could rebuild/update changes as soon as we make them.

Thanks a lot for your time team @h-mdm.

We highly appreciate the availability of your open-source MDM solution (possibly the only one being actively maintained in the market). Please keep up the great work do let us know if you'll need any help with testing anything related to Android 13, or any other help that we could provide as devs. Thanks a lot once again @h-mdm!

There's no special script. We update the code by the following commands (as root):

cp $SERVER_WAR $TOMCAT_HOME/webapps/$TOMCAT_DEPLOY_PATH.war
service tomcat9 restart

There's no need to change files in the /var/lib/tomcat9/webapps/ROOT directory, Tomcat automatically unzips the WAR file.

If you don't see the changes immediately, try clearing the browser cache and reloading the web app.

Headwind MDM web app could be developed and built in Intellij IDEA (a free Community edition is enough).

Not really sure but I think there are some issues with the way the caching mechanism of Tomcat server itself. I have completely disabled caching for the time being and the site is a bit slow to load, but we always get the latest version of the site now.

We added this under the main Context tag as the first element, to the file that is generated using the context template under the main install directory, used in the install script which helped us disable caching.

<Resources cachingAllowed="false" />

The mention about the client-side caching part, kind of helped us figure out the possible server-side caching issue, which was the case, luckily and was solved.

Thanks a lot for the valuable time and help @h-mdm!