B4J Question jshell - start a java app on linux

codie01

Active Member
Licensed User
Longtime User
Hi All,

I need help with starting a java app from a manager java app running in centos linux. Basically I can start and stop the app from ssh in Linux via a bash script as follows:

bash script : bgwWatch.sh:
#! /bin/bash

if [ "$1" == "start" ]; then
   nohup java -Xms128m -Xmx256m -jar /home/bgw/apps/bgwWatch.jar 1> /home/bgw/logs/bgwWatch.log 2>&1 </dev/null &
   echo ""
   echo "bgwWatch.service started"
fi

if [ "$1" == "stop" ]; then
   pkill -f bgwWatch
   echo ""
   echo "bgwWatch.service stopped"
fi

In my manager app built in b4J ABMaterial, I am able to STOP the app but unable to START it. The start and stop buttons fire and run the run_command precedure.

BUTTON EVENTS AND RUN CODE:
Sub myModalprocessChip2a1_Clicked(Target As String)
    Log("STOP")
    Dim clickedApp As String = "bgwWatch.sh"
    Dim clickedCommand As String = "stop"
    Run_Command("/home/bgw/" & clickedApp, Array As String(clickedCommand))
    StartMessageLoop
End Sub

Sub myModalprocessChip2a2_Clicked(Target As String)
    Log("START")
    Dim clickedApp As String = "bgwWatch.sh"
    Dim clickedCommand As String = "START"
    Run_Command("./" & clickedApp, Array As String(clickedCommand))
    StartMessageLoop
End Sub

Sub Run_Command( cli As String, args As List)
    Try
        Log( "Run_Command")
        Dim sh As Shell
        'sh.Initialize("cli",cli,args)
        sh.InitializeDoNotHandleQuotes("cli", cli, args)
        sh.Run(1000)    '<<< changed
       
        Wait for cli_ProcessCompleted( Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
         
        '    #if Debug
        page.ShowToast(DateTime.Now,"",cli & " " & Success & "; ExitCode = " & ExitCode & "StdOut = " & StdOut & " StdErr = " & StdErr,3000,False)
        Log(Success & "; ExitCode = " & ExitCode)
        Log("StdOut = " &  StdOut)
        Log("StdErr = " &  StdErr)

    Catch
        Log("RUN:COMMAND - SHELL INTERUPT ISSUE!")
    End Try
End Sub

Any ideas Please.
 

teddybear

Well-Known Member
Licensed User
It seems the bgwWatch.sh is not in dirapp, try using full-path to start it
B4X:
Sub myModalprocessChip2a2_Clicked(Target As String)

    Log("START")

    Dim clickedApp As String = "bgwWatch.sh"

    Dim clickedCommand As String = "START"

    'Run_Command("./" & clickedApp, Array As String(clickedCommand))
    Run_Command("/home/bgw/" & clickedApp, Array As String(clickedCommand))

    StartMessageLoop

End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Could it be the script checks for "start" and you send it "START"
 
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…