Advertisement
skaramicke

Untitled

Aug 4th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: hass
  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: Home\ Assistant
  9. ### END INIT INFO
  10.  
  11. # /etc/init.d Service Script for Home Assistant
  12. # Created with: https://gist.github.com/naholyr/4275302#file-new-service-sh
  13. PRE_EXEC=""
  14. RUN_AS="USER"
  15. PID_FILE="/var/run/hass.pid"
  16. CONFIG_DIR="/var/opt/homeassistant"
  17. FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
  18. REDIRECT="> $CONFIG_DIR/home-assistant.log 2>&1"
  19.  
  20. start() {
  21. if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
  22. echo 'Service already running' >&2
  23. return 1
  24. fi
  25. echo 'Starting service…' >&2
  26. local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
  27. su -c "$CMD" $RUN_AS
  28. echo 'Service started' >&2
  29. }
  30.  
  31. stop() {
  32. if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then
  33. echo 'Service not running' >&2
  34. return 1
  35. fi
  36. echo 'Stopping service…' >&2
  37. kill $(cat "$PID_FILE")
  38. while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;
  39. echo 'Service stopped' >&2
  40. }
  41.  
  42. install() {
  43. echo "Installing Home Assistant Daemon (hass-daemon)"
  44. echo "999999" > $PID_FILE
  45. chown $RUN_AS $PID_FILE
  46. mkdir -p $CONFIG_DIR
  47. chown $RUN_AS $CONFIG_DIR
  48. }
  49.  
  50. uninstall() {
  51. echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  52. local SURE
  53. read SURE
  54. if [ "$SURE" = "yes" ]; then
  55. stop
  56. rm -fv "$PID_FILE"
  57. echo "Notice: The config directory has not been removed"
  58. echo $CONFIG_DIR
  59. update-rc.d -f hass-daemon remove
  60. rm -fv "$0"
  61. echo "Home Assistant Daemon has been removed. Home Assistant is still installed."
  62. fi
  63. }
  64.  
  65. case "$1" in
  66. start)
  67. start
  68. ;;
  69. stop)
  70. stop
  71. ;;
  72. install)
  73. install
  74. ;;
  75. uninstall)
  76. uninstall
  77. ;;
  78. restart)
  79. stop
  80. start
  81. ;;
  82. *)
  83. echo "Usage: $0 {start|stop|restart|install|uninstall}"
  84. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement