cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Problems to call REST end point of EMS

drichter
14-Alexandrite

Problems to call REST end point of EMS

Hi,

 

I have a edge device where ems/lua is running in a docker container. The edge device is a gateway, what mean other devices are connected to the edge device. EMS is quite normally connected with thingworx. On Thingworx I will add new devices (what mean I will update the config.json) via code. To do this I will use the REST Services that EMS supports ( http://support.ptc.com/help/edge_microserver/r5.4.7/en/index.html#page/edge_microserver%2Fc_ems_wsems_rest_api_details.html%23 ). I test the REST-Calls via curl on the console where EMS is running (in the docker container). In most case of the calls I get error codes back. For example this call

 

curl -d '{name:EMSBox__DARI}' http://localhost:8000/Thingworx/Things/LocalEms/Services/Restart -v

 

gives me a 403 Forbidden (note: EMSBox__DARI is my thing based on RemoteThingWithTunnelsAndFileTransfer which is connected to EMS). Other calls like

 

curl -d '{name:EMSBox__DARI}' http://localhost:8000/Thingworx/Things/LocalEms/Services/GetMicroserverVersion -v

 

works fine with HTTP-200 OK and the result:

{"rows":[{"result":"5.4.7.864"}],"datashape":{"fieldDefinitions":{"result":{"name":"result","description":"","baseType":"STRING","aspects":{}}}}}

 

How can I restart the EMS- and Lua-service via the EMS-REST-API?

1 ACCEPTED SOLUTION

Accepted Solutions

After some discussions with David, we reached the conclusion that the following activities need to be performed:

1. Add the "-b" parameter to the do_start() function in the tw_luaScriptResourced and tw_microServerd from the "install_services" folder

2. Remove the "--pidfile $PIDFILE" in the do_stop() function in the tw_luaScriptResourced and tw_microServerd from the "install_services" folder

3. The restart script that was used to restart the services looks now like this:

#!/bin/bash

sleep 5

service tw_luaScriptResourced stop

service tw_microServerd stop

sleep 5

service tw_microServerd start

sleep 10

service tw_luaScriptResourced start

View solution in original post

6 REPLIES 6
slangley
23-Emerald II
(To:drichter)

Hi @drichter.

 

It looks like the documentation is a little misleading.  For restarting the EMS, the command syntax should be something like this:

 

curl http://localhost:8000/Thingworx/Things/LocalEms/Services/Restart -v

 

We were testing using Postman, however, so you may have to play around with the syntax for cURL.

 

Please be sure your config.json is allowing restarts.

 

Another option for restarting the EMS, would be to create a batch file and initiate the restart at the o/s level, or set up the EMS process as a service within the o/s.

 

Regards.

 

--Sharon

drichter
14-Alexandrite
(To:slangley)

Okay, I really forgot the to set the restart-property in config.json.

 

Now when I send

curl -d '{name:EMSBox__DARI}' http://localhost:8000/Thingworx/Things/LocalEms/Services/Restart -v

it seems that the call is doing something (it takes a short moment ~1s before the result 200-OK) but its doesn't restart the ems service. The service call without the thingname returns 400 Bad Request.

 

Before I saw the restart-service of ems I used a bash-script:

#!/bin/bash
sleep 1s
service tw_microServerd restart
service tw_luaScriptResourced restart

When I call this script in my console everything works fine. When I call this script via its restart the services but the EMS will not connect correctly with TWX. The file transfert not longer works.

 

Here the restarting part in lue-script which call the bash-file:

 

serviceDefinitions.RestartServices(
    output { baseType="NOTHING", description="" },
    description { "restarts the services for WSEMS and LUAScriptResource" }
)


services.RestartServices = function(me)
    os.execute("/microserver/etc/custom/bash/restartServices.sh &")
    return 200
end

 

slangley
23-Emerald II
(To:slangley)

Hi @drichter.

 

We followed up with engineering on the Restart function to validate the behavior.  The information contained in the Help Center is incorrect and is being updated with the next release.

 

Specifically, the Restart function can only be used to restart the EMS--not a device.  The url would be something like this:  http://localhost:8000/Thingworx/Things/LocalEms/Services/Restart

 

Please let us know if you still have questions.

 

Regards.

 

--Sharon

 

 

drichter
14-Alexandrite
(To:slangley)

I know that the device is not restart. But without a name (from auto_bind) it will not restart the EMS. With the name as -d parameter it is doing something but i don't thing that its reload the new config.json.

 

And the other question is, how to restart the lua-service after changing config.lua?

Hi,

 

Can you try to put a

sleep 5s

 between the two service restart calls in your bash script?

After some discussions with David, we reached the conclusion that the following activities need to be performed:

1. Add the "-b" parameter to the do_start() function in the tw_luaScriptResourced and tw_microServerd from the "install_services" folder

2. Remove the "--pidfile $PIDFILE" in the do_stop() function in the tw_luaScriptResourced and tw_microServerd from the "install_services" folder

3. The restart script that was used to restart the services looks now like this:

#!/bin/bash

sleep 5

service tw_luaScriptResourced stop

service tw_microServerd stop

sleep 5

service tw_microServerd start

sleep 10

service tw_luaScriptResourced start

Top Tags