summaryrefslogtreecommitdiff
path: root/system/s6/s6-svscanboot
blob: 8fa8ec5d571d9feaf2de840b0c033f5efc6cd114 (plain) (blame)
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
#!/bin/execlineb -P

# Basic sanity.

export PATH /usr/bin:/usr/sbin:/bin:/sbin
umask 022


# The live service directories are in /run/services
# The scandir is /run/service, containing only the catch-all logger and symlinks
# (and the s6-svscan configuration in /run/service/.s6-svscan)

if { rm -rf /run/service /run/services }
if { mkdir -p -m 0755 /run/service/.s6-svscan /run/service/s6-svscan-log }
if { ln -sf /bin/false /run/service/.s6-svscan/crash }
if
{
  redirfd -w 1 /run/service/.s6-svscan/finish
  heredoc 0 "#!/bin/execlineb -P\ns6-svc -X -- \"/run/service/s6-svscan-log\"\n"
  cat
}
if { chmod 0755 /run/service/.s6-svscan/finish }


# Directory for the catch-all logger to store its logs

if { mkdir -p -m 2700 /run/uncaught-logs }
if { chown catchlog:catchlog /run/uncaught-logs }
if { chmod 2700 /run/uncaught-logs }


# Copy all the early services and link them into the scandir

if { /bin/cp -a /etc/s6/early-services /run/services }
if
{
  forbacktickx -pnd"\n" i { ls -1 -U /run/services }
    importas -u i i
    ln -nsf ../services/$i /run/service/$i
}


# Also link the early services defined in sysinit, if any

if
{
  if -t { test -d /run/early-services }
  forbacktickx -pnd"\n" i { ls -1 -U /run/early-services }
    importas -u i i
    ln -nsf ../early-services/$i /run/service/$i
}


# Create the catch-all logger servicedir directly in the scandir
# (It's too fundamental to be made configurable as an early service.)

if { rm -f /run/service/s6-svscan-log/fifo }
if { mkfifo -m 0600 /run/service/s6-svscan-log/fifo }
if
{
  redirfd -w 1 /run/service/s6-svscan-log/run
  heredoc 0 "#!/bin/execlineb -P
redirfd -w 2 /dev/console
redirfd -rnb 0 fifo
s6-setuidgid catchlog
exec -c
s6-log t /run/uncaught-logs\n"
  cat
}
if { chmod 0755 /run/service/s6-svscan-log/run }


# All ready, exec into s6-svscan.
# By default all messages from all services will go to the catch-all logger it spawns.

redirfd -r 0 /dev/null
redirfd -wnb 1 /run/service/s6-svscan-log/fifo
fdmove -c 2 1
s6-svscan -St0 /run/service