0

Linux server start when PC starts, but cannot get to stop or restart

Jackie Roos 8 лет назад в Server Solutions / Linux Server 0

Hi

I have the following script that starts, stops and restarts iRidium server on Ubuntu


#!/bin/sh
### BEGIN INIT INFO
# Provides:          iridiumserver
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $portmap
# Should-Stop:       $portmap
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.

### END INIT INFO

test -x /iridiumserver/iridium || exit 0
IRDIR=/iridiumserver
IREXE=$IRDIR/iridium
IRPID=$IRDIR/iridium.pid
IRPARAMS="--watchdog=10 --hidden"
USERID="root"

case "$1" in
start)
        echo -n "Starting iRidium server:"
        cd $IRDIR
        start-stop-daemon --start --chuid $USERID --chdir $IRDIR --make-pidfile --pidfile $IRPID    --exec $IREXE -- $IRPARAMS &
        echo "."
        ;;

stop)
        echo -n "Stopping iRidium server:"
        start-stop-daemon --stop --quiet --pidfile $IRPID
        if [ -e $IRPID ]
                then rm $IRPID
        fi
        echo "."  ;;

restart)
        echo -n "Restarting iRidium server:"
        cd $IRDIR
        start-stop-daemon --stop --quiet --pidfile $IRPID
        start-stop-daemon --start --chuid $USERID --chdir $IRDIR --make-pidfile --pidfile $IRPID    --exec $IREXE -- $IRPARAMS &  echo "."  ;;
*)
        echo "Usage: /etc/init.d/iridiumserver (start|stop|restart)"
        exit 1
        ;;

esac
exit 0


Then run the following commands in the terminal to get this to work

//move the above script to the startup folder

 cp home/linux/Downloads/iridiumserver /etc/init.d/iridiumserver

//change permissions to be executable

sudo chmod +x /etc/init.d/iridiumserver

//add the script to the startup

  sudo update-rc.d iridiumserver defaults 10

Now can run the script manually to test

  sudo /etc/init.d/iridiumserver

Result:

 Usage: /etc/init.d/iridiumserver (start|stop|restart)

 sudo /etc/init.d/iridiumserver start

Result:

  Starting iRidium server:.
   =================== Start as Daemon ===================
   Main thread exit

//enter CTL + C to get back to the terminal

  ^C

Test by rebooting

sudo shutdown -r now


The iRidium server starts.


But I cannot get the stop and restarts to work. It says cannot find the pid, and running the second time says stopping, but it does not actually stop.


Any suggestions please?


Thanks


Сервис поддержки клиентов работает на платформе UserEcho