]> Pileus Git - mkinit/blob - services.mk
Add reload.
[mkinit] / services.mk
1 MKSHELL=/opt/plan9/bin/rc
2
3 # Example
4 test-start:VQPservice -u: foo-start
5         echo starting test
6         service -U $target
7
8 test-stop:VQPservice -d: /
9         echo stopping test
10         service -D $target
11
12 # Core commands
13 # -------------
14 # Reboot commands
15 poweroff:V: halt
16         $P poweroff -ndf
17 reboot:V: halt
18         $P reboot -ndf
19 kexec:V: halt
20         $P reboot -ndfk
21
22 # Initial setup/shutdown for mkinit
23 boot:VEPservice -u: /
24         echo Starting init
25         $P mount -o remount,rw /
26         $P mount -t tmpfs tmpfs /lib/mkinit/state
27         # mount proc here to make bootchart happier
28         $P mount -t proc proc /proc
29         service -U $target
30
31 # Kill all process, then remount and sync
32 halt:QVE: utmp-stop hwclock-stop alsa-stop
33         echo TERMinating all processes
34         $P pkill -15 --inverse -g0 >/dev/null >[2=1]
35         for (i in 1 2 3 4 5)
36                 { $P pgrep -vg0 && $P sleep 1 }
37         echo KILLing all processes
38         $P pkill  -9 --inverse -g0 >/dev/null >[2=1]
39         for (i in 1 2 3)
40                 { $P pgrep -vg0 && $P sleep 1 }
41         service -F
42         echo Remounting read-only
43         $P mount -o remount,ro /
44         $P sync
45
46 # Bare
47 # ----
48 # Listener for /dev/initctl, for shutdown(8)
49 initctl-start:VPservice -u: boot
50         fifo=/dev/initctl
51         if (! test -e $fifo)
52                 $P mkfifo $fifo
53         { exec $P initctld $fifo |
54           while(line=`{line})
55                 $P mkinit $line >/dev/console >[2=1]
56         } &
57         service -U $target
58 initctl-stop_cmd=fuser -k /dev/initctl
59
60 # Proc, mtab, fstab
61 mounts-start:VPservice -u: $devnodes-start
62         $P mdadm -A /dev/md2 /dev/sd[bcd]2 || true
63         $P ln -snf /proc/self/fd /dev/fd
64         $P mount -a
65         service -U $target
66
67 # Set console font
68 font-start_cmd=setfont
69
70 # Setup device nodes
71 devtmpfs-start:VEPservice -u: boot
72         $P mount /dev
73         $P mkdir /dev/shm
74         $P mkdir /dev/pts
75         service -U $target
76
77 devawk-start:VEPservice -u: devtmpfs-start
78         $P echo /root/bin/dev.awk > /proc/sys/kernel/hotplug
79         $P /root/bin/dev.awk
80         service -U $target
81
82 devsh-start:VEPservice -u: devtmpfs-start
83         $P echo /root/bin/dev.sh > /proc/sys/kernel/hotplug
84         $P /root/bin/dev.sh -a
85         service -U $target
86
87 mdev-start:VEPservice -u: devtmpfs-start
88         $P echo /sbin/mdev > /proc/sys/kernel/hotplug
89         $P mdev -s
90         service -U $target
91
92 udev-start:VEPservice -u:  mounts-start
93         $P udevd --daemon
94         $P udevadm trigger
95         $P udevadm settle '--timeout=10'
96         service -U $target
97 udev-stop_cmd=pkill udevd
98
99 # Load kernel modules
100 modules-start:VEPservice -u: mounts-start
101         for (i in `{find /sys/devices -name wakeup -not -path '*PWRBN*'})
102                 { $P echo disabled > $i }
103         service -U $target
104
105 # Intel graphics card
106 intel-start:VEPservice -u: mounts-start
107         $P modprobe i915    'modeset=1'
108         $P modprobe nouveau 'modeset=1'
109         $P echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
110         service -U $target
111
112 # Nvidia graphics card
113 nvidia-start:VEPservice -u: mounts-start
114         $P modprobe i915    'modeset=1'
115         $P modprobe nouveau 'modeset=1'
116         $P echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch
117         $P echo 0    > /sys/class/vtconsole/vtcon1/bind
118         $P modprobe -r nouveau
119         $P modprobe    nvidia
120         $P setpci -v -H1 -s '00:01.00' 'BRIDGE_CONTROL=0'
121         service -U $target
122
123 # Nouveau graphics card
124 nouveau-start:VEPservice -u: mounts-start
125         $P modprobe    i915    'modeset=1'
126         $P modprobe    nouveau 'modeset=1'
127         $P echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch
128         $P echo 0    > /sys/class/vtconsole/vtcon1/bind
129         $P modprobe -r nouveau
130         $P modprobe    nouveau 'modeset=1'
131         service -U $target
132
133 # Clean out /tmp and /var/run directories
134 fsclean-start:VPservice -u: boot
135         dirs=(/run /var/run /tmp)
136         $P mkdir -p /.old
137         $P mv $dirs /.old || true
138         $P mkdir -p $dirs
139         $P chmod 1777 /tmp
140         $P install -m 1777 -d /var/run/screen # Fuck you Screen
141         $P exec rm -rf /.old &
142         service -U $target
143
144 # Hardware keys
145 hwkeys-start:VEPservice -u: mounts-start
146         $P /root/bin/touchpad.sh
147         $P exec hwkeys &
148         service -U $target
149 hwkeys-stop_cmd=pkill hwkeys
150
151 # Spawn gettyd for tty[23456]
152 gettyd-start:VEPservice -u: hostname-start utmp-start
153         $P exec gettyd tty2 tty3 tty4 tty5 tty6 &
154         service -U $target
155 gettyd-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6
156
157 # Spawn agettys for tty[23456]
158 agetty-start:VEPservice -u: hostname-start utmp-start
159         $P respawn setsid agetty 38400 tty2 linux
160         $P respawn setsid agetty 38400 tty3 linux
161         $P respawn setsid agetty 38400 tty4 linux
162         $P respawn setsid agetty 38400 tty5 linux
163         $P respawn setsid agetty 38400 tty6 linux
164         service -U $target
165 agetty-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6
166
167 # Spawn qingys for tty[7]
168 qingy-start:VEPservice -u: hostname-start utmp-start modules-start $devnodes-start
169         $P /root/bin/touchpad.sh
170         $P exec setsid /sbin/qingy tty7 &
171         $P chvt 7
172         service -U $target
173 qingy-stop_cmd=fuser -k /dev/tty7
174
175 # Spawn xorg on tty[7]
176 xinit-start:VEPservice -u: mounts-start
177         $P /root/bin/gpu $graphics | tee /root/gpu.log
178         $P /root/bin/touchpad.sh
179         $p chown andy:tty /dev/tty7
180         $p rm -f /usr/libexec/xf86-video-intel-backlight-helper
181         $p exec su -l andy -c /home/andy/bin/xsession &
182         service -U $target
183 xinit-stop_cmd=fuser -k /dev/tty7
184
185 # Login records
186 utmp-start:VPservice -u: fsclean-start
187         for (i in /var/run/utmp /var/log/wtmp) {
188                 $P eval 'echo -n > $i'
189                 $P chgrp utmp $i
190                 $P chmod 0664 $i
191         }
192         service -U $target
193 utmp-stop_cmd=halt -w
194
195 # CPU freq
196 cpufreq-start:VPservice -u: mounts-start
197         $P cpupower frequency-set -g ondemand
198         service -U $target
199
200 # Localhost
201 localhost-start_cmd=ifconfig lo 127.0.0.1
202 localhost-stop_cmd=ifconfig lo down
203
204 # Set hostname
205 hostname-start_cmd=hostname
206
207 # Power management
208 power-start:VPservice -u: mounts-start
209         echo 1         | $P tee /sys/module/snd_hda_intel/parameters/power_save
210         echo min_power | $P tee /sys/class/scsi_host/*/link_power_management_policy
211         echo auto      | $P tee /sys/bus/usb/devices/*/power/control
212         echo auto      | $P tee /sys/bus/pci/devices/*/power/control
213         echo 1500      | $P tee /proc/sys/vm/dirty_writeback_centisecs
214         service -U $target
215
216 # Kernel parameters
217 sysctl-start:VPservice -u: mounts-start
218         $P sysctl -p
219         $P chmod a+w /sys/class/leds/smc::kbd_backlight/brightness
220         $P chmod a+w /sys/class/backlight/gmux_backlight/brightness
221         $P chmod a+w /sys/devices/platform/applesmc.768/fan[12]_manual
222         $P chmod a+w /sys/devices/platform/applesmc.768/fan[12]_output
223         service -U $target
224
225
226 # System
227 # -------
228 at-start:VPservice -u: fsclean-start
229         $P atd
230         service -U $target
231 at-stop_cmd=pkill atd
232
233 cron-start:VPservice -u: localhost-start fsclean-start
234         $P crond
235         service -U $target
236 cron-stop_cmd=pkill cron
237
238 hddtemp-start_cmd=hddtemp -d
239 hddtemp-stop_cmd=pkill hddtemp
240
241 hwclock-start_cmd=hwclock --hctosys --utc
242 hwclock-stop_cmd=hwclock --systohc --utc
243
244 mdadm-start_cmd=mdadm --monitor --scan --daemonize
245 mdadm-stop_cmd=pkill mdadm
246
247 smartd-start_cmd=smartd
248 smartd-stop_cmd=pkill smartd
249
250 sshd-start_cmd=/usr/sbin/sshd
251 sshd-stop_cmd=pkill sshd
252
253 swap-start_cmd=swapon -a
254 swap-stop_cmd=swapoff -a
255
256 syslog-start:VPservice -u: mounts-start
257         $P syslog-ng
258         service -U $target
259 syslog-stop_cmd=pkill syslog
260
261
262 # Desktop
263 # -------
264 alsa-start:VPservice -u: boot
265         $P modprobe snd-hda-intel
266         $P modprobe snd-usb-audio
267         $P sleep 0.1
268         $P alsactl restore
269         service -U $target
270 alsa-stop_cmd=alsactl store
271
272 bluez-start:VPservice -u: dbus-start
273         $P modprobe btusb
274         $P modprobe hidp
275         $P hciconfig hci0 up
276         $P exec /usr/libexec/bluetooth/bluetoothd &
277         service -U $target
278 bluez-stop_cmd=pkill bluetoothd
279
280 cups-start_cmd=cupsd
281 cups-stop_cmd=pkill cupsd
282
283 dbus-start:VPservice -u: fsclean-start localhost-start
284         $P install -m 1777 -d /var/run/dbus
285         $P /usr/bin/dbus-daemon --system
286         service -U $target
287 dbus-stop_cmd=pkill dbus-daemon
288
289 gpm-start_cmd=gpm -m /dev/input/mice -t ps2
290 gpm-stop_cmd=pkill gpm
291
292 gpsd-start_cmd=gpsd tcp://localhost:2222
293 gpsd-stop_cmd=pkill gpsd
294
295 keymap-start_cmd=loadkeys -u us-cc
296
297 polipo-start:VPservice -u: localhost-start
298         $P polipo
299         service -U $target
300 polipo-stop_cmd=pkill polipo
301
302
303 # Server
304 # ------
305 apache2-start:VPservice -u: fsclean-start
306         $P install -o apache -g apache -d /var/run/session
307         $P install -o apache -g apache -d /run/apache_ssl_mutex
308         $P apache2 $(apache2-opts)
309         service -U $target
310 apache2-stop_cmd=pkill apache2
311
312 bitlbee-start_cmd=bitlbee -D -u bitlbee
313 bitlbee-stop_cmd=pkill bitlbee
314
315 cups-start_cmd=cupsd
316 cups-stop_cmd=pkill cupsd
317
318 denyhosts-start_cmd=denyhosts.py --daemon
319 denyhosts-stop_cmd=pkill denyhosts.py
320
321 courier-start:VPservice -u: fsclean-start
322         $P install -o mail -g mail -d /var/run/courier
323         $P authdaemond       start
324         $P courier           start
325         $P courierfilter     start
326         $P courier-imapd-ssl start
327         service -U $target
328 courier-stop_cmd=pkill '(courier|authdaemon)'
329
330 dioc-start:VPservice -u: munged-start
331         $P mount -n /mnt/c
332         $P mount -n /mnt/c/mnt/x
333         service -U $target
334 dioc-stop:EVPservice -d:
335         $P umount /mnt/c/mnt/x
336         $P umount /mnt/c
337         service -D $target
338
339 diod-start:VPservice -u: munged-start
340         $P diod --export-all
341         service -U $target
342 diod-stop_cmd=pkill diod
343
344 docker-start_cmd=docker
345 docker-stop_cmd=pkill docker
346
347 dovecot-start_cmd=dovecot
348 dovecot-stop_cmd=pkill dovecot
349
350 eth0-start_cmd=dhcpcd eth0 -4 -A
351 eth0-stop_cmd=dhcpcd eth0 -k
352
353 exim-start_cmd=exim -bd -q5m
354 exim-stop_cmd=pkill exim
355
356 fail2ban-start:VPservice -u: boot
357         $P mkdir -p /run/fail2ban
358         $P fail2ban-client start
359         service -U $target
360 fail2ban-stop_cmd=fail2ban-client stop
361
362 gitd-start_cmd=git daemon \
363         '--detach' \
364         '--syslog' \
365         '--export-all' \
366         '--user-path=git' \
367         '--interpolated-path=/etc/git/%H%D' \
368         '--listen=0.0.0.0' \
369         '--user=nobody' \
370         '--group=nobody'
371 gitd-stop_cmd=pkill git-daemon
372
373 iptables-start:VPservice -u: boot
374         $P iptables-restore < /var/lib/iptables/rules-save
375         service -U $target
376 iptables-stop:EVPservice -d:
377         $P iptables-save > /var/lib/iptables/rules-save
378         service -D $target
379
380 jabberd-start_cmd=sudo -u jabber -g jabber jabberd-andy -b
381 jabberd-stop_cmd=pkill --uid jabber
382
383 mailman-start_cmd=sudo -u mailman -g mailman \
384         /usr/lib64/mailman/bin/mailmanctl -s start
385 mailman-stop_cmd=sudo -u mailman -g mailman \
386         /usr/lib64/mailman/bin/mailmanctl stop
387
388 minidlna-start:VPservice -u: mounts-start
389         $P install -o minidlna -g minidlna -d /var/run/minidlna
390         $P install -o minidlna -g minidlna -d /var/cache/minidlna
391         $P sudo    -u minidlna -g minidlna minidlnad
392         service -U $target
393 minidlna-stop_cmd=pkill minidlnad
394
395 munged-start:VPservice -u: localhost-start mounts-start
396         $P install -o munge -g munge -d /var/run/munge
397         $P sudo -u munge -g munge munged
398         service -U $target
399 munged-stop_cmd=pkill munged
400
401 mysql-start:VPservice -u: fsclean-start
402         $P install -o mysql -g mysql -d /var/run/mysqld
403         $P exec mysqld &
404         service -U $target
405 mysql-stop_cmd=pkill mysqld
406
407 ntpd-start_cmd=ntpd
408 ntpd-stop_cmd=pkill ntpd
409
410 privoxy-start_cmd=privoxy --user privoxy.privoxy /etc/privoxy/config
411 privoxy-stop_cmd=pkill privoxy
412
413 rngd-start_cmd=rngd -b -s64 -W2048
414 rngd-stop_cmd=pkill rngd
415
416 sasl-start_cmd=saslauthd -n0 -ashadow
417 sasl-stop_cmd=pkill saslauthd
418
419 spamd-start_cmd=spamd -u spamd -d
420 spamd-stop_cmd=pkill spamd
421
422 tftpd-start_cmd=in.tftpd -s -l /img/boot
423 tftpd-stop_cmd=
424
425 tor-start:VPservice -u: boot
426         $P exec tor &
427         service -U $target
428 tor-stop_cmd=pkill tor
429
430 unifi-start:VPservice -u: wpa-start
431         cd /usr/lib/unifi
432         exec java -jar lib/ace.jar start &
433 unifi-stop:EVPservice -d:
434         cd /usr/lib/unifi
435         java -jar lib/ace.jar stop
436         service -D $target
437
438 ventrilo-opts=-f/opt/ventrilo-server/ventrilo_srv -d
439 ventrilo-start_cmd=sudo -u ventrilo -g ventrilo /opt/ventrilo-server/ventrilo_srv
440 ventrilo-stop_cmd=pkill -u ventrilo
441
442 vpn-start:VPservice -u: localhost-start
443         $P ipsec start
444         $P exec /usr/sbin/rp-l2tpd &
445         $P exec /usr/sbin/pptpd &
446         service -U $target
447 vpn-stop:VQPservice -d: /
448         $P pkill rp-l2tpd
449         $P pkill pptpd
450         $P ipsec stop
451         service -D $target
452
453 wlan0-start:VPservice -u: wpa-start
454         $P dhcpcd -4 wlan0
455         service -U $target
456 wlan0-stop_cmd=dhcpcd wlan0 -k
457
458 wpa-start:VPservice -u: $devnodes-start
459         $P modprobe brcmfmac && sleep 1
460         $P exec wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf &
461         service -U $target
462 wpa-stop_cmd=pkill wpa
463
464 # Library
465 # -------
466 %-start:QVPservice -u: boot
467         if (~ $#($stem^-start_cmd) 0)
468                 echo No such service $stem && exit 0
469         $P $($stem^-start_cmd) $($stem^-opts)
470         service -U $target
471
472 %-stop:QVPservice -d: /
473         if (~ $#($stem^-stop_cmd) 0)
474                 echo No such service $stem
475         if not
476                 $P $($stem^-stop_cmd)
477         service -D $target
478
479 %-zap:QVPservice -d: /
480         service -D $target
481
482 %-status:QV:
483         service -q $target