[Chugalug] Bash Scripting Question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Chugalug] Bash Scripting Question

Dean Warren
Hey guys,
 I am running a game server that is hosting a couple of old BBS doors. The front end is an interesting telnet to http/https front end called fTelnet and the doors are hosted thru GameSrv. I am attempting to create a start up script called gamesrv to place in /etc/init.d to start the service on boot. Here is the code thus far:
gamesrv script

#! /bin/sh
### BEGIN INIT INFO
# Provides: gamesrv
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: gamesrv
# Description: This file starts and stops the Gamesrv server
#
### END INIT INFO

GAMESRV_DIR=/Gamesrv

case "$1" in
 start)
   su gamesrv -c $GAMESRV_DIR/start.sh
   ;;
 stop)
   su gamesrv -c $GAMESRV_DIR/stop.sh
   sleep 10
   ;;
 restart)
   su gamesrv -c $GAMESRV_DIR/stop.sh
   sleep 20
   su gamesrv -c $GAMESRV_DIR/start.sh
   ;;
 *)
   echo "Usage: gamesrv {start|stop|restart}" >&2
   exit 3
   ;;
esac

The start.sh script:

#!/bin/bash

# Check the effective user id to see if it's root (EUID works with sudo, UID does not)
if (( EUID != 0 )); then
   echo "######## ########   ########  #######  ########"
   echo "##            ##       ##  ##        ##  ##     ## ##       ##"
   echo "##            ##       ##  ##        ##  ##     ## ##       ##"
   echo "######     ########  ########   ##     ## ########"
   echo "##            ##     ##    ##      ##    ##     ## ##     ##"
   echo "##            ##      ##   ##       ##   ##     ## ##      ##"
   echo "########  ##      ##  ##        ##  ####### ##       ##"
   echo ""
   echo ""
   echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
   echo "This script must be run as root to work properly!"
   echo "You could also try running 'sudo ./start.sh' too."
   echo "##################################################"
   echo ""
   exit 1
fi

# Create a PID to keep track of what process is what
echo $$ >> /var/run/gamesrv/start_sh.pid

# for DOSEMU -- may be able to comment out in newer releases
sysctl -w vm.mmap_min_addr="0"

cd /Gamesrv
privbind -u gamesrv -g gamesrv mono GameSrvConsole.exe DEBUG


Then my stop.sh script
#!/bin/bash
# Stop script for gamesrv start.sh script
file="/var/run/gamesrv/start_sh.pid"
# Check the effective user id to see if it's root (EUID works with sudo, UID does not)
if (( EUID != 0 )); then
   echo "######## ########  ########   #######  ########"
   echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
   echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
   echo "######    ########  ########   ##     ##   ########"
   echo "##           ##     ##    ##     ##     ##     ##   ##     ##"
   echo "##           ##      ##   ##      ##    ##     ##   ##      ##"
   echo "######## ##       ## ##       ##   #######   ##       ##"
   echo ""
   echo ""
   echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
   echo "This script must be run as root to work properly!"
   echo "You could also try running 'sudo start.sh' too."
   echo "##################################################"
   echo ""
   exit 1
fi

# Find the PID we created on startup and placed in /var/run/gamesrv/start_sh.pid 
if [ -e $file ];
then
   kill $(cat $file)
   rm $file
else echo "Process is NOT running."
fi

The problem is that if it is started from another terminal I don't see the start.sh process using ps -A.

Is there a way to find the running process regardless of where it is started?



Hope you have a great day,
Dean Warren

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
Reply | Threaded
Open this post in threaded view
|

Re: [Chugalug] Bash Scripting Question

Jared Hamilton
I use `ps aux` to sort by user who owns process and includes processes run
without attached tty (per man page). Hope that helps?

On Thu, Oct 08, 2015 at 10:29:49AM -0400, Dean Warren wrote:

>   Hey guys,
>    I am running a game server that is hosting a couple of old BBS doors. The
>   front end is an interesting telnet to http/https front end called
>   [1]fTelnet and the doors are hosted thru [2]GameSrv. I am attempting to
>   create a start up script called gamesrv to place in /etc/init.d to start
>   the service on boot. Here is the code thus far:
>   gamesrv script
>   #! /bin/sh
>   ### BEGIN INIT INFO
>   # Provides: gamesrv
>   # Required-Start: $remote_fs $syslog
>   # Required-Stop: $remote_fs $syslog
>   # Default-Start: 2 3 4 5
>   # Default-Stop: 0 1 6
>   # Short-Description: gamesrv
>   # Description: This file starts and stops the Gamesrv server
>   #
>   ### END INIT INFO
>   GAMESRV_DIR=/Gamesrv
>   case "$1" in
>    start)
>      su gamesrv -c $GAMESRV_DIR/start.sh
>      ;;
>    stop)
>      su gamesrv -c $GAMESRV_DIR/stop.sh
>      sleep 10
>      ;;
>    restart)
>      su gamesrv -c $GAMESRV_DIR/stop.sh
>      sleep 20
>      su gamesrv -c $GAMESRV_DIR/start.sh
>      ;;
>    *)
>      echo "Usage: gamesrv {start|stop|restart}" >&2
>      exit 3
>      ;;
>   esac
>   The start.sh script:
>   #!/bin/bash
>   # Check the effective user id to see if it's root (EUID works with sudo,
>   UID does not)
>   if (( EUID != 0 )); then
>      echo "######## ########   ########  #######  ########"
>      echo "##            ##       ##  ##        ##  ##     ## ##       ##"
>      echo "##            ##       ##  ##        ##  ##     ## ##       ##"
>      echo "######     ########  ########   ##     ## ########"
>      echo "##            ##     ##    ##      ##    ##     ## ##     ##"
>      echo "##            ##      ##   ##       ##   ##     ## ##      ##"
>      echo "########  ##      ##  ##        ##  ####### ##       ##"
>      echo ""
>      echo ""
>      echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
>      echo "This script must be run as root to work properly!"
>      echo "You could also try running 'sudo ./start.sh' too."
>      echo "##################################################"
>      echo ""
>      exit 1
>   fi
>   # Create a PID to keep track of what process is what
>   echo $$ >> /var/run/gamesrv/start_sh.pid
>   # for DOSEMU -- may be able to comment out in newer releases
>   sysctl -w vm.mmap_min_addr="0"
>   cd /Gamesrv
>   privbind -u gamesrv -g gamesrv mono GameSrvConsole.exe DEBUG
>   Then my stop.sh script
>   #!/bin/bash
>   # Stop script for gamesrv start.sh script
>   file="/var/run/gamesrv/start_sh.pid"
>   # Check the effective user id to see if it's root (EUID works with sudo,
>   UID does not)
>   if (( EUID != 0 )); then
>      echo "######## ########  ########   #######  ########"
>      echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
>      echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
>      echo "######    ########  ########   ##     ##   ########"
>      echo "##           ##     ##    ##     ##     ##     ##   ##     ##"
>      echo "##           ##      ##   ##      ##    ##     ##   ##      ##"
>      echo "######## ##       ## ##       ##   #######   ##       ##"
>      echo ""
>      echo ""
>      echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
>      echo "This script must be run as root to work properly!"
>      echo "You could also try running 'sudo start.sh' too."
>      echo "##################################################"
>      echo ""
>      exit 1
>   fi
>   # Find the PID we created on startup and placed in
>   /var/run/gamesrv/start_sh.pid 
>   if [ -e $file ];
>   then
>      kill $(cat $file)
>      rm $file
>   else echo "Process is NOT running."
>   fi
>   The problem is that if it is started from another terminal I don't see the
>   start.sh process using ps -A.
>   Is there a way to find the running process regardless of where it is
>   started?
>   Hope you have a great day,
>   Dean Warren
>
>References
>
>   Visible links
>   1. https://ftelnet.ca/
>   2. https://gamesrv.ca/

>_______________________________________________
>Chugalug mailing list
>[hidden email]
>http://chugalug.org/cgi-bin/mailman/listinfo/chugalug

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
Reply | Threaded
Open this post in threaded view
|

Re: [Chugalug] Bash Scripting Question

Dean Warren
Jared,
Yeah, "ps aux -A" that is a big help. Thanks!

Hope you have a great day,
Dean Warren

On Thu, Oct 8, 2015 at 11:04 AM, Jared Hamilton <[hidden email]> wrote:
I use `ps aux` to sort by user who owns process and includes processes run without attached tty (per man page). Hope that helps?

On Thu, Oct 08, 2015 at 10:29:49AM -0400, Dean Warren wrote:
  Hey guys,
   I am running a game server that is hosting a couple of old BBS doors. The
  front end is an interesting telnet to http/https front end called
  [1]fTelnet and the doors are hosted thru [2]GameSrv. I am attempting to

  create a start up script called gamesrv to place in /etc/init.d to start
  the service on boot. Here is the code thus far:
  gamesrv script
  #! /bin/sh
  ### BEGIN INIT INFO
  # Provides: gamesrv
  # Required-Start: $remote_fs $syslog
  # Required-Stop: $remote_fs $syslog
  # Default-Start: 2 3 4 5
  # Default-Stop: 0 1 6
  # Short-Description: gamesrv
  # Description: This file starts and stops the Gamesrv server
  #
  ### END INIT INFO
  GAMESRV_DIR=/Gamesrv
  case "$1" in
   start)
     su gamesrv -c $GAMESRV_DIR/start.sh
     ;;
   stop)
     su gamesrv -c $GAMESRV_DIR/stop.sh
     sleep 10
     ;;
   restart)
     su gamesrv -c $GAMESRV_DIR/stop.sh
     sleep 20
     su gamesrv -c $GAMESRV_DIR/start.sh
     ;;
   *)
     echo "Usage: gamesrv {start|stop|restart}" >&2
     exit 3
     ;;
  esac
  The start.sh script:
  #!/bin/bash
  # Check the effective user id to see if it's root (EUID works with sudo,
  UID does not)
  if (( EUID != 0 )); then
     echo "######## ########   ########  #######  ########"
     echo "##            ##       ##  ##        ##  ##     ## ##       ##"
     echo "##            ##       ##  ##        ##  ##     ## ##       ##"
     echo "######     ########  ########   ##     ## ########"
     echo "##            ##     ##    ##      ##    ##     ## ##     ##"
     echo "##            ##      ##   ##       ##   ##     ## ##      ##"
     echo "########  ##      ##  ##        ##  ####### ##       ##"
     echo ""
     echo ""
     echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
     echo "This script must be run as root to work properly!"
     echo "You could also try running 'sudo ./start.sh' too."
     echo "##################################################"
     echo ""
     exit 1
  fi
  # Create a PID to keep track of what process is what
  echo $$ >> /var/run/gamesrv/start_sh.pid
  # for DOSEMU -- may be able to comment out in newer releases
  sysctl -w vm.mmap_min_addr="0"
  cd /Gamesrv
  privbind -u gamesrv -g gamesrv mono GameSrvConsole.exe DEBUG
  Then my stop.sh script
  #!/bin/bash
  # Stop script for gamesrv start.sh script
  file="/var/run/gamesrv/start_sh.pid"
  # Check the effective user id to see if it's root (EUID works with sudo,
  UID does not)
  if (( EUID != 0 )); then
     echo "######## ########  ########   #######  ########"
     echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
     echo "##           ##       ##  ##       ##   ##     ##   ##       ##"
     echo "######    ########  ########   ##     ##   ########"
     echo "##           ##     ##    ##     ##     ##     ##   ##     ##"
     echo "##           ##      ##   ##      ##    ##     ##   ##      ##"
     echo "######## ##       ## ##       ##   #######   ##       ##"
     echo ""
     echo ""
     echo "####### ERROR: ROOT PRIVILEGES REQUIRED #########"
     echo "This script must be run as root to work properly!"
     echo "You could also try running 'sudo start.sh' too."
     echo "##################################################"
     echo ""
     exit 1
  fi
  # Find the PID we created on startup and placed in
  /var/run/gamesrv/start_sh.pid 
  if [ -e $file ];
  then
     kill $(cat $file)
     rm $file
  else echo "Process is NOT running."
  fi
  The problem is that if it is started from another terminal I don't see the
  start.sh process using ps -A.
  Is there a way to find the running process regardless of where it is
  started?
  Hope you have a great day,
  Dean Warren

References

  Visible links
  1. https://ftelnet.ca/
  2. https://gamesrv.ca/

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug


_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug