Stopping Apps via ssh

Discussions about Z-Way software and Z-Wave technology in general
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Stopping Apps via ssh

Post by ridewithstyle »

Hi there,

it seems that I have created an EasyScripting app that kills everything and makes zway ununsable (it was the seconds that I hit "run" I realized that this would result in a royal clustermess.

I haven't found any documentation so far how I can stop/kill zway and stop the app via textfile edit and restart zway. Alternatively: where are the EasyScripting apps located as textfile? My "find" magic was not sufficient for this

Thanks, zway is currently pauting at 100% CPU and refusing to talk to me

best regards,
rws
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Re: Stopping Apps via ssh

Post by ridewithstyle »

Hi there,

managed to find my culprit, but I had to resort to violence. This is just in case, somebody else has the same problem.

Firstly, everything seems to be stored in /opt/z-way-server/automation/storage/configjson-xy.json, I only found that by using

Code: Select all

find / -type f -exec grep -H 'text-to-find-here' {} \;


whereas my text-to-find was a code-part I knew by heart. I then placed a syntax error so the script would fail. That allowed my to access my gui again.

Nerves wrecked for a moment for sure

Regards,
rws
lanbrown
Posts: 279
Joined: 01 Jun 2021 08:06

Re: Stopping Apps via ssh

Post by lanbrown »

To see the status of Z-Way:

Code: Select all

sudo systemctl status z-way-server
To stop Z-Way:

Code: Select all

sudo systemctl stop z-way-server
To restart Z-Way:

Code: Select all

sudo systemctl restart z-way-server
To start Z-Way:

Code: Select all

sudo systemctl start z-way-server
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Re: Stopping Apps via ssh

Post by ridewithstyle »

Thanks, but you misunderstood, I was asking how to suspend APPS in ZWay via ssh. Not how to stop and resume ZWay.
lanbrown
Posts: 279
Joined: 01 Jun 2021 08:06

Re: Stopping Apps via ssh

Post by lanbrown »

ridewithstyle wrote:
07 May 2022 06:02
Thanks, but you misunderstood, I was asking how to suspend APPS in ZWay via ssh. Not how to stop and resume ZWay.
I haven't found any documentation so far how I can stop/kill zway and stop the app via textfile edit and restart zway.
I provided the Z-Way portion as you specifically mentioned stopping and restarting Z-Way. So the commands I provided are exactly how you handle Z-Way. The app you speak of could just be a process that gets triggered. So if that is the case, restarting Z-Way may not start the app app unless it gets triggered to start it.

To see what processes are running and if it is using a lot of CPU time, then you can use the ps command along with grep to get rid of processes with no CPU time.

Code: Select all

ps -ef | grep -v 00:00
Once you have the PID, you can use:

Code: Select all

sudo kill -9 [i]PID[/i]
So if the PID was 38247 you would use:

Code: Select all

sudo kill -9 38247
You could even use cron to run every few minutes and if the CPU is at 100% to terminate the process. If the App is running as part of Z-Way then restarting Z-Way should clear it unless it gets triggered to run.
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Re: Stopping Apps via ssh

Post by ridewithstyle »

Hi there, I really appreciate the effort, but the app - due to my error - was constantly triggered, so I needed it to be deactivated. I don't know yet where the status is if an app, once I find that out, I'll post it here for reference.
lanbrown
Posts: 279
Joined: 01 Jun 2021 08:06

Re: Stopping Apps via ssh

Post by lanbrown »

When the app is active use top and ps to see if you can find it. If you can see it listed, then you can kill it.
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Re: Stopping Apps via ssh

Post by ridewithstyle »

lanbrown wrote:
07 May 2022 17:50
When the app is active use top and ps to see if you can find it. If you can see it listed, then you can kill it.
top only showed the z-way-server at 105% CPU, nothing more.

To clarify further what my question was: what is the equivalent to do from the console when I can't click on this "suspend" Button anymore
2022-05-12 10_08_54-Z-Wave Smart Home.png
2022-05-12 10_08_54-Z-Wave Smart Home.png (3.16 KiB) Viewed 1942 times
seattleneil
Posts: 172
Joined: 02 Mar 2020 22:41

Re: Stopping Apps via ssh

Post by seattleneil »

Z-Way does not have a friendly shell command to stop/start a specific script that runs as part of the EasyScripting module. It can be done, but it's not pretty.

Run the following shell commands as root, replace BAD_SCRIPT in 2 places and ZWAY_ADMIN_PASSWORD:

Code: Select all

# cp /opt/z-way-server/automation/storage/configjson*json /opt/z-way-server/automation/storage/configjson_`date +%F_%T`
# sed -i /opt/z-way-server/automation/storage/configjson*json -e s/'"EasyScripting","active":true,"title":"BAD_SCRIPT"'/'"EasyScripting","active":false,"title":"BAD_SCRIPT"'/
# curl -s -u admin:ZWAY_ADMIN_PASSWORD --globoff '127.0.0.1:8083/ZAutomation/api/v1/modules/reinitialize/EasyScripting'
Explanation:
1. The first command makes a backup copy of your configuration file. This is an important safety measure that allows you to easily revert back to your original configuration.
2. The second command "edits" the configuration file by changing the status of BAD_SCRIPT (from active:true to active:false). Replace BAD_SCRIPT in 2 places with the name of the script you want to deactivate.
3. The last command tells Z-Way to stop the EasyScripting module, reload the module and re-read the configuration data for the module (i.e., BAD_SCRIPT will not run since active has been changed to false). Replace ZWAY_ADMIN_PASSWORD with your Z-Way admin password.
ridewithstyle
Posts: 155
Joined: 02 Jan 2016 01:20

Re: Stopping Apps via ssh

Post by ridewithstyle »

Excellent, thank you!

I figured that the script status must be in the same file as the script itself was embedded into the configjson. Me adding a syntax error was just the lazy way to edit that huge textfile. Haven't seen vim slowing down for quite a long time to be honest.

Maybe this helps as documentation in case somebody else breaks his/her EasyScripting app.

Thanks again,

BR,
rws
Post Reply