summaryrefslogtreecommitdiff
path: root/system/guix/config/rc.guix
blob: b07ebce7aa9c00d1b92dd45a6bc4731e946d40be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

# Short-Description:  A purely functional package manager.
# Description:
# GNU Guix provides state-of-the-art package management features such as
# transactional upgrades and roll-backs, reproducible build environments,
# unprivileged package management, and per-user profiles. It uses low-level
# mechanisms from the Nix package manager, but packages are defined as native 
# Guile modules, using extensions to the Scheme language—which makes it nicely
# hackable.

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

BASE=guix-daemon

UNSHARE=/usr/bin/unshare
GUIX=/usr/bin/$BASE
GUIX_PIDFILE=/var/run/$BASE.pid
GUIX_LOG=/var/log/guix.log
GUIX_OPTS=--build-users-group=guixbuild

if [ -f /etc/default/$BASE ]; then
  . /etc/default/$BASE
fi

# Check guix is present
if [ ! -x $GUIX ]; then
  echo "$GUIX not present or not executable"
  exit 1
fi

guix_start() {
  echo "starting $BASE ..."
  if [ -x ${GUIX} ]; then
    # If there is an old PID file (no guix-daemon running), clean it up:
    if [ -r ${GUIX_PIDFILE} ]; then
      if ! ps axc | grep guix-daemon 1> /dev/null 2> /dev/null ; then
        echo "Cleaning up old ${GUIX_PIDFILE}."
        rm -f ${GUIX_PIDFILE}
      fi
    fi
    nohup "${UNSHARE}" -m -- "${GUIX}" "${GUIX_OPTS}" >> ${GUIX_LOG} 2>&1 &
    echo $! > ${GUIX_PIDFILE}
  fi
}

guix_stop() {
  echo "stopping $BASE ..."
  # If there is no PID file, ignore this request...
  if [ -r ${GUIX_PIDFILE} ]; then
    kill $(cat ${GUIX_PIDFILE})
  fi
  rm -f ${GUIX_PIDFILE}
}

guix_restart() {
  guix_stop
  guix_start
}

case "$1" in
'start')
  guix_start
  ;;
'stop')
  guix_stop
  ;;
'restart')
  guix_restart
  ;;
'status')
  if [ -f ${GUIX_PIDFILE} ] && ps -o cmd $(cat ${GUIX_PIDFILE}) | grep -q $BASE ; then
    echo "status of $BASE: running"
  else
    echo "status of $BASE: stopped"
  fi
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac

exit 0