Problems launching OpenMRS server as a service

Hi everybody! I’m working on a project using OpenMRS and a client-server android app. I’m pretty new using OpenMRS, so I’ll try to do my best to explain my issue.

I’m trying to launch automatically the server (Standalone-2.7.0) as a service once the computer is already on and the network is working. I’m using Ubuntu 16.04.1

This is the simple shell script I’m running:

#!/bin/bash

cd /home/pere/Documents/referenceapplication-standalone-2.7.0/ 
java -jar openmrs-standalone.jar`

And this is the .service file:

[Unit]
Description=Launch OpenMRS server service
After=network.service
StartLimitIntervalSec=0

[Service]
Type=simple
RestartSec=1
User=pere
ExecStart=/usr/local/bin/launchServer.sh

[Install]
WantedBy=multi-user.target

If I check the status of the service once the computer is on I got the following error:

● launchOpenmrs.service - Launch OpenMRS server service
   Loaded: loaded (/lib/systemd/system/launchOpenmrs.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since ven. 2018-09-07 15:07:40 CEST; 12min ago
  Process: 771 ExecStart=/usr/local/bin/launchServer.sh (code=exited, status=0/SUCCESS)
 Main PID: 771 (code=exited, status=0/SUCCESS)

sept. 07 15:07:40 nicotris launchServer.sh[771]:         at java.awt.Window.<init>(Window.java:536)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at java.awt.Frame.<init>(Frame.java:420)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at java.awt.Frame.<init>(Frame.java:385)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at javax.swing.JFrame.<init>(JFrame.java:189)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at org.openmrs.standalone.MainFrame.<init>(MainFrame.java:68)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at org.openmrs.standalone.ApplicationController.init(ApplicationController.java:227)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at org.openmrs.standalone.ApplicationController.<init>(ApplicationController.java:55)
sept. 07 15:07:40 nicotris launchServer.sh[771]:         at org.openmrs.standalone.ApplicationController.main(ApplicationController.java:126)
sept. 07 15:07:40 nicotris launchServer.sh[771]: Exit:1
sept. 07 15:07:40 nicotris launchServer.sh[771]: [MysqldResource] Mysqld not running. No file: /home/pere/Documents/referenceapplication-standalone-2.7.0/database/data/MysqldResource.pid

It seems like is trying to find the file MysqldResource.pid file but it doesn’t finds it. However, if I run the shell, for instance, from the desktop OpenMRS starts normally and working fine.

I have been looking in the forum, but I haven’t found any topic talking about this issue. I would be very appreciated if you could help me.

Thank you all!

Could it be a permission problem? Which account is the service running under?

Thank you Daniel for your fast answer!

Service is running under administrator acount, so it should not be a permission issue.

Any other ideas?

I have been trying to solve the issue and I have kind of conclusion, but still don’t know how to solve it.

I modified the script to see if the mysqld process is running:

#!/bin/bash

cd /home/pere/Documents/referenceapplication-standalone-2.7.0/ 
java -jar openmrs-standalone.jar
ps -ef | grep mysqld

After rebooting the computer and checking the status of the service I got this:

● OpenMRS.service - Launch OpenMRS server service
   Loaded: loaded (/lib/systemd/system/OpenMRS.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since lun. 2018-09-10 16:19:47 CEST; 1min 1s ago
  Process: 773 ExecStart=/usr/local/bin/launchServer.sh (code=exited, status=0/SUCCESS)
 Main PID: 773 (code=exited, status=0/SUCCESS)

sept. 10 16:19:46 nicotris launchServer.sh[773]:         at java.awt.Frame.<init>(Frame.java:420)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at java.awt.Frame.<init>(Frame.java:385)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at javax.swing.JFrame.<init>(JFrame.java:189)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at org.openmrs.standalone.MainFrame.<init>(MainFrame.java:68)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at org.openmrs.standalone.ApplicationController.init(ApplicationController.java:227)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at org.openmrs.standalone.ApplicationController.<init>(ApplicationController.java:55)
sept. 10 16:19:46 nicotris launchServer.sh[773]:         at org.openmrs.standalone.ApplicationController.main(ApplicationController.java:126)
sept. 10 16:19:46 nicotris launchServer.sh[773]: Exit:1
sept. 10 16:19:47 nicotris launchServer.sh[773]: [MysqldResource] Mysqld not running. No file: /home/pere/Documents/referenceapplication-standalone-2.7.0/database/data/MysqldResource.pid
sept. 10 16:19:47 nicotris launchServer.sh[773]: pere      1216   773  0 16:19 ?        00:00:00 grep mysqld

Where this line.

sept. 10 16:19:47 nicotris launchServer.sh[773]: pere 1216 773 0 16:19 ? 00:00:00 grep mysqld

clearly says that mysql process is not running after executing the .jar file. Perhaps this is why it can not find the MysqldResource.pid file.

Otherwise, if I run the script directly from the desktop and check the mysqld process I get this:

pere@nicotris:/usr/local/bin$ ps -ef|grep mysqld
pere      3807  3760  4 17:04 pts/18   00:00:00 /home/pere/Documents/referenceapplication-standalone-2.7.0/database/bin/mysqld --no-defaults --basedir=/home/pere/Documents/referenceapplication-standalone-2.7.0/database --max_allowed_packet=96M --port=3320 --datadir=/home/pere/Documents/referenceapplication-standalone-2.7.0/database/data --character-set-server=utf8 --socket=mysql.sock --collation-server=utf8_general_ci --pid-file=/home/pere/Documents/referenceapplication-standalone-2.7.0/database/data/MysqldResource.pid
pere      3829  2490  0 17:04 pts/19   00:00:00 grep --color=auto mysqld

Which means that everything works fine.

I’m kind of a bit lost and I don’t really know how to fix this problem. Any ideas?

Can you share the full error log or stack trace?

@dkayiwa Stack trace of mysql? Java?

For Java…

It finally worked. There were problems with the graphic console. It can not be launched as a service. So I only had to execute the jar file in commandline mode.

I made a quick guide for make run OpenMRS as a service and launch it automatically after boot and after this is network available. It might be useful for somebody!

Here it goes:

Launching OpenMRS automatically as a service

Steps to follow for making the OpenMRS launch automatically. It starts automatically after booting the pc and when is network available.

Script to launch the server:

#!/bin/bash
cd /home/pere/Documents/referenceapplication-standalone-2.7.0/ 
java -jar openmrs-standalone.jar -commandline

We have to save it in:/usr/local/bin/

Now, create a file called: /lib/system/system/OpenMRS.service

It has to contain:

[Unit]

Description=Launch OpenMRS server service

After=network.target

StartLimitIntervalSec=0

[Service]

Type=simple

RestartSec=1

User=pere

ExecStart=/usr/local/bin/launchServer.sh

[Install]

WantedBy=multi-user.target

Where User= field contains the user’s session name and ExecStart = the path to run the script.

Now, start the service:

$ systemctl start OpenMRS

And start on boot:

$ systemctl enable OpenMRS

For checking the status of the service:

$ systemctl status OpenMRS.service

Thanks @sergiogimenez for sharing! :slight_smile:

Do you mind creating a wiki page and then link to it from here? https://wiki.openmrs.org/display/docs/OpenMRS+Standalone

You’re welcome! I think that is the spirit for this kind of projects.

By the wat @dkayiwa, it seems that I do not have access to the wiki page due to my “basic user” status. Could it be possible? If it is not about permissions, I don’t know why I can’t log in the wiki page.

Awesome! :smile:

Just create a help desk case and you will be granted the required permission.