Merge branch 'feature/KASM-3747-optional-systemd-start' into 'master'

Resolve KASM-3747 "Feature/ optional systemd start"

Closes KASM-3747

See merge request kasm-technologies/internal/KasmVNC!164
This commit is contained in:
Matthew McClaskey 2025-11-03 15:40:02 +00:00
commit 2066c1d739
10 changed files with 213 additions and 13 deletions

View file

@ -46,6 +46,7 @@ sudo dnf localinstall ./kasmvncserver_*.rpm
sudo usermod -a -G kasmvnc-cert $USER
```
## Getting Started
The following examples provide basic usage of KasmVNC with the tools provided. For full documentation on all the utilities and the runtime environment, see our [KasmVNC Documentation](https://www.kasmweb.com/kasmvnc/docs/latest/index.html)
@ -70,6 +71,21 @@ vncserver -list
vncserver -kill :2
```
### Optional systemd auto-start on boot
```sh
# Optionally use systemd to start KasmVNC on boot.
sudo reboot # Needed for systemd to pick up $USER's ssl-cert or kasmvnc-cert group
systemctl --user enable kasmvncserver@:1 # :1 is Xorg DISPLAY number.
systemctl --user start kasmvncserver@:1
# You can run multiple KasmVNC instances via systemd by passing a different
# DISPLAY number:
# systemctl --user enable kasmvncserver@:2
# systemctl --user start kasmvncserver@:2
# systemctl --user enable kasmvncserver@:3
# systemctl --user start kasmvncserver@:3
```
## Configuration
KasmVNC is configured via YAML based configurations. The server level configuration is at `/etc/kasmvnc/kasmvnc.yaml`. Edits to this file apply to all users. Individual users can override server global configurations by specifying them in their configuration file at `~/.vnc/kasmvnc.yaml`.

View file

@ -21,6 +21,7 @@ install: unpack_tarball
cp $(SRC_BIN)/kasmvncpasswd $(DESTDIR)/usr/bin/
cp $(SRC_BIN)/kasmxproxy $(DESTDIR)/usr/bin/
cp -r $(SRC)/lib/kasmvnc/ $(DESTDIR)/usr/lib/kasmvncserver
cp -r $(SRC)/lib/systemd/ $(DESTDIR)/usr/lib/
cp -r $(SRC)/share/doc/kasmvnc*/* $(DESTDIR)/usr/share/doc/kasmvncserver/
rsync -r --links --safe-links --exclude '.git*' --exclude po2js \
--exclude xgettext-html --exclude www/utils/ --exclude .eslintrc \

1
debian/control vendored
View file

@ -15,6 +15,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, ssl-cert, xauth,
x11-xkb-utils, xkb-data, procps, libswitch-perl, libyaml-tiny-perl,
libhash-merge-simple-perl, libscalar-list-utils-perl, liblist-moreutils-perl,
libtry-tiny-perl, libdatetime-perl, libdatetime-timezone-perl, libgbm1
Suggests: systemd
Provides: vnc-server
Description: KasmVNC provides remote web-based access to a Desktop or application.
While VNC is in the name, KasmVNC differs from other VNC variants such

51
debian/prerm vendored
View file

@ -16,20 +16,55 @@ set -e
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package
stop_vncserver_systemd_services_for_all_logged_in_users() {
for session in $(list_user_sessions); do
stop_user_services "$session"
done
}
list_user_sessions() {
loginctl list-sessions --no-legend | awk '{print $1}'
}
stop_user_services() {
local session="$1"
for service in $(list_active_services); do
systemctl --user --machine=$(systemd_user_from_session "$session") stop "$service" || true
done
}
systemd_user_from_session() {
local session="$1"
echo $(loginctl show-session "$session" -p Name --value)@
}
list_active_services() {
systemctl --user --machine=$(systemd_user_from_session "$session") \
list-units --type=service --state=active --plain --no-legend | \
awk '{ print $1 }' | grep kasmvncserver
}
remove_vncserver_and_other_alternatives_from_bin() {
bindir=/usr/bin
mandir=/usr/share/man
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc kasmxproxy"
for kasm_command in $commands; do
generic_command=`echo "$kasm_command" | sed -e 's/kasm//'`;
update-alternatives --remove "$generic_command" "$bindir/$kasm_command"
done
}
case "$1" in
remove)
bindir=/usr/bin
mandir=/usr/share/man
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc kasmxproxy"
for kasm_command in $commands; do
generic_command=`echo "$kasm_command" | sed -e 's/kasm//'`;
update-alternatives --remove "$generic_command" "$bindir/$kasm_command"
done
stop_vncserver_systemd_services_for_all_logged_in_users || true
remove_vncserver_and_other_alternatives_from_bin
;;
remove|upgrade|deconfigure)
stop_vncserver_systemd_services_for_all_logged_in_users || true
;;
failed-upgrade)

View file

@ -50,6 +50,7 @@ cp $SRC_BIN/vncconfig $DESTDIR/usr/bin;
cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin;
cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin;
cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver
cp -r $SRC/lib/systemd/ $DESTDIR/usr/lib/
cd $DESTDIR/usr/bin && ln -s kasmvncpasswd vncpasswd;
cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/
rsync -r --links --safe-links --exclude '.git*' --exclude po2js --exclude xgettext-html \
@ -69,12 +70,45 @@ cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN;
cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN;
cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
%preun
stop_vncserver_systemd_services_for_all_logged_in_users() {
for session in $(list_user_sessions); do
stop_user_services "$session"
done
}
list_user_sessions() {
loginctl list-sessions --no-legend | awk '{print $1}'
}
stop_user_services() {
local session="$1"
for service in $(list_active_services); do
systemctl --user --machine=$(systemd_user_from_session "$session") stop "$service" || true
done
}
systemd_user_from_session() {
local session="$1"
echo $(loginctl show-session "$session" -p Name --value)@
}
list_active_services() {
systemctl --user --machine=$(systemd_user_from_session "$session") \
list-units --type=service --state=active --plain --no-legend | \
awk '{ print $1 }' | grep kasmvncserver
}
stop_vncserver_systemd_services_for_all_logged_in_users
%files
%config(noreplace) /etc/kasmvnc
/usr/bin/*
/usr/lib/kasmvncserver
/usr/lib/systemd/user/kasmvncserver@.service
/usr/share/man/man1/*
/usr/share/perl5/KasmVNC
/usr/share/kasmvnc
@ -161,4 +195,11 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
make_self_signed_certificate
%postun
rm -f /etc/pki/tls/private/kasmvnc.pem
is_uninstall=0
if [ "$1" == 0 ]; then
is_uninstall=1
fi
if [ "$is_uninstall" = 1 ]; then
rm -f /etc/pki/tls/private/kasmvnc.pem
fi

View file

@ -48,6 +48,7 @@ cp $SRC_BIN/vncconfig $DESTDIR/usr/bin;
cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin;
cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin;
cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver
cp -r $SRC/lib/systemd/ $DESTDIR/usr/lib/
cd $DESTDIR/usr/bin && ln -s kasmvncpasswd vncpasswd;
cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/
rsync -r --links --safe-links --exclude '.git*' --exclude po2js --exclude xgettext-html \
@ -67,12 +68,45 @@ cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN;
cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN;
cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
%preun
stop_vncserver_systemd_services_for_all_logged_in_users() {
for session in $(list_user_sessions); do
stop_user_services "$session"
done
}
list_user_sessions() {
loginctl list-sessions --no-legend | awk '{print $1}'
}
stop_user_services() {
local session="$1"
for service in $(list_active_services); do
systemctl --user --machine=$(systemd_user_from_session "$session") stop "$service" || true
done
}
systemd_user_from_session() {
local session="$1"
echo $(loginctl show-session "$session" -p Name --value)@
}
list_active_services() {
systemctl --user --machine=$(systemd_user_from_session "$session") \
list-units --type=service --state=active --plain --no-legend | \
awk '{ print $1 }' | grep kasmvncserver
}
stop_vncserver_systemd_services_for_all_logged_in_users
%files
%config(noreplace) /etc/kasmvnc
/usr/bin/*
/usr/lib/kasmvncserver
/usr/lib/systemd/user/kasmvncserver@.service
/usr/share/man/man1/*
%perl_vendorlib/KasmVNC
/usr/share/kasmvnc
@ -159,4 +193,11 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
make_self_signed_certificate
%postun
rm -f /usr/share/pki/trust/anchors/kasmvnc.pem
is_uninstall=0
if [ "$1" == 0 ]; then
is_uninstall=1
fi
if [ "$is_uninstall" = 1 ]; then
rm -f /usr/share/pki/trust/anchors/kasmvnc.pem
fi

View file

@ -49,6 +49,7 @@ cp $SRC_BIN/vncconfig $DESTDIR/usr/bin;
cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin;
cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin;
cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver
cp -r $SRC/lib/systemd/ $DESTDIR/usr/lib/
cd $DESTDIR/usr/bin && ln -s kasmvncpasswd vncpasswd;
cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/
rsync -r --links --safe-links --exclude '.git*' --exclude po2js --exclude xgettext-html \
@ -68,12 +69,12 @@ cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN;
cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN;
cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
%files
%config(noreplace) /etc/kasmvnc
/usr/bin/*
/usr/lib/kasmvncserver
/usr/lib/systemd/user/kasmvncserver@.service
/usr/share/man/man1/*
/usr/share/perl5/KasmVNC
/usr/share/kasmvnc
@ -160,4 +161,11 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
make_self_signed_certificate
%postun
rm -f /etc/pki/tls/private/kasmvnc.pem
is_uninstall=0
if [ "$1" == 0 ]; then
is_uninstall=1
fi
if [ "$is_uninstall" = 1 ]; then
rm -f /etc/pki/tls/private/kasmvnc.pem
fi

View file

@ -49,6 +49,7 @@ cp $SRC_BIN/vncconfig $DESTDIR/usr/bin;
cp $SRC_BIN/kasmvncpasswd $DESTDIR/usr/bin;
cp $SRC_BIN/kasmxproxy $DESTDIR/usr/bin;
cp -r $SRC/lib/kasmvnc/ $DESTDIR/usr/lib/kasmvncserver
cp -r $SRC/lib/systemd/ $DESTDIR/usr/lib/
cd $DESTDIR/usr/bin && ln -s kasmvncpasswd vncpasswd;
cp -r $SRC/share/doc/kasmvnc*/* $DESTDIR/usr/share/doc/kasmvncserver/
rsync -r --links --safe-links --exclude '.git*' --exclude po2js --exclude xgettext-html \
@ -68,12 +69,45 @@ cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN;
cp $SRC/share/man/man1/kasmxproxy.1 $DST_MAN;
cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
%preun
stop_vncserver_systemd_services_for_all_logged_in_users() {
for session in $(list_user_sessions); do
stop_user_services "$session"
done
}
list_user_sessions() {
loginctl list-sessions --no-legend | awk '{print $1}'
}
stop_user_services() {
local session="$1"
for service in $(list_active_services); do
systemctl --user --machine=$(systemd_user_from_session "$session") stop "$service" || true
done
}
systemd_user_from_session() {
local session="$1"
echo $(loginctl show-session "$session" -p Name --value)@
}
list_active_services() {
systemctl --user --machine=$(systemd_user_from_session "$session") \
list-units --type=service --state=active --plain --no-legend | \
awk '{ print $1 }' | grep kasmvncserver
}
stop_vncserver_systemd_services_for_all_logged_in_users
%files
%config(noreplace) /etc/kasmvnc
/usr/bin/*
/usr/lib/kasmvncserver
/usr/lib/systemd/user/kasmvncserver@.service
/usr/share/man/man1/*
/usr/share/perl5/KasmVNC
/usr/share/kasmvnc
@ -160,4 +194,11 @@ cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
make_self_signed_certificate
%postun
rm -f /etc/pki/tls/private/kasmvnc.pem
is_uninstall=0;
if [ "$1" == 0 ]; then
is_uninstall=1;
fi
if [ "$is_uninstall" = 1 ]; then
rm -f /etc/pki/tls/private/kasmvnc.pem
fi

View file

@ -53,6 +53,8 @@ if [ $SERVER = 1 ]; then
install -m 755 ./xorg.build/lib/dri/swrast_dri.so $OUTDIR/lib/dri/
mkdir -p $OUTDIR/lib/kasmvnc
install -m 755 $SRCDIR/builder/startup/deb/select-de.sh $OUTDIR/lib/kasmvnc
mkdir -p $OUTDIR/lib/systemd/user
install -m 644 ./unix/kasmvncserver@.service $OUTDIR/lib/systemd/user
mkdir -p $OUTDIR/share/kasmvnc
cp -r $SRCDIR/unix/KasmVNC/ $OUTDIR/bin/

View file

@ -0,0 +1,14 @@
[Unit]
Description=KasmVNC
After=network.target
[Service]
Type=forking
Restart=always
RestartSec=5
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=default.target