ridelogic_daemon_manager 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. #
  3. # ridelogic_daemon_manager
  4. #
  5. # Copyright (c) 2019 Clementine Computing LLC.
  6. #
  7. # This file is part of PopuFare.
  8. #
  9. # PopuFare is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # PopuFare is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  21. #
  22. . /etc/rc.d/init.d/functions
  23. if [ -f /etc/ridelogic/daemon.conf ]
  24. then
  25. . /etc/ridelogic/daemon.conf
  26. else
  27. echo "Missing config file /etc/ridelogic/daemon.conf, exiting"
  28. exit 1
  29. fi
  30. daemon=( ridelogic_avlsd ridelogic_buspassd ridelogic_billingd ridelogic_hellod ridelogic_versiond )
  31. prog=''
  32. for d in ${daemon[@]}
  33. do
  34. if [ "$1" == $d ]
  35. then
  36. prog=$d
  37. break
  38. fi
  39. done
  40. if [ -z "$1" ] || [ -z "$prog" ]
  41. then
  42. echo "Usage: $0 daemon (start|stop|restart|condrestart)"
  43. exit 1
  44. fi
  45. path="$RIDELOGIC_DAEMON_DIR/$prog"
  46. pidfile="$RIDELOGIC_DAEMON_PID_DIR/$prog.pid"
  47. logfile="$RIDELOGIC_DAEMON_LOG_DIR/$prog.log"
  48. start() {
  49. if [ -e "$pidfile" ]; then
  50. if ps -p `cat $pidfile` > /dev/null 2>&1; then
  51. echo $path is already running - skipping start
  52. return 0
  53. else
  54. echo Lockfile $pidfile is junk. Deleting...
  55. rm -f $pidfile
  56. fi
  57. fi
  58. echo -n Starting $path
  59. daemon --user $RIDELOGIC_DAEMON_USER $path
  60. RETVAL=$?
  61. echo
  62. return $RETVAL
  63. }
  64. stop() {
  65. RETVAL=0
  66. if [ -e $pidfile ]; then
  67. echo -n Stopping $path
  68. killproc $path
  69. RETVAL=$?
  70. rm -f $pidfile
  71. else
  72. echo -n $path is not running
  73. fi
  74. echo
  75. return $RETVAL
  76. }
  77. case $2 in
  78. start )
  79. start
  80. ;;
  81. stop )
  82. stop
  83. ;;
  84. restart )
  85. stop
  86. start
  87. ;;
  88. status )
  89. status -p ${pidfile} $path
  90. ;;
  91. condrestart )
  92. if [ -f "$pidfile" ] ; then
  93. stop
  94. start
  95. fi
  96. ;;
  97. * )
  98. echo "Usage: $prog (start|stop|restart|condrestart|status)"
  99. ;;
  100. esac