-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsystemd_utils.sh
More file actions
107 lines (101 loc) · 1.77 KB
/
Copy pathsystemd_utils.sh
File metadata and controls
107 lines (101 loc) · 1.77 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
source "${SCRIPT_DIR}/lib/bashlib.sh"
source "${SCRIPT_DIR}/lib/cli.sh"
systemd.locate() {
local showhelp=0
while (($#)); do
case "$1" in
--help | -h)
showhelp=1
shift
;;
*) break ;;
esac
done
((showhelp)) && {
cat <<-EOF
Usage: ${FUNCNAME[0]} UNIT
Show location of a systemd unit file.
EOF
return 0
}
[[ -z "${1:-}" ]] && {
echo "Error: unit name required" >&2
return 1
}
systemctl cat "$1" 2>/dev/null | head -1
}
systemd.ls.enabled() {
local showhelp=0
while (($#)); do
case "$1" in
--help | -h)
showhelp=1
shift
;;
*) break ;;
esac
done
((showhelp)) && {
cat <<-EOF
Usage: ${FUNCNAME[0]}
List enabled systemd units.
EOF
return 0
}
systemctl list-unit-files --state=enabled
}
systemd.ls.active() {
local showhelp=0
while (($#)); do
case "$1" in
--help | -h)
showhelp=1
shift
;;
*) break ;;
esac
done
((showhelp)) && {
cat <<-EOF
Usage: ${FUNCNAME[0]}
List active systemd units.
EOF
return 0
}
systemctl list-units --state=active
}
systemd.log() {
local showhelp=0 lines=50
while (($#)); do
case "$1" in
--help | -h)
showhelp=1
shift
;;
-n)
lines="$2"
shift 2
;;
*) break ;;
esac
done
((showhelp)) && {
cat <<-EOF
Usage: ${FUNCNAME[0]} [-n LINES] UNIT
Show recent journal logs for a unit.
EOF
return 0
}
[[ -z "${1:-}" ]] && {
echo "Error: unit name required" >&2
return 1
}
journalctl -u "$1" -n "$lines" --no-pager
}
export -f systemd.locate systemd.ls.enabled systemd.ls.active systemd.log
register_simple_completion "systemd.locate"
register_simple_completion "systemd.ls.enabled"
register_simple_completion "systemd.ls.active"
register_simple_completion "systemd.log" "-n"