Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7ca50efb
Commit
7ca50efb
authored
May 01, 2019
by
Erik Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add k3s-killall.sh script to installer
parent
0726ce75
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
24 deletions
+78
-24
install.sh
install.sh
+78
-24
No files found.
install.sh
View file @
7ca50efb
...
@@ -125,6 +125,13 @@ setup_env() {
...
@@ -125,6 +125,13 @@ setup_env() {
fi
fi
SERVICE_K3S
=
${
SYSTEM_NAME
}
.service
SERVICE_K3S
=
${
SYSTEM_NAME
}
.service
UNINSTALL_K3S_SH
=
${
SYSTEM_NAME
}
-uninstall
.sh
UNINSTALL_K3S_SH
=
${
SYSTEM_NAME
}
-uninstall
.sh
KILLALL_K3S_SH
=
k3s-killall.sh
# --- use sudo if we are not already root ---
SUDO
=
sudo
if
[
`
id
-u
`
=
0
]
;
then
SUDO
=
fi
# --- use systemd type if defined or create default ---
# --- use systemd type if defined or create default ---
if
[
-n
"
${
INSTALL_K3S_TYPE
}
"
]
;
then
if
[
-n
"
${
INSTALL_K3S_TYPE
}
"
]
;
then
...
@@ -161,13 +168,10 @@ setup_env() {
...
@@ -161,13 +168,10 @@ setup_env() {
FILE_K3S_ENV
=
/etc/rancher/k3s/
${
SYSTEM_NAME
}
.env
FILE_K3S_ENV
=
/etc/rancher/k3s/
${
SYSTEM_NAME
}
.env
fi
fi
# --- use sudo if we are not already root ---
# --- get hash of config & exec for currently installed k3s ---
SUDO
=
sudo
if
[
`
id
-u
`
=
0
]
;
then
SUDO
=
fi
PRE_INSTALL_HASHES
=
`
get_installed_hashes
`
PRE_INSTALL_HASHES
=
`
get_installed_hashes
`
# --- if bin directory is read only skip download ---
if
[
"
${
INSTALL_K3S_BIN_DIR_READ_ONLY
}
"
=
"true"
]
;
then
if
[
"
${
INSTALL_K3S_BIN_DIR_READ_ONLY
}
"
=
"true"
]
;
then
INSTALL_K3S_SKIP_DOWNLOAD
=
true
INSTALL_K3S_SKIP_DOWNLOAD
=
true
fi
fi
...
@@ -342,6 +346,63 @@ create_symlinks() {
...
@@ -342,6 +346,63 @@ create_symlinks() {
fi
fi
}
}
# --- create killall script ---
create_killall
()
{
[
"
${
INSTALL_K3S_BIN_DIR_READ_ONLY
}
"
=
"true"
]
&&
return
info
"Creating killall script
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
"
$SUDO
tee
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
>
/dev/null
<<
\
EOF
#!/bin/sh
set -x
[ `id -u` = 0 ] || exec sudo
$0
$@
for bin in /var/lib/rancher/k3s/data/**/bin/; do
[ -d
$bin
] && export PATH=
$bin
:
$PATH
done
for service in /etc/systemd/system/k3s*.service; do
[ -s
$service
] && systemctl stop
$(
basename
$service
)
done
for service in /etc/init.d/k3s*; do
[ -x
$service
] &&
$service
stop
done
pstree() {
for pid in
$@
; do
echo
$pid
pstree
$(
ps
-o
ppid
=
-o
pid
=
|
awk
"
\$
1==
$pid
{print
\$
2}"
)
done
}
killtree() {
[
$#
-ne 0 ] && kill
$(
set
+x
;
pstree
$@
;
set
-x
)
}
killtree
$(
lsof |
sed
-e
's/^[^0-9]*//g; s/ */\t/g'
|
grep
-w
'k3s/data/[^/]*/bin/containerd-shim'
|
cut
-f1
|
sort
-n
-u
)
do_unmount() {
MOUNTS=`cat /proc/self/mounts | awk '{print
$2
}' | grep "^
$1
" | sort -r`
if [ -n "
${
MOUNTS
}
" ]; then
umount
${
MOUNTS
}
fi
}
do_unmount '/run/k3s'
do_unmount '/var/lib/rancher/k3s'
nets=
$(
ip
link
show |
grep
'master cni0'
|
awk
-F
': '
'{print $2}'
|
sed
-e
's|@.*||'
)
for iface in
$nets
; do
ip link delete
$iface
;
done
ip link delete cni0
ip link delete flannel.1
rm -rf /var/lib/cni/
EOF
$SUDO
chmod
755
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
$SUDO
chown
root:root
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
}
# --- create uninstall script ---
# --- create uninstall script ---
create_uninstall
()
{
create_uninstall
()
{
[
"
${
INSTALL_K3S_BIN_DIR_READ_ONLY
}
"
=
"true"
]
&&
return
[
"
${
INSTALL_K3S_BIN_DIR_READ_ONLY
}
"
=
"true"
]
&&
return
...
@@ -349,12 +410,19 @@ create_uninstall() {
...
@@ -349,12 +410,19 @@ create_uninstall() {
$SUDO
tee
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
>
/dev/null
<<
EOF
$SUDO
tee
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
>
/dev/null
<<
EOF
#!/bin/sh
#!/bin/sh
set -x
set -x
[ \`id -u\` = 0 ] || exec sudo \
$0
\
$@
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
if which systemctl; then
if which systemctl; then
systemctl kill
${
SYSTEM_NAME
}
systemctl disable
${
SYSTEM_NAME
}
systemctl disable
${
SYSTEM_NAME
}
systemctl reset-failed
${
SYSTEM_NAME
}
systemctl reset-failed
${
SYSTEM_NAME
}
systemctl daemon-reload
systemctl daemon-reload
fi
fi
if which rc-update; then
rc-update delete
${
SYSTEM_NAME
}
default
fi
rm -f
${
FILE_K3S_SERVICE
}
rm -f
${
FILE_K3S_SERVICE
}
rm -f
${
FILE_K3S_ENV
}
rm -f
${
FILE_K3S_ENV
}
...
@@ -368,22 +436,6 @@ if (ls ${SYSTEMD_DIR}/k3s*.service || ls /etc/init.d/k3s*) >/dev/null 2>&1; then
...
@@ -368,22 +436,6 @@ if (ls ${SYSTEMD_DIR}/k3s*.service || ls /etc/init.d/k3s*) >/dev/null 2>&1; then
exit
exit
fi
fi
do_unmount() {
MOUNTS=\`cat /proc/self/mounts | awk '{print \
$2
}' | grep "^\
$1
"\`
if [ -n "\
${
MOUNTS
}
" ]; then
umount \
${
MOUNTS
}
fi
}
do_unmount '/run/k3s'
do_unmount '/var/lib/rancher/k3s'
nets=\
$(
ip
link
show master cni0 |
grep
cni0 |
awk
-F
': '
'{print \$2}'
|
sed
-e
's|@.*||'
)
for iface in \
$nets
; do
ip link delete \
$iface
;
done
ip link delete cni0
ip link delete flannel.1
if [ -L
${
BIN_DIR
}
/kubectl ]; then
if [ -L
${
BIN_DIR
}
/kubectl ]; then
rm -f
${
BIN_DIR
}
/kubectl
rm -f
${
BIN_DIR
}
/kubectl
fi
fi
...
@@ -394,6 +446,7 @@ fi
...
@@ -394,6 +446,7 @@ fi
rm -rf /etc/rancher/k3s
rm -rf /etc/rancher/k3s
rm -rf /var/lib/rancher/k3s
rm -rf /var/lib/rancher/k3s
rm -f
${
BIN_DIR
}
/k3s
rm -f
${
BIN_DIR
}
/k3s
rm -f
${
BIN_DIR
}
/
${
KILLALL_K3S_SH
}
EOF
EOF
$SUDO
chmod
755
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
$SUDO
chmod
755
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
$SUDO
chown
root:root
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
$SUDO
chown
root:root
${
BIN_DIR
}
/
${
UNINSTALL_K3S_SH
}
...
@@ -492,7 +545,7 @@ create_service_file() {
...
@@ -492,7 +545,7 @@ create_service_file() {
# --- get hashes of the current k3s bin and service files
# --- get hashes of the current k3s bin and service files
get_installed_hashes
()
{
get_installed_hashes
()
{
sha256sum
${
BIN_DIR
}
/k3s
${
FILE_K3S_SERVICE
}
${
FILE_K3S_ENV
}
2>&1
||
true
$SUDO
sha256sum
${
BIN_DIR
}
/k3s
${
FILE_K3S_SERVICE
}
${
FILE_K3S_ENV
}
2>&1
||
true
}
}
# --- enable and start systemd service ---
# --- enable and start systemd service ---
...
@@ -542,6 +595,7 @@ service_enable_and_start() {
...
@@ -542,6 +595,7 @@ service_enable_and_start() {
setup_env
${
INSTALL_K3S_EXEC
}
$@
setup_env
${
INSTALL_K3S_EXEC
}
$@
download_and_verify
download_and_verify
create_symlinks
create_symlinks
create_killall
create_uninstall
create_uninstall
systemd_disable
systemd_disable
create_env_file
create_env_file
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment