1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.services.torque.server;
9 torque = pkgs.torque;
10in
11{
12 options = {
13
14 services.torque.server = {
15
16 enable = lib.mkEnableOption "torque server";
17
18 };
19
20 };
21
22 config = lib.mkIf cfg.enable {
23 environment.systemPackages = [ pkgs.torque ];
24
25 systemd.services.torque-server-init = {
26 path = with pkgs; [
27 torque
28 util-linux
29 procps
30 inetutils
31 ];
32
33 script = ''
34 tmpsetup=$(mktemp -t torque-XXXX)
35 cp -p ${torque}/bin/torque.setup $tmpsetup
36 sed -i $tmpsetup -e 's/pbs_server -t create/pbs_server -f -t create/'
37
38 pbs_mkdirs -v aux
39 pbs_mkdirs -v server
40 hostname > /var/spool/torque/server_name
41 cp -prv ${torque}/var/spool/torque/* /var/spool/torque/
42 $tmpsetup root
43
44 sleep 1
45 rm -f $tmpsetup
46 kill $(pgrep pbs_server) 2>/dev/null
47 kill $(pgrep trqauthd) 2>/dev/null
48 '';
49
50 serviceConfig = {
51 Type = "oneshot";
52 RemainAfterExit = true;
53 };
54
55 unitConfig = {
56 ConditionPathExists = "!/var/spool/torque";
57 };
58 };
59
60 systemd.services.trqauthd = {
61 path = [ torque ];
62
63 requires = [ "torque-server-init.service" ];
64 after = [ "torque-server-init.service" ];
65
66 serviceConfig = {
67 Type = "forking";
68 ExecStart = "${torque}/bin/trqauthd";
69 };
70 };
71
72 systemd.services.torque-server = {
73 documentation = [ "man:pbs_server(8)" ];
74 path = [ torque ];
75
76 wantedBy = [ "multi-user.target" ];
77 wants = [
78 "torque-scheduler.service"
79 "trqauthd.service"
80 ];
81 before = [ "trqauthd.service" ];
82 requires = [ "torque-server-init.service" ];
83 after = [
84 "torque-server-init.service"
85 "network.target"
86 ];
87
88 serviceConfig = {
89 Type = "forking";
90 ExecStart = "${torque}/bin/pbs_server";
91 ExecStop = "${torque}/bin/qterm";
92 PIDFile = "/var/spool/torque/server_priv/server.lock";
93 };
94 };
95
96 systemd.services.torque-scheduler = {
97 documentation = [ "man:pbs_sched(8)" ];
98 path = [ torque ];
99
100 requires = [ "torque-server-init.service" ];
101 after = [ "torque-server-init.service" ];
102
103 serviceConfig = {
104 Type = "forking";
105 ExecStart = "${torque}/bin/pbs_sched";
106 PIDFile = "/var/spool/torque/sched_priv/sched.lock";
107 };
108 };
109
110 };
111}