Advertisement
Guest User

Script to start utserver in ubuntu.

a guest
Sep 6th, 2010
11,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.54 KB | None | 0 0
  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:          utserver
  4. # Required-Start:    $local_fs $remote_fs $network
  5. # Required-Stop:     $local_fs $remote_fs $network
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start or stop the utserver.
  9. ### END INIT INFO
  10.  
  11. CHDIR=<dir containing utserver program>
  12. NAME=utserver
  13. OPTIONS="-LOGFILE"
  14. DAEMON=$CHDIR/$NAME
  15. USER=<username>
  16. PIDFILE=/var/run/$NAME.pid
  17. STOP_TIMEOUT=5
  18.  
  19. [ -x $DAEMON ] || exit 1
  20.  
  21. . /lib/lsb/init-functions
  22.  
  23. start_daemon () {
  24.     pgrep -U $USER $NAME >/dev/null && echo "$NAME is already running" && log_end_msg 1
  25.     rm -f $PIDFILE >/dev/null
  26.     start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --chuid $USER --chdir $CHDIR --background --exec $DAEMON -- $OPTIONS
  27. }
  28.  
  29. case "$1" in
  30.     start)         
  31.         log_daemon_msg "Starting $NAME daemon" "$NAME"
  32.         start_daemon
  33.         log_end_msg 0
  34.         ;;
  35.     stop)
  36.         log_daemon_msg "Stopping $NAME daemon" "$NAME"
  37.         start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT || log_end_msg 1
  38.         pgrep -U $USER $NAME >/dev/null || rm -f $PIDFILE >/dev/null
  39.         log_end_msg 0
  40.         ;;
  41.     restart)
  42.         log_daemon_msg "Restarting $NAME daemon" "$NAME"
  43.         start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT || log_end_msg 1
  44.         start_daemon
  45.         log_end_msg 0
  46.         ;;
  47.     *)
  48.         echo "Usage: /etc/init.d/$NAME {start|stop|restart}"
  49.         exit 2
  50.         ;;
  51. esac
  52.  
  53. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement