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" |
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
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
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
Hi, might I suggest adding
dbus
to the end of line 17? As a new FreeBSD user I had a terrible time figuring out why vnc connetctions displayed a black screen after a reboot, but restarting the service (I use PhilZ-cwm6's version) would fix it. It might be more obvious to those more experienced but I run my machine headless (hence why this service is critical). As such I don't see the dmesg boot sequence. I've found the dmesg I can launch via ssh after the fact doesn't match 100% what's displayed on the console. At any rate, the issue is that rc.d was launching Xvnc before dbus which is why it wouldn't work after a reboot. Thank you both for this script, it was immensely helpful.