forked from b-it-bots/automatic-startup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_services.bash
executable file
·49 lines (45 loc) · 1.65 KB
/
manage_services.bash
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
#!/bin/bash
allowed_platforms=("freddy","qtrobot")
allowed_cmds=("enable","restart","disable")
platform=$1
cmd=$2
if [[ -z "$platform" ]] || [[ ${allowed_platforms[*]} != $platform ]]; then
echo "Manages all service files for a specified platform"
echo "Usage: ./manage_services.bash [platform] [cmd]"
echo " where the allowed values for platform are [$allowed_platforms]"
echo " and the allowed values for cmd are [$allowed_cmds]"
exit 1
else
if [ $cmd == "enable" ]; then
echo 'Copying service files to /etc/systemd/system...';
sudo cp $platform/* /etc/systemd/system/
echo 'Service files copied successfully';
echo 'Enabling services...';
service_files=$(ls $platform);
for service in $service_files; do
echo 'Enabling' $service;
sudo systemctl enable $service
done
echo 'Services enabled successfully';
elif [ $cmd == "restart" ]; then
echo 'Restarting services...';
service_files=$(ls $platform);
for service in $service_files; do
echo 'Restarting' $service;
sudo systemctl restart $service
done
echo 'All services have been restarted';
elif [ $cmd == "disable" ]; then
echo 'Disabling services...';
service_files=$(ls $platform);
for service in $service_files; do
echo 'Disabling' $service;
sudo systemctl disable $service
echo 'Removing' $service 'from /etc/systemd/system';
sudo rm /etc/systemd/system/$service
done
echo 'Services disabled';
else
echo "Unknown command $cmd"
fi
fi