選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

init.d 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: <NAME>
  4. # Required-Start: $local_fs $network $named $time $syslog
  5. # Required-Stop: $local_fs $network $named $time $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Description: <DESCRIPTION>
  9. ### END INIT INFO
  10. SCRIPT='screen -dmS fake-tracker /var/fake-tracker/fake-tracker.py /var/fake-tracker/config.conf'
  11. RUNAS=root
  12. PIDFILE=/var/run/fake-tracker.pid
  13. start() {
  14. if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
  15. echo 'Service already running' >&2
  16. return 1
  17. fi
  18. echo 'Starting service…' >&2
  19. local CMD="$SCRIPT & echo \$!"
  20. su -c "$CMD" $RUNAS > "$PIDFILE"
  21. echo 'Service started' >&2
  22. }
  23. stop() {
  24. if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
  25. echo 'Service not running' >&2
  26. return 1
  27. fi
  28. echo 'Stopping service…' >&2
  29. kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
  30. echo 'Service stopped' >&2
  31. }
  32. uninstall() {
  33. echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  34. local SURE
  35. read SURE
  36. if [ "$SURE" = "yes" ]; then
  37. stop
  38. rm -f "$PIDFILE"
  39. echo "Notice: log file is not be removed: '$LOGFILE'" >&2
  40. update-rc.d -f <NAME> remove
  41. rm -fv "$0"
  42. fi
  43. }
  44. case "$1" in
  45. start)
  46. start
  47. ;;
  48. stop)
  49. stop
  50. ;;
  51. uninstall)
  52. uninstall
  53. ;;
  54. retart)
  55. stop
  56. start
  57. ;;
  58. *)
  59. echo "Usage: $0 {start|stop|restart|uninstall}"
  60. esac