summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd-systemctl/systemctl
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/systemd/systemd-systemctl/systemctl')
-rwxr-xr-xmeta/recipes-core/systemd/systemd-systemctl/systemctl127
1 files changed, 127 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
new file mode 100755
index 0000000000..f7866565b9
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -0,0 +1,127 @@
1#!/bin/sh
2echo "Started $0 $*"
3
4ROOT=
5
6# parse command line params
7action=
8while [ $# != 0 ]; do
9 opt="$1"
10
11 case "$opt" in
12 enable)
13 shift
14
15 action="$opt"
16 services="$1"
17 cmd_args="1"
18 shift
19 ;;
20 disable)
21 shift
22
23 action="$opt"
24 services="$1"
25 cmd_args="1"
26 shift
27 ;;
28 mask)
29 shift
30
31 action="$opt"
32 services="$1"
33 cmd_args="1"
34 shift
35 ;;
36 --root=*)
37 ROOT=${opt##--root=}
38 cmd_args="0"
39 shift
40 ;;
41 *)
42 if [ "$cmd_args" = "1" ]; then
43 services="$services $opt"
44 shift
45 else
46 echo "'$opt' is an unkown option; exiting with error"
47 exit 1
48 fi
49 ;;
50 esac
51done
52
53for service in $services; do
54 if [ "$action" = "mask" ]; then
55 if [ ! -d $ROOT/etc/systemd/system/ ]; then
56 mkdir -p $ROOT/etc/systemd/system/
57 fi
58 cmd="ln -s /dev/null $ROOT/etc/systemd/system/$service"
59 echo "$cmd"
60 $cmd
61 exit 0
62 fi
63
64 echo "Try to find location of $service..."
65 # find service file
66 for p in $ROOT/etc/systemd/system \
67 $ROOT/lib/systemd/system \
68 $ROOT/usr/lib/systemd/system; do
69 if [ -e $p/$service ]; then
70 service_file=$p/$service
71 service_file=${service_file##$ROOT}
72 fi
73 done
74 if [ -z "$service_file" ]; then
75 echo "'$service' couldn't be found; exiting with error"
76 exit 1
77 fi
78 echo "Found $service in $service_file"
79
80 # If any new unit types are added to systemd they should be added
81 # to this regular expression.
82 unit_types_re='\.\(service\|socket\|device\|mount\|automount\|swap\|target\|path\|timer\|snapshot\)$'
83
84 # create the required symbolic links
85 wanted_by=$(sed '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
86 | tr ',' '\n' \
87 | grep "$unit_types_re")
88
89 for r in $wanted_by; do
90 echo "WantedBy=$r found in $service"
91 if [ "$action" = "enable" ]; then
92 mkdir -p $ROOT/etc/systemd/system/$r.wants
93 ln -s $service_file $ROOT/etc/systemd/system/$r.wants
94 echo "Enabled $service for $wanted_by."
95 else
96 rm -f $ROOT/etc/systemd/system/$r.wants/$service
97 rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants
98 echo "Disabled $service for $wanted_by."
99 fi
100 done
101
102 # create the required symbolic 'Alias' links
103 alias=$(sed '/^Alias[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
104 | tr ',' '\n' \
105 | grep "$unit_types_re")
106
107 for r in $alias; do
108 if [ "$action" = "enable" ]; then
109 mkdir -p $ROOT/etc/systemd/system
110 ln -s $service_file $ROOT/etc/systemd/system/$r
111 echo "Enabled $service for $alias."
112 else
113 rm -f $ROOT/etc/systemd/system/$r
114 echo "Disabled $service for $alias."
115 fi
116 done
117
118 # call us for the other required scripts
119 also=$(sed '/^Also[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \
120 | tr ',' '\n')
121 for a in $also; do
122 echo "Also=$a found in $service"
123 if [ "$action" = "enable" ]; then
124 $0 --root=$ROOT enable $a
125 fi
126 done
127done