|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi, everybody!
I,m trying to reach with goals new service : 1) On start - run two instances of "socat" with parameters; chmod 777 them; 2) On stop - kill only those two instances of "socat"; 3) On restart - stop and start service; 4) On status - check if "socat" instances are running and if not - start them. Here is my "service": Code:
#!/bin/bash
# chkconfig: - 98 02
# description: socat service
# processname: socat
KIND="Socat"
FsIn='/usr/bin/socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.0.188:7000'
ScIn='/usr/bin/socat PTY,link=/dev/ttyS1,raw,echo=0 tcp4:192.168.0.188:7001'
Port1=/dev/ttyS0
Port2=/dev/ttyS1
start() {
echo -n $"Starting $KIND services: "
$FsIn &
$ScIn &
chmod 777 $Port1
chmod 777 $Port2
echo
}
stop() {
echo -n $"Shutting down $KIND services: "
killproc $FsIn
killproc $ScIn
echo
}
restart() {
echo -n $"Restarting $KIND services: "
killproc $FsIn
killproc $ScIn
$FsIn &
$ScIn &
chmod 777 $Port1
chmod 777 $Port2
echo
}
status() {
TEST='ps ax | grep -c $FsIn';
if [ "$TEST" = "2" ];
then
echo "Alive :)"
else
echo "Dead :("
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $?
I have tried a lot of modifications, this is just one of them.Can service watch for "socat" (maybe some "while" loop) instances and respawn them if they dies? Thanks in advance! |
|
|||
|
Thanks for answer. But still no joy. Here is a part of my script:
Code:
start)
echo -n $"Starting socat services: "
Temp1=/var/run/socat1.pid
FsIn='/usr/bin/socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.1.105:7000'
Chk1=$(ps -fe | grep "$FsIn" | head -n1|cut -d" " -f 7)
$FsIn &
echo $Chk1 > $Temp1
# Remember status and be verbose
rc_status -v
;;
P.S. Sorry for English, I'm in a hurry |
|
|||
|
Look at using /etc/inittab. Web search for inittab.
|
|
|||
|
I have tried inittab, but in some cases it can't respawn my process. For example, if I unplug network cable from comp and plug in it in 10 seconds. Only "init q" can help me in that case
|
|
|||
|
So you write a wrapper that init calls to detect anomalous conditions and exit so that init can restart it. Maybe even create a watchdog process to monitor the work process. Thing is you end up writing your own respawn loop anyway if you write your own SysV init script instead of using inittab.
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|