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/systemctl126
1 files changed, 126 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..d71c7eda8b
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -0,0 +1,126 @@
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 # create the required symbolic links
81 wanted_by=$(grep WantedBy $ROOT/$service_file \
82 | sed 's,WantedBy=,,g' \
83 | tr ',' '\n' \
84 | grep '\(\.target$\)\|\(\.service$\)')
85
86 for r in $wanted_by; do
87 echo "WantedBy=$r found in $service"
88 if [ "$action" = "enable" ]; then
89 mkdir -p $ROOT/etc/systemd/system/$r.wants
90 ln -s $service_file $ROOT/etc/systemd/system/$r.wants
91 echo "Enabled $service for $wanted_by."
92 else
93 rm -f $ROOT/etc/systemd/system/$r.wants/$service
94 rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants
95 echo "Disabled $service for $wanted_by."
96 fi
97 done
98
99 # create the required symbolic 'Alias' links
100 alias=$(grep Alias $ROOT/$service_file \
101 | sed 's,Alias=,,g' \
102 | tr ',' '\n' \
103 | grep '\.service$')
104
105 for r in $alias; do
106 if [ "$action" = "enable" ]; then
107 mkdir -p $ROOT/etc/systemd/system
108 ln -s $service_file $ROOT/etc/systemd/system/$r
109 echo "Enabled $service for $alias."
110 else
111 rm -f $ROOT/etc/systemd/system/$r
112 echo "Disabled $service for $alias."
113 fi
114 done
115
116 # call us for the other required scripts
117 also=$(grep Also $ROOT/$service_file \
118 | sed 's,Also=,,g' \
119 | tr ',' '\n')
120 for a in $also; do
121 echo "Also=$a found in $service"
122 if [ "$action" = "enable" ]; then
123 $0 --root=$ROOT enable $a
124 fi
125 done
126done