LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   How to define pidfile in sh script of AIX (https://www.linuxquestions.org/questions/aix-43/how-to-define-pidfile-in-sh-script-of-aix-4175479209/)

Firerat 10-03-2013 07:47 AM

Quote:

Originally Posted by Firerat (Post 5039249)
until you use code tags I will not help.

https://www.linuxquestions.org/quest....php?do=bbcode

redssr 10-03-2013 07:59 AM

Hi,

Friend,

Sorry.

Kindly find the script.
Code:


cat opensync_linux
#!/bin/ksh
#
# chkconfig: 345 99 05
# description: Java deamon script
#
# A non-SUSE Linux start/stop script for Java daemons.
#
# Derived from -
# Home page: http://www.source-code.biz
# License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)
# Copyright 2006 Christian d'Heureuse, Inventec Informatik AG, Switzerland.
#
# History:
# 2010-09-21 Josh Davis: Changed 'sudo' to 'su', fix some typos, removed unused variables
# 2009-03-04 Josh Davis: Ubuntu/Redhat version.
# 2006-06-27 Christian d'Heureuse: Script created.
# 2006-07-02 chdh: Minor improvements.
# 2006-07-10 chdh: Changes for SUSE 10.0.


# Set this to your Java installation
JAVA_HOME=/usr/java6

serviceNameLo="opensyncserver" # service name with the first letter in lowercase
serviceName="opensync" # service name
serviceUser="root" # OS user name for the service
serviceGroup="system" # OS group name for the service
applDir="/usr/cachesys/od_bk/Server_Platform" # home directory of the service application
#serviceUserHome="/home/$serviceUser" # home directory of the service user
serviceLogFile="$applDir/$serviceNameLo.log" # log file for StdOut/StdErr
maxShutdownTime=15 # maximum number of seconds to wait for the daemon to terminate normally
pidFile="/var/run/$serviceNameLo.pid" # name of PID file (PID = process ID number)
javaCommand="java" # name of the Java launcher without the path
javaExe="$JAVA_HOME/bin/$javaCommand" # file name of the Java application launcher executable
javaArgs=" -jar $applDir/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application"
javaCommandLine="$javaExe $javaArgs" # command line to start the Java service application

# Makes the file $1 writable by the group $serviceGroup.
function makeFileWritable {
local filename="$1"
touch $filename || return 1
chgrp $serviceGroup $filename || return 1
chmod g+w $filename || return 1
return 0; }

# Returns 0 if the process with PID $1 is running.
function checkProcessIsRunning {
local pid="$1"
if [ -z "$pid" -o "$pid" == " " ]; then return 1; fi
if [ ! -e /proc/$pid ]; then return 1; fi
return 0; }

# Returns 0 if the process with PID $1 is our Java service process.
function checkProcessIsOurService {
local pid="$1"
if [ "$(ps -p $pid --no-headers -o comm)" != "$javaCommand" ]; then return 1; fi
grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
if [ $? -ne 0 ]; then return 1; fi
return 0; }

# Returns 0 when the service is running and sets the variable $pid to the PID.
function getServicePID {
if [ ! -f $pidFile ]; then return 1; fi
pid="$(<$pidFile)"
checkProcessIsRunning $pid || return 1
checkProcessIsOurService $pid || return 1
return 0; }

function startServiceProcess {
cd $applDir || return 1
rm -f $pidFile
makeFileWritable $pidFile || return 1
makeFileWritable $serviceLogFile || return 1
cmd="$javaCommandLine >>$serviceLogFile 2>&1 |& echo \$! >$pidFile"
# cmd="nohup $javaCommandLine >>$serviceLogFile 2>&1 & echo \$! >$pidFile"
su -c "$cmd" || return 1
# su -m $serviceUser -s $SHELL -c "$cmd" || return 1
sleep 0.1
pid="$(<$pidFile)"
if checkProcessIsRunning $pid; then :; else
echo -ne "\n$serviceName start failed, see logfile."
return 1
fi
return 0; }

function stopServiceProcess {
kill $pid || return 1
for i in $(seq 0 $((maxShutdownTime*10)))
do
checkProcessIsRunning $pid
if [ $? -ne 0 ]; then
rm -f $pidFile
return 0
fi
sleep 0.1
done
echo -e "\n$serviceName did not terminate within $maxShutdownTime seconds, sending SIGKILL..."
kill -s KILL $pid || return 1
local killWaitTime=15
for i in $(seq 0 $((maxShutdownTime*10)))
do
checkProcessIsRunning $pid
if [ $? -ne 0 ]; then
rm -f $pidFile
return 0
fi
sleep 0.1
done
echo "Error: $serviceName could not be stopped within $maxShutdownTime+$killWaitTime seconds!"
return 1; }

function startService {
getServicePID
if [ $? -eq 0 ]; then echo -n "$serviceName is already running"; RETVAL=0; return 0; fi
echo -n "Starting $serviceName "
startServiceProcess
if [ $? -ne 0 ]; then RETVAL=1; echo "failed"; return 1; fi
echo "started PID=$pid"
RETVAL=0
return 0; }

function stopService {
getServicePID
if [ $? -ne 0 ]; then echo -n "$serviceName is not running"; RETVAL=0; echo ""; return 0; fi
echo -n "Stopping $serviceName "
stopServiceProcess
if [ $? -ne 0 ]; then RETVAL=1; echo "failed"; return 1; fi
echo "stopped PID=$pid"
RETVAL=0
return 0; }

function checkServiceStatus {
echo -n "Checking for $serviceName: "
if getServicePID; then
echo "running PID=$pid"
RETVAL=0
else
echo "stopped"
RETVAL=3
fi
return 0; }

function main {
RETVAL=0
case "$1" in
start) # starts the Java program as a Linux service
startService
;;
stop) # stops the Java program service
stopService
;;
restart) # stops and restarts the service
stopService && startService
;;
status) # displays the service status
checkServiceStatus
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
}

main $1

Regards,

redssr

redssr 10-03-2013 08:03 AM

Its my mistake.

Its started but not getting stoped.

Kindly find the output
Code:

ksh -x opensync_linux stop
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/var/run/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main stop
ps: Not a recognized flag: -
Usage: ps [-AMNZaedfklm] [-n namelist] [-F Format] [-o specifier[=header],...]
[-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist] [ -T pid] [ -L pidlist ]
[-@ [wparname] ]
Usage: ps [aceglnsuvwxX] [t tty] [processnumber]
-n opensync is not running

Regards,

Firerat 10-03-2013 08:20 AM

you lost the indentation, but let us ignore that


why are you using ksh?
Actually, let us ignore that as well

Your error

Code:

ps: Not a recognized flag: -
Usage: ps [-AMNZaedfklm] [-n namelist] [-F Format] [-o specifier[=header],...]
[-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist] [ -T pid] [ -L pidlist ]
[-@ [wparname] ]



Code:

# Returns 0 if the process with PID $1 is our Java service process.
function checkProcessIsOurService {
  local pid="$1"
  if [ "$(ps -p $pid --no-headers -o comm)" != "$javaCommand" ]; then return 1; fi
  grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
  if [ $? -ne 0 ]; then return 1; fi
  return 0; }

see the bold..

AIX's ps is different to the one the script was written for

Code:

# Returns 0 if the process with PID $1 is our Java service process.
function checkProcessIsOurService {
  local pid="$1"
  if [ "$(ps -T $pid --no-headers -o comm)" != "$javaCommand" ]; then return 1; fi
  grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
  if [ $? -ne 0 ]; then return 1; fi
  return 0; }

the rest of the ps, you will have to experiment..


post output of
Code:

ps | grep java



I honestly have no idea why that grep has --binary, we shall cross that bridge later..

redssr 10-04-2013 03:23 AM

Hi,

Done changes according to yr sugesstions. Here is the output.
code given by u.
Code:

function checkProcessIsOurService {
  local pid="$1"
  if [ "$(ps -T $pid --no-headers -o comm)" != "$javaCommand" ]; then return 1; fi
  grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
  if [ $? -ne 0 ]; then return 1; fi
  return 0; }

After that

Code:

opensync_linux start
-n Starting opensync
sleep: 0509-020 Specify time as a positive integer.
started PID=9699444
ps |grep java
  8323156  pts/2  0:00 grep java
  9699444  pts/2  0:05 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla

netstat -aAn|grep 3636
f1000e000a643bb8 tcp        0      0  *.3636                *.*                  LISTEN

ksh -x opensync_linux stop
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main stop
ps: Not a recognized flag: -
Usage: ps [-AMNZaedfklm] [-n namelist] [-F Format] [-o specifier[=header],...]
                [-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist] [ -T pid] [ -L pidlist ]
                [-@ [wparname] ]
Usage: ps [aceglnsuvwxX] [t tty] [processnumber]
-n opensync is not running

After stopping the process the output of ps is same as of after starting
Code:

ps |grep java
  8323156  pts/2  0:00 grep java
  9699444  pts/2  0:05 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla

netstat -aAn|grep 3636
f1000e000a643bb8 tcp        0      0  *.3636                *.*                  LISTEN

About changing shell, I cant do it as it's a client's machine and they r not in the will of changing it.

Regards.

redssr

cliffordw 10-04-2013 03:32 AM

Quote:

Originally Posted by redssr (Post 5039247)
Sorry,

Friends,

Its my mistake.

Its started but not getting stoped.

Kindly find the output

ksh -x opensync_linux stop
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/var/run/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main stop
ps: Not a recognized flag: -
Usage: ps [-AMNZaedfklm] [-n namelist] [-F Format] [-o specifier[=header],...]
[-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist] [ -T pid] [ -L pidlist ]
[-@ [wparname] ]
Usage: ps [aceglnsuvwxX] [t tty] [processnumber]
-n opensync is not running

Regards,

redssr

Hi,

The problem seems to be with this command:
Code:

ps -p $pid --no-headers -o comm
AIX doesn't support the --no-headers option. Try changing your command to:
Code:

ps -p $pid -o comm | grep -v COMMAND

redssr 10-04-2013 03:58 AM

Hi,

Changes done as per yr suggestion.

Still same output.

Code:

opensync_linux start
-n Starting opensync
sleep: 0509-020 Specify time as a positive integer.
started PID=8323318
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # ps |grepjava
ksh: grepjava:  not found.
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # ps |grep java
  8323318  pts/2  0:01 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla
 10420404  pts/2  0:00 grep java
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # netstat -aAn|grep 3636
f1000e0001ab43b8 tcp        0      0  *.3636                *.*                  LISTEN
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # opensync_linux ^C
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # ksh -x opensync_linux stop
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main stop
grep: Not a recognized flag: -
grep: Not a recognized flag: a
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
        [-f pattern_file...] [file...]
Usage: grep [-r] [-R] [-H] [-L]  [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
        -f pattern_file... [file...]
Usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] pattern_list [file...]
-n opensync is not running

(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # ps |grep java
  8323318  pts/2  0:05 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla
  9830610  pts/2  0:00 grep java
(ADS-BACKUP SERV) /usr/cachesys/od_bk/Server_Platform # netstat -aAn|grep 3636
f1000e0001ab43b8 tcp        0      0  *.3636                *.*                  LISTEN

Regards,

redssr

cliffordw 10-04-2013 04:10 AM

Hi there,

Surely you can figure some of this out yourself? The result is not the same. The "ps" error is gone, and you now have a "grep" error. The cause is the same - using arguments which are not supported by AIX. How about looking at the man page to try and fix it yourself?

Good luck!

Clifford

redssr 10-04-2013 04:57 AM

Hi,

Friends,

Here is my other problem now,

Code:

ksh -x opensync_linux start
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main start
-n Starting opensync
sleep: 0509-020 Specify time as a positive integer.
started PID=3473522


ksh -x opensync_linux status
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main status
-n Checking for opensync:
stopped

ps |grep java
  3473522  pts/2  0:02 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla
  7340184  pts/2  0:00 grep java

netstat -aAn|grep 3636
f1000e0001bce3b8 tcp        0      0  *.3636                *.*                  LISTEN

I had not stopped the service yet but still status showing stopped. I replaced the -v option of grep with -R
old code
Code:

ps -p $pid -o comm | grep -v COMMAND
I replaced it with
Code:

ps -p $pid -o comm | grep -R COMMAND
Regards,

redssr

Firerat 10-04-2013 07:38 AM

Quote:

Originally Posted by redssr (Post 5039857)
About changing shell, I cant do it as it's a client's machine and they r not in the will of changing it.

Regards.

redssr

I imagine they have sh available
you will not be changing their shell, only using it for the script..

However, that will not help you here, since the problem is the 'utilities' used in the script are using a different, incompatible syntax.

I did say you needed to experiment with that ps

found a manual ( which should have been very simple for yourself )
http://publib.boulder.ibm.com/infoce...ixcmds4/ps.htm

the -T was wrong,
Code:

-T pid        Displays the process hierarchy rooted at a given pid in a tree format using ASCII art.
              This flag can be used in combination with the -f, -F, -o, and -l flags.

so, you should be able to just drop the --no-headers, and use -o comm= ( not from above box, but the full manual, read it , I did and I'm not getting paid, you are. )
Code:

function checkProcessIsOurService {
  local pid="$1"
  if [ "$( ps -p $pid -o comm= )" != "$javaCommand" ]; then return 1; fi
  grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
  if [ $? -ne 0 ]; then return 1; fi
  return 0; }


now your grep, I don't think you need --binary
from gnu's grep manpage on debian
Code:

      -U, --binary
              Treat the file(s) as binary.  By default, under MS-DOS and MS-Windows, grep guesses the file type by looking at the contents of the first 32KB read from the file.  If grep decides the file
              is a text file, it strips the CR characters from the original file contents (to make regular expressions with ^ and $ work correctly).  Specifying -U overrules this guesswork, causing  all
              files to be read and passed to the matching mechanism verbatim; if the file is a text file with CR/LF pairs at the end of each line, this will cause some regular expressions to fail.  This
              option has no effect on platforms other than MS-DOS and MS-Windows.

still, it shouldn't take much for you to work out the equivalent on AIX

redssr 10-07-2013 12:46 AM

Hi,

Friend,

Sorry if you had got hurted. It was my mistake. Actually i am not as expert in AIX as in Linux. As said before this script i had developed in linux and its working fine and i copy pasted the same script here. But due to your guidelines i had reached till here. And i am realy thankful for the same.
This is the 9th day (excluding weekoffs) where i am working on AIX. I even don't know the ABCD of AIX, but i am trying my best to make it possible.

You were right. they had sh shel available and i used the same now for script. I corrected the code as per yr suggestions. and here is the output.

Code:

sh -x opensync_linux start
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main start
-n Starting opensync
sleep: 0509-020 Specify time as a positive integer.
started PID=8257712

 ps |grep java
  8257712  pts/0  0:00 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla
 10420340  pts/0  0:00 grep java

sh -x opensync_linux status
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main status
-n Checking for opensync:
grep: 0652-033 Cannot open /proc/8257712/cmdline.
stopped

ls -lrtr /proc/8257712
total 16
lr-x------  24 root    system            0 Oct 07 01:04 root -> /
lr-x------    9 root    system            0 Oct 07 02:00 cwd -> /usr/cachesys/od_bk/Server_Platform/
-r--r--r--    1 root    system            0 Oct 07 02:01 sysent
-r--------    1 root    system        1520 Oct 07 02:01 status
-r--------    1 root    system        12288 Oct 07 02:01 sigact
-r--r--r--    1 root    system          448 Oct 07 02:01 psinfo
dr-x------    1 root    system            0 Oct 07 02:01 object
-r--------    1 root    system            0 Oct 07 02:01 mmap
-r--------    1 root    system            0 Oct 07 02:01 map
dr-xr-xr-x    1 root    system            0 Oct 07 02:01 lwp
dr-x------    1 root    system            0 Oct 07 02:01 fd
--w-------    1 root    system            0 Oct 07 02:01 ctl
-r--------    1 root    system          128 Oct 07 02:01 cred
-rw-------    1 root    system            0 Oct 07 02:01 as

netstat -anA|grep 3636
f1000e0001cbe3b8 tcp        0      0  *.3636                *.*                  LISTEN

Unable to understand this strange outputs. The service is running but the status is showing still stoped. I had not stoped the service yet.

Regards,

redssr

Firerat 10-07-2013 03:16 AM

Quote:

Cannot open /proc/8257712/cmdline.
does not exist..

check the other files in /proc/8257712/ ,
Or check the cwd is a link to /usr/cachesys/od_bk/Server_Platform/ which is probably enough as a 'double check'

redssr 10-07-2013 03:45 AM

Yes there is a link pointing to the directory.

Code:


ls -lrtr /proc/8257712
total 16
lr-x------  24 root    system            0 Oct 07 01:04 root -> /
lr-x------    9 root    system            0 Oct 07 02:00 cwd -> /usr/cachesys/od_bk/Server_Platform/
-r--r--r--    1 root    system            0 Oct 07 02:01 sysent
-r--------    1 root    system        1520 Oct 07 02:01 status
-r--------    1 root    system        12288 Oct 07 02:01 sigact
-r--r--r--    1 root    system          448 Oct 07 02:01 psinfo
dr-x------    1 root    system            0 Oct 07 02:01 object
-r--------    1 root    system            0 Oct 07 02:01 mmap
-r--------    1 root    system            0 Oct 07 02:01 map
dr-xr-xr-x    1 root    system            0 Oct 07 02:01 lwp
dr-x------    1 root    system            0 Oct 07 02:01 fd
--w-------    1 root    system            0 Oct 07 02:01 ctl
-r--------    1 root    system          128 Oct 07 02:01 cred
-rw-------    1 root    system            0 Oct 07 02:01 as

netstat -anA|grep 3636
f1000e0001cbe3b8 tcp        0      0  *.3636                *.*                  LISTEN

I replaced the code

Code:

/proc/pid/cmdline
with

Code:

/proc/pid/cwd
the error gone but the status still showing stopped without any error.

Code:

sh -x opensync_linux status
+ JAVA_HOME=/usr/java6
+ serviceNameLo=opensyncserver
+ serviceName=opensync
+ serviceUser=root
+ serviceGroup=system
+ applDir=/usr/cachesys/od_bk/Server_Platform
+ serviceLogFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.log
+ maxShutdownTime=15
+ pidFile=/usr/cachesys/od_bk/Server_Platform/opensyncserver.pid
+ javaCommand=java
+ javaExe=/usr/java6/bin/java
+ javaArgs= -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ javaCommandLine=/usr/java6/bin/java  -jar  /usr/cachesys/od_bk/Server_Platform/Opensync-server-platform-1.3.0.jar com.qarea.opendoc.server.Application
+ main status
-n Checking for opensync:
stopped

Regards,

redssr

Firerat 10-07-2013 04:24 AM

Quote:

Originally Posted by redssr (Post 5041375)
Yes there is a link pointing to the directory.



I replaced the code

Code:

/proc/pid/cmdline
with

Code:

/proc/pid/cwd
the error gone but the status still showing stopped without any error.


redssr

?
you are trying to grep a symlink?

lets go back and see what you are doing

Code:

function checkProcessIsOurService {
  local pid="$1"
  # the PID is from a file ( created when service started )
  if [ "$(ps -p $pid -o comm=)" != "$javaCommand" ]; then return 1; fi
  # use ps to print the command of the PID we had in the file,
  # if that command does not match what we expect it to be ( java ) return 1
  grep -q --binary -F "$javaCommandLineKeyword" /proc/$pid/cmdline
  if [ $? -ne 0 ]; then return 1; fi
  # the above serves as a double check, it could be a coincidence that the PID just happens to be java
  #  First problem, javaCommandLineKeyword is commented out in the OP
  # Next problem /proc/$pid/cmdline does not exist on AIX.
  # What was it intended to do?
  # check the file /proc/$pid/cmdline contains $javaCommandLineKeyword
  # (Opensync-angel-services-1.3.0.jar angel.plugin.Main)
  # since /proc/$pid/cmdline does not exist , look for the string in the other files in /proc/$pid/
  # if that fails, then test the cwd symlink
  # example..
  # JavaCWD=/usr/cachesys/od_bk/Server_Platform
  # ( stat -c %N /proc/$pid/cwd | grep -q "$JavaCWD" ) || return 1
  return 0; }

an alternative is to check the output of ps, it may truncate ( but I think that is only when output is to a term, grep should get the 'full' line... I think..not 100%

from manual
Code:

args
    Indicates the full command name being executed. All command-line arguments are included, though truncation may occur. The default header for this field is COMMAND.

so
Code:

( ps -p $pid -o args= | grep -q "$javaCommandLineKeyword" ) || return 1
Note, I have used list constructs
http://www.tldp.org/LDP/abs/html/lis...ml#LISTCONSREF
I honestly can't recall if they work in plain sh
re-write as if statements

redssr 10-07-2013 04:46 AM

Hi,

Friend,

Thanks for your most valuable help. It worked finally. I can't explain in words what u have done for me.

Here is the output.

Code:


opensync_linux start
-n Starting opensync
sleep: 0509-020 Specify time as a positive integer.
started PID=10027050

 ps |grep java
  7208978  pts/0  0:00 grep java
 10027050  pts/0  0:00 /usr/java6/bin/java -jar /usr/cachesys/od_bk/Server_Pla

opensync_linux status
-n Checking for opensync:
running PID=10027050

opensync_linux stop
-n stoping opensync

opensync_linux status
-n Checking for opensync:
stopped

 ps |grep java

With Warm Rqegards,

redssr


All times are GMT -5. The time now is 12:09 AM.