I have a shell script and I decided to create AIX service with subsystem.
. Here how the subsystem is defined:
mkssys -s mytest -p "/home/tester/testServices/bin/test/script.sh" -a "start" -u 206 -R -Q -d -S -n 9 -f 15
Now the `script.sh` is the following script:
#!/bin/bash
PRINT_SCRIPT=/home/tester/testServices/Screen.sh
LOG_FILE="/home/tester/testServices/bin/test/log.txt"
echo "Begin script" >> "$LOG_FILE"
trap sigquit 9 15
sigquit()
{
set -x
echo "Stop case" >> "$LOG_FILE"
PID=ps -ef | grep screen.sh | grep -v grep | awk '{print $2}'
kill -9 $PID
exit 0
}
case "$1" in
start)
echo "Starting screen.sh" >> "$LOG_FILE"
$PRINT_SCRIPT
;;
stop)
echo "Stopping screen.sh" >> "$LOG_FILE"
PID=ps -ef | grep screen.sh | grep -v grep | awk '{print $2}'
kill -9 $PID
;;
*)
echo "USAGE " >> "$LOG_FILE"
echo "Usage: {start|stop}" >&2
exit 1
;;
esac
exit 0
I have made the subsystem to be used under the user with ID=206, and i have added in /etc/sudoers permissions to start/stop the service .Interestingly when I start it via `sudo startsrc -s mytest` , the subsystem goes to active status (via lssrc -a) and the start) clause gets called and i see indeed a logging in the file, however when i stop the subsystem via `sudo stopsrc -s mytest` the subsystem goes from active to inoperative ,However I don't see any logging in the file and the underlying script $PRINT_SCRIPT keeps running .Now my theory is that it doesn't even get called since even "Begin script" is not logged into the file on stop.
Interestingly when i make the same service but change the user from 206 to 0 (aka root) and start and stop it as a root everything works perfect.Why under the user with ID=206 it doesn't log anything?And is this the correct way a shell script to understand from the AIX SRC that it has to stop, if not what is the practice to make a service understand that it has to stop , as you can see I have checked if "stop" arguments is passed and also tried with signals in the sigquit() but it doesn't work under non-root user.Also under root user, on stop it doesn't log anything but the script stops working.