aboutsummaryrefslogtreecommitdiff
path: root/system/nix/rc.nix
diff options
context:
space:
mode:
authorPragmatic Cypher <slackbuilds@server.ky>2016-11-20 20:51:49 +0000
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2016-11-26 11:47:24 +0700
commit106a4ec9c91ab079ea086ab7745030554cce5506 (patch)
treecbb8d2bc44cf8cd679f2cbd58722c11ddba1886e /system/nix/rc.nix
parent379e0016752c6a561ac6625e387265e3afb20189 (diff)
system/nix: Updated for version 1.11.4.
Signed-off-by: David Spencer <idlemoor@slackbuilds.org>
Diffstat (limited to 'system/nix/rc.nix')
-rw-r--r--system/nix/rc.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/system/nix/rc.nix b/system/nix/rc.nix
new file mode 100644
index 000000000000..86f54a25eac1
--- /dev/null
+++ b/system/nix/rc.nix
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
+
+BASE=nix-daemon
+
+UNSHARE=/usr/bin/unshare
+NIX=/usr/bin/$BASE
+NIX_PIDFILE=/var/run/$BASE.pid
+NIX_LOG=/var/log/nix.log
+NIX_OPTS=
+
+if [ -f /etc/default/$BASE ]; then
+ . /etc/default/$BASE
+fi
+
+# Check nix is present
+if [ ! -x $NIX ]; then
+ echo "$NIX not present or not executable"
+ exit 1
+fi
+
+nix_start() {
+ echo "starting $BASE ..."
+ if [ -x ${NIX} ]; then
+ # If there is an old PID file (no nix-daemon running), clean it up:
+ if [ -r ${NIX_PIDFILE} ]; then
+ if ! ps axc | grep nix-daemon 1> /dev/null 2> /dev/null ; then
+ echo "Cleaning up old ${NIX_PIDFILE}."
+ rm -f ${NIX_PIDFILE}
+ fi
+ fi
+ nohup "${UNSHARE}" -m -- ${NIX} >> ${NIX_LOG} 2>&1 &
+ echo $! > ${NIX_PIDFILE}
+ fi
+}
+
+# Stop nix:
+nix_stop() {
+ echo "stopping $BASE ..."
+ # If there is no PID file, ignore this request...
+ if [ -r ${NIX_PIDFILE} ]; then
+ kill $(cat ${NIX_PIDFILE})
+ fi
+ rm -f ${NIX_PIDFILE}
+}
+
+# Restart nix:
+nix_restart() {
+ nix_stop
+ nix_start
+}
+
+case "$1" in
+'start')
+ nix_start
+ ;;
+'stop')
+ nix_stop
+ ;;
+'restart')
+ nix_restart
+ ;;
+'status')
+ if [ -f ${NIX_PIDFILE} ] && ps -o cmd $(cat ${NIX_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