guix-daemon.in 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: guix-daemon
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Guix build daemon
  9. # Description: Provides a daemon that does builds for Guix
  10. ### END INIT INFO
  11. set -e
  12. mkdir -p "/var/run"
  13. if [ ! -f "@localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon" ]
  14. then
  15. exit 5
  16. fi
  17. case "$1" in
  18. start)
  19. if [ -f "/var/run/guix-daemon.pid" ]
  20. then
  21. if pgrep -F "/var/run/guix-daemon.pid" guix-daemon
  22. then
  23. exit 0
  24. else
  25. echo "guix-daemon has a stale pid file" >&2
  26. exit 1
  27. fi
  28. else
  29. daemonize \
  30. -a \
  31. -e "/var/log/guix-daemon-stderr.log" \
  32. -o "/var/log/guix-daemon-stdout.log" \
  33. -E GUIX_LOCPATH=@localstatedir@/guix/profiles/per-user/root/guix-profile/lib/locale \
  34. -E LC_ALL=en_US.utf8 \
  35. -p "/var/run/guix-daemon.pid" \
  36. @localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon \
  37. --build-users-group=guixbuild --discover=no
  38. fi
  39. ;;
  40. stop)
  41. if [ -f "/var/run/guix-daemon.pid" ]
  42. then
  43. pkill -F "/var/run/guix-daemon.pid" guix-daemon || {
  44. exit 1
  45. }
  46. rm -f "/var/run/guix-daemon.pid"
  47. exit 0
  48. else
  49. exit 0
  50. fi
  51. ;;
  52. status)
  53. if [ -f "/var/run/guix-daemon.pid" ]
  54. then
  55. if pgrep -F "/var/run/guix-daemon.pid" guix-daemon
  56. then
  57. echo "guix-daemon is running"
  58. exit 0
  59. else
  60. echo "guix-daemon has a stale pid file"
  61. exit 1
  62. fi
  63. else
  64. echo "guix-daemon is not running"
  65. exit 3
  66. fi
  67. ;;
  68. restart|force-reload)
  69. "$0" stop
  70. "$0" start
  71. ;;
  72. *)
  73. echo "Usage: $0 (start|stop|status|restart|force-reload)"
  74. exit 3
  75. ;;
  76. esac