Guest User

Untitled

a guest
May 16th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #!/bin/bash -e
  2. #
  3. # TinyERP
  4.  
  5. NAME=tinyerp
  6. DESC="TinyERP Server"
  7. DAEMON=/usr/bin/tinyerp-server
  8. DAEMON_ARGS="--db_host=localhost --db_port=5432 --database=terp --db_user=terp --db_password=terp"
  9. PIDFILE=/var/run/$NAME.pid
  10. WEB_DAEMON=/usr/bin/start-tinyerp
  11. WEB_PIDFILE=/var/run/etiny-server.pid
  12.  
  13. LOG_PATH=/var/log/tinyERP
  14. LOG_SERVER=tiny_serv.log
  15.  
  16. PID=$(cat $PIDFILE &)
  17.  
  18. ###########################################################
  19.  
  20. if [ $(whoami) != 'tinyerp' ] ; then
  21. echo 'Permission denied: This script must be run as tinyerp !'
  22. exit 1
  23. fi
  24.  
  25. do_start() {
  26. # Check if server is running
  27. if ps --pid $PID > /dev/null ; then
  28. echo "$DESC is already running !\n"
  29. exit 1
  30. fi
  31. start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS >> $LOG_PATH/$LOG_SERVER &
  32. start-stop-daemon --start --make-pidfile --pidfile $WEB_PIDFILE --exec $WEB_DAEMON &
  33. }
  34.  
  35. do_stop() {
  36. # Check if server is running
  37. if ! ps --pid $PID > /dev/null ; then
  38. echo "$DESC is not running !\n"
  39. exit 1
  40. fi
  41. start-stop-daemon --stop --pidfile $PIDFILE
  42. start-stop-daemon --stop --signal HUP --pidfile $WEB_PIDFILE
  43. }
  44.  
  45. case "$1" in
  46. start)
  47. echo "Starting $DESC...\n"
  48. do_start
  49. ;;
  50.  
  51. stop)
  52. echo "Stopping $DESC...\n"
  53. do_stop
  54. ;;
  55.  
  56. restart)
  57. echo "Restarting $DESC:"
  58. echo " Stopping $DESC..."
  59. do_stop
  60. sleep 0.5
  61. echo " Starting $DESC...\n"
  62. do_start
  63. ;;
  64.  
  65. # Default behaviour
  66. *)
  67. echo "Usage: /etc/init.d/tinyerp {start|stop|restart}\n" >&2
  68. echo
  69. exit 2
  70. ;;
  71. esac
  72.  
  73. exit 0
Add Comment
Please, Sign In to add comment