mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Exit on unexpected params; better testing when launching; use bash to create pid file.
This commit is contained in:
parent
4c8cf98d24
commit
022317b47a
2 changed files with 17 additions and 13 deletions
|
@ -87,7 +87,7 @@ logf( XW_LogLevel level, const char* format, ... )
|
|||
syslog( LOG_LOCAL0 | LOG_INFO, buf );
|
||||
va_end(ap);
|
||||
#else
|
||||
static FILE* where = 0;
|
||||
static FILE* where = stderr;
|
||||
struct tm* timp;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
@ -566,6 +566,12 @@ int main( int argc, char** argv )
|
|||
}
|
||||
}
|
||||
|
||||
/* Did we consume all the options passed in? */
|
||||
if ( optind != argc ) {
|
||||
usage( argv[0] );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
RelayConfigs::InitConfigs( conffile );
|
||||
RelayConfigs* cfg = RelayConfigs::GetConfigs();
|
||||
|
||||
|
@ -613,12 +619,6 @@ int main( int argc, char** argv )
|
|||
}
|
||||
}
|
||||
|
||||
pid_t pid = getpid();
|
||||
FILE* f = fopen( "./xwrelay.pid", "w" );
|
||||
assert( f );
|
||||
fprintf( f, "%d", pid );
|
||||
fclose( f );
|
||||
|
||||
#ifdef SPAWN_SELF
|
||||
/* loop forever, relaunching children as they die. */
|
||||
for ( ; ; ) {
|
||||
|
|
|
@ -3,32 +3,36 @@
|
|||
XWRELAY="./xwrelay"
|
||||
PIDFILE=./xwrelay.pid
|
||||
|
||||
CMD=$1
|
||||
shift
|
||||
|
||||
case $1 in
|
||||
case $CMD in
|
||||
|
||||
stop)
|
||||
if [ -f $PIDFILE ]; then
|
||||
if [ -f $PIDFILE ] && [ -f /proc/$(cat $PIDFILE)/exe ]; then
|
||||
sync
|
||||
echo "killing pid=$(cat $PIDFILE)"
|
||||
kill $(cat $PIDFILE)
|
||||
rm $PIDFILE
|
||||
else
|
||||
echo "not running"
|
||||
fi
|
||||
rm $PIDFILE
|
||||
;;
|
||||
|
||||
restart)
|
||||
$0 stop
|
||||
sleep 1
|
||||
$0 start
|
||||
$0 start $@
|
||||
;;
|
||||
|
||||
start|*)
|
||||
if [ -f $PIDFILE ]; then
|
||||
if [ -f $PIDFILE ] && [ -f /proc/$(cat $PIDFILE)/exe ]; then
|
||||
echo "already running: pid=$(cat $PIDFILE)"
|
||||
else
|
||||
echo "starting..."
|
||||
$XWRELAY
|
||||
$XWRELAY $@ &
|
||||
NEWPID=$!
|
||||
echo $NEWPID > $PIDFILE
|
||||
sleep 1
|
||||
echo "running with pid=$(cat $PIDFILE)"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue