Last active
January 1, 2024 12:01
-
-
Save PieterScheffers/1ecd70a1bfe640afb98f3cac9630814b to your computer and use it in GitHub Desktop.
vncserver rc.d script for FreeBSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Download this file | |
# cd /usr/local/etc/rc.d && fetch --no-verify-peer https://gist.githubusercontent.com/PieterScheffers/1ecd70a1bfe640afb98f3cac9630814b/raw/326033ce1c243fd7ecd018684e748234668cf9ff/vncserver | |
# | |
# Make the file executable with: | |
# /usr/local/etc/rc.d/vncserver (chmod +x) | |
# | |
# add to /etc/rc.conf | |
# | |
# vncserver_enable="YES" | |
# vncserver_user="vncserver" | |
# vncserver_display="1" | |
# PROVIDE: vncserver | |
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv | |
# | |
. /etc/rc.subr | |
name=vncserver | |
rcvar=vncserver_enable | |
VNCSERVER=/usr/local/bin/vncserver | |
load_rc_config $name | |
start_cmd="vncserver_start" | |
stop_cmd="vncserver_stop" | |
restart_cmd="vncserver_restart" | |
: ${vncserver_user="vncserver"} | |
: ${vncserver_enable="NO"} | |
: ${vncserver_display="1"} | |
: ${vncserver_depth="24"} | |
: ${vncserver_geometry="1280x800"} | |
vncserver_start() | |
{ | |
CMD="$VNCSERVER -depth ${vncserver_depth} -geometry ${vncserver_geometry} -nolisten tcp :${vncserver_display}" | |
su -l ${vncserver_user} -c "${CMD}" | |
} | |
vncserver_stop() | |
{ | |
CMD="$VNCSERVER -kill :${vncserver_display}" | |
su -l ${vncserver_user} -c "${CMD}" | |
} | |
run_rc_command "$1" |
I wasn't using port forwarding. My issue is that upon boot the vnc service would start before dbus and thus fail. So after every reboot I would have to manually restart the vnc service. But when I added dbus to the require line the service would wait for dbus to be active, then start so everything worked automatically if I reboot my system.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding dbus at the end doesn't fix the issue if the ssh connection with the server (C2S port forwarding) is established too early
In that case, SSH connection needs to be closed and a new login established to get the display on VNC