summaryrefslogtreecommitdiff
path: root/arch-daemons
blob: ffe428901aa65f6d440864f4810a473d760d299f (plain)
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
#!/bin/bash
#
# /usr/lib/systemd/system-generators/arch-daemons
#

. /etc/rc.conf

[[ $1 ]] || exit 1

# when called at boot, this is /run/systemd/generator.late
dest=$3

# list of services that have to be started before the next one
deps=()

# Check if $1 is a valid daemon name
have_daemon() {
  [[ -f /etc/rc.d/$1 && -x /etc/rc.d/$1 ]]
}

# Make service file
create_unit() {
  local deps= daemon=${1%.service}

  if ! have_daemon $daemon; then
    return
  fi

  (( $# > 1 )) && printf -v deps 'After=%s\n' "${*:2}"

  printf \
'[Unit]
SourcePath=/etc/rc.conf
Documentation=https://raw.github.com/falconindy/initscripts-systemd/master/README
Description=Legacy unit for %s
%s
[Service]
ExecStart=/etc/rc.d/%s start
ExecStop=/etc/rc.d/%s stop
RemainAfterExit=yes
Type=forking
' "$daemon" "$deps" "$daemon" "$daemon" > "$dest/$1"

}

for daemon in /etc/rc.d/*; do
  create_unit "${daemon##*/}".service
done

[[ -d $dest/multi-user.target.wants ]] || /bin/mkdir -p "$dest/multi-user.target.wants"

for daemon in "${DAEMONS[@]}"; do
  service="$daemon.service"
  case ${daemon:0:1} in
    '!') continue ;;
    '@') create_unit "${service:1}" "${deps[@]}"
         ln -s "../${service:1}" "$dest/multi-user.target.wants"
        ;;
    *) create_unit "$service" "${deps[@]}"
       deps+=("$service")
       ln -s "../$service" "$dest/multi-user.target.wants"
      ;;
   esac
done

# vim: et sw=2: