rc.guix 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. # Short-Description: A purely functional package manager.
  3. # Description:
  4. # GNU Guix provides state-of-the-art package management features such as
  5. # transactional upgrades and roll-backs, reproducible build environments,
  6. # unprivileged package management, and per-user profiles. It uses low-level
  7. # mechanisms from the Nix package manager, but packages are defined as native
  8. # Guile modules, using extensions to the Scheme language—which makes it nicely
  9. # hackable.
  10. PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. BASE=guix-daemon
  12. UNSHARE=/usr/bin/unshare
  13. GUIX=/usr/bin/$BASE
  14. GUIX_PIDFILE=/var/run/$BASE.pid
  15. GUIX_LOG=/var/log/guix.log
  16. GUIX_OPTS=--build-users-group=guixbuild
  17. if [ -f /etc/default/$BASE ]; then
  18. . /etc/default/$BASE
  19. fi
  20. # Check guix is present
  21. if [ ! -x $GUIX ]; then
  22. echo "$GUIX not present or not executable"
  23. exit 1
  24. fi
  25. guix_start() {
  26. echo "starting $BASE ..."
  27. if [ -x ${GUIX} ]; then
  28. # If there is an old PID file (no guix-daemon running), clean it up:
  29. if [ -r ${GUIX_PIDFILE} ]; then
  30. if ! ps axc | grep guix-daemon 1> /dev/null 2> /dev/null ; then
  31. echo "Cleaning up old ${GUIX_PIDFILE}."
  32. rm -f ${GUIX_PIDFILE}
  33. fi
  34. fi
  35. nohup "${UNSHARE}" -m -- "${GUIX}" "${GUIX_OPTS}" >> ${GUIX_LOG} 2>&1 &
  36. echo $! > ${GUIX_PIDFILE}
  37. fi
  38. }
  39. guix_stop() {
  40. echo "stopping $BASE ..."
  41. # If there is no PID file, ignore this request...
  42. if [ -r ${GUIX_PIDFILE} ]; then
  43. kill $(cat ${GUIX_PIDFILE})
  44. fi
  45. rm -f ${GUIX_PIDFILE}
  46. }
  47. guix_restart() {
  48. guix_stop
  49. guix_start
  50. }
  51. case "$1" in
  52. 'start')
  53. guix_start
  54. ;;
  55. 'stop')
  56. guix_stop
  57. ;;
  58. 'restart')
  59. guix_restart
  60. ;;
  61. 'status')
  62. if [ -f ${GUIX_PIDFILE} ] && ps -o cmd $(cat ${GUIX_PIDFILE}) | grep -q $BASE ; then
  63. echo "status of $BASE: running"
  64. else
  65. echo "status of $BASE: stopped"
  66. fi
  67. ;;
  68. *)
  69. echo "usage $0 start|stop|restart|status"
  70. esac
  71. exit 0