-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.nix
64 lines (54 loc) · 1.69 KB
/
service.nix
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
{ pkgs, ... }:
{ name ? "supervised-program"
, command ? let script = pkgs.writeScript "${name}" ''
#!/usr/bin/env bash
echo hello
sleep 10
echo bye
''; in "${script}"
, state-dir ? "/var/tmp/${name}"
}:
with pkgs.lib;
let inherit (pkgs.pythonPackages) supervisor; in
rec {
config = pkgs.writeText "supervisord.conf" ''
[supervisord]
pidfile=${state-dir}/run/supervisord.pid
childlogdir=${state-dir}/log/
logfile=${state-dir}/log/supervisord.log
[supervisorctl]
serverurl = unix:///${state-dir}/run/supervisord.sock
[unix_http_server]
file = ${state-dir}/run/supervisord.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:${name}]
command=${command}
directory=${state-dir}
redirect_stderr=true
startsecs=1
stopsignal=TERM
stopasgroup=true
'';
supervisord-wrapper = pkgs.writeScript "supervisord-wrapper" ''
#!${pkgs.bash}/bin/bash
extraFlags=""
export STATEDIR=${state-dir}
mkdir -p "$STATEDIR"/{run,log}
export PATH="${pkgs.coreutils}/bin"
${supervisor}/bin/supervisord -c ${config} -j $STATEDIR/run/supervisord.pid -d $STATEDIR -q $STATEDIR/log/ -l $STATEDIR/log/supervisord.log $@
'';
supervisorctl-wrapper = pkgs.writeScript "supervisorctl-wrapper" ''
#!${pkgs.bash}/bin/bash
${supervisor}/bin/supervisorctl -c ${config} $@
'';
supervisor-env = pkgs.stdenv.mkDerivation {
name = "${name}-main";
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/bin/
ln -sf ${supervisord-wrapper} $out/bin/supervisord
ln -sf ${supervisorctl-wrapper} $out/bin/supervisorctl
'';
};
}