org_server.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2019 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. org_daemon_base_dir="/home/bus/bin/server_daemon"
  21. org_deamon_pid_dir="/tmp"
  22. org_daemon_log_dir="/home/bus/log"
  23. daemon=( avls_server billing_server buspass_server hello_daemon version_server )
  24. start_org_server() {
  25. path=$1
  26. lockfile=$2
  27. logfile=$3
  28. if [ -e "$lockfile" ]; then
  29. if ps -p `cat $lockfile` > /dev/null 2>&1; then
  30. echo $path is already running - skipping start
  31. return 0
  32. else
  33. echo Lockfile $lockfile is junk. Deleting...
  34. rm -f $lockfile
  35. #start_buspass_server
  36. fi
  37. fi
  38. if [ -z "$logfile" ]
  39. then
  40. logfile="/dev/null"
  41. fi
  42. #else
  43. echo Starting $path
  44. $path > $logfile 2>&1 &
  45. echo $! > $lockfile
  46. #fi
  47. }
  48. stop_org_server() {
  49. path=$1
  50. lockfile=$2
  51. if [ -e $lockfile ]; then
  52. echo Stopping $path
  53. kill `cat $lockfile`
  54. rm -f $lockfile
  55. else
  56. echo $path is not running
  57. fi
  58. }
  59. echo
  60. case $1 in
  61. start )
  62. for d in ${daemon[@]}
  63. do
  64. start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
  65. done
  66. ;;
  67. stop )
  68. for d in ${daemon[@]}
  69. do
  70. stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
  71. done
  72. ;;
  73. restart )
  74. $0 stop
  75. $0 start
  76. ;;
  77. * )
  78. for d in ${daemon[@]}
  79. do
  80. if [ "$d" == $1 ]
  81. then
  82. case "$2" in
  83. start )
  84. start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
  85. break
  86. ;;
  87. stop )
  88. stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
  89. break
  90. ;;
  91. restart )
  92. stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
  93. start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
  94. break
  95. ;;
  96. * )
  97. break
  98. ;;
  99. esac
  100. return 0
  101. fi
  102. done
  103. echo "Usage:"
  104. echo " $0 start"
  105. echo " $0 stop"
  106. echo " $0 restart"
  107. ;;
  108. esac