How to run xfce4 on debian on VNC startup? - xfce

I have a debian server. It is running the latest stable version of Debian.
The following commands have been entered:
apt-get install xfce4 xfce4-goodies
I have also added startxfce4 to the VNC startup file.
However, I get this black and white dotted screen when I start vnc:
Is there a way to make the xfce4 desktop run properly?
(it's a server, so i dont have the monitor, physical access etc)

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#it works for me

Use xfce4-session instead of startxfce4, it's in the package xfce4-session.

vi /root/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

Related

Docker: File (bootstrap.sh) not found in docker image while running container. Although file is present in image

I have created an image to run docker container with chrome. Below is my code. My dockerfile does compile into image. But whenever I try to run container from image I get error "Bootstrap.sh file not found" Although file is present in my FileSystem snapshot inside image. You can check screenshot.
Please help me resolve this issue I am new to docker.
FROM ubuntu:16.04
RUN apt-get update && apt-get clean && apt-get install -y \
x11vnc \
xvfb \
fluxbox \
wmctrl \
wget \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get -y install google-chrome-stable
RUN useradd apps \
&& mkdir -p /home/apps \
&& chown -v -R apps:apps /home/apps
COPY bootstrap.sh /
CMD '/bootstrap.sh'
BootStrap.sh file code:
#!/bin/bash
# Based on: http://www.richud.com/wiki/Ubuntu_Fluxbox_GUI_with_x11vnc_and_Xvfb
main() {
log_i "Starting xvfb virtual display..."
launch_xvfb
log_i "Starting window manager..."
launch_window_manager
log_i "Starting VNC server..."
run_vnc_server
}
launch_xvfb() {
local xvfbLockFilePath="/tmp/.X1-lock"
if [ -f "${xvfbLockFilePath}" ]
then
log_i "Removing xvfb lock file '${xvfbLockFilePath}'..."
if ! rm -v "${xvfbLockFilePath}"
then
log_e "Failed to remove xvfb lock file"
exit 1
fi
fi
# Set defaults if the user did not specify envs.
export DISPLAY=${XVFB_DISPLAY:-:1}
local screen=${XVFB_SCREEN:-0}
local resolution=${XVFB_RESOLUTION:-1280x960x24}
local timeout=${XVFB_TIMEOUT:-5}
# Start and wait for either Xvfb to be fully up or we hit the timeout.
Xvfb ${DISPLAY} -screen ${screen} ${resolution} &
local loopCount=0
until xdpyinfo -display ${DISPLAY} > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
log_e "xvfb failed to start"
exit 1
fi
done
}
launch_window_manager() {
local timeout=${XVFB_TIMEOUT:-5}
# Start and wait for either fluxbox to be fully up or we hit the timeout.
fluxbox &
local loopCount=0
until wmctrl -m > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
log_e "fluxbox failed to start"
exit 1
fi
done
}
run_vnc_server() {
local passwordArgument='-nopw'
if [ -n "${VNC_SERVER_PASSWORD}" ]
then
local passwordFilePath="${HOME}/.x11vnc.pass"
if ! x11vnc -storepasswd "${VNC_SERVER_PASSWORD}" "${passwordFilePath}"
then
log_e "Failed to store x11vnc password"
exit 1
fi
passwordArgument=-"-rfbauth ${passwordFilePath}"
log_i "The VNC server will ask for a password"
else
log_w "The VNC server will NOT ask for a password"
fi
x11vnc -display ${DISPLAY} -forever ${passwordArgument} &
wait $!
}
log_i() {
log "[INFO] ${#}"
}
log_w() {
log "[WARN] ${#}"
}
log_e() {
log "[ERROR] ${#}"
}
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ${#}"
}
control_c() {
echo ""
exit
}
trap control_c SIGINT SIGTERM SIGHUP
main
exit
Snapshot of Error:
Proof bootstrap.sh file is present inside my docker image
What you need to do is give the file the correct permissions. In your Dockerfile if you can add the line RUN chmod +x /bootstrap.sh right before you run CMD.
Dockerfile
FROM ubuntu:16.04
COPY bootstrap.sh /
RUN apt-get update && apt-get clean && apt-get install -y \
x11vnc \
xvfb \
fluxbox \
wmctrl \
wget \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get -y install google-chrome-stable
RUN useradd apps \
&& mkdir -p /home/apps \
&& chown -v -R apps:apps /home/apps
RUN chmod +x /bootstrap.sh
CMD '/bootstrap.sh'
You can try this:
CMD sh /bootstrap.sh
DockerFile
FROM ubuntu:16.04
COPY bootstrap.sh /
RUN apt-get update && apt-get clean && apt-get install -y \
x11vnc \
xvfb \
fluxbox \
wmctrl \
wget \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get -y install google-chrome-stable
RUN useradd apps \
&& mkdir -p /home/apps \
&& chown -v -R apps:apps /home/apps
CMD sh /bootstrap.sh

Bash Script with Several Nested elif Statements Not Working

I am trying to create a script I can provide to those who will use an academic game I am making. I am trying to do the following:
Verify that Apache2 is installed and Running
If Apache2 is installed, move a folder containing the website files to /var/www/html while backing up apache's original index.html
The code is as follows:
#!/bin/sh
acm=[]
cnn=[]
gnu=[]
ieee=[]
if [pgrep -x "apache2" > /dev/null]; then
echo "Apache 2 Installed and Running!"
if [ -d "$HOME/acmDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv acmDL /var/www/html/
cd /var/www/html/
sudo mv acmDL/* .
exit
elif [ -d "$HOME/cnnDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv cnnDL /var/www/html/
cd /var/www/html/
sudo mv cnnDL/* .
exit
elif [ -d "$HOME/gnuDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv gnuDL /var/www/html/
cd /var/www/html/
sudo mv gnuDL/* .
exit
elif [ -d "$HOME/ieeeDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv ieeeDL /var/www/html/
cd /var/www/html/
sudo mv ieeeDL/* .
exit
else
echo "Provided websites not found... Are you using a custom website?"
fi
else
echo "Please check apache2... It may not have installed correctly"
fi
The error I keep getting is syntax error near unexpected token `elif' on line 15.
As you can see, I even tried moving the boolean expression [ - d "$HOME/site" ] to their own variables, but then the error becomes : -d: command not found and the error on line 15.
Is what I am trying to do impossible, or am I missing something undocumented and yet completely obvious (like a handful of my previous posts)?
This is being run on a minimal installation of Ubuntu 18 on a Virtual Machine. The site directories are shared by Filezilla. Script written in Notepad++ on Windows 7 x64.
First of all, can you rewrite it like this?
Please tell me the execution result.
This is wrong.
if [pgrep -x "apache2" > /dev/null]; then
This is correct.
pgrep -x "apache2" > /dev/null
if [ $? -eq 0 ]; then

Is the Syntax for the Bash Script right for an if elif statement

I added another condition to my if, elseif condition for my bash shell script. I am new to shell scripting, can you guys review my code if my syntax for if conditions are right especially the "fi" implementation. Much appreciated.
if [ -f /etc/system-release ] && grep Amazon /etc/system-release > /dev/null; then
cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
else
# we're either RedHat or Ubuntu
DISTRIBUTOR=`lsb_release -is`
DISTRIBUTOR2=`lsb_release -cs`
if [ "trusty" == $DISTRIBUTOR2 ]; then
cd /tmp
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo start amazon-ssm-agent
elif [ "RedHatEnterpriseServer" == $DISTRIBUTOR ]; then
cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
elif [ "xenial" == $DISTRIBUTOR2 ]; then
cd /tmp
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo systemctl enable amazon-ssm-agent
fi
fi
sleep 10
Looks basically ok, but https://www.shellcheck.net/ has a couple of comments that you should probably address.

Fedora 25 Tigervnc displays Black screen

The system is Fedora 25. The issue is vncviewer is displaying a black screen. By comparison the vnc package list is the same as those in a Fedora 24 system where vnc viewer is displaying correctly.The same client system is used to access the server.
Other threads with this issue have been reviewed and tried, specifically vnc package requirements, $HOME//.vnc/xstartup permissions, and suggestions for the xstartup script.
Below is the xstartup script:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec gnome-session
# --session=gnome-fallback
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
startx &
Below is the output from systemctl status vncserver:
vncserver#:2.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver#:2.service; enabled; vendor
preset: disabled)
Active: active (running) since Fri 2017-01-13 07:05:58 PST; 1h 18min ago
Process: 25119 ExecStop=/usr/bin/vncserver -kill %i (code=exited,
status=0/SUCCESS)
Process: 25152 ExecStart=/usr/bin/vncserver %i (code=exited,
status=0/SUCCESS)
Process: 25147 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited,
status=2)
Main PID: 25161 (Xvnc)
Tasks: 186 (limit: 4915)
CGroup: /system.slice/system-vncserver.slice/vncserver#:2.service
├─25161 /usr/bin/Xvnc :2 -auth /home/dan/.Xauthority -desktop server:2
(dan) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x
├─25168 /usr/bin/vncconfig -nowin
├─25170 /usr/libexec/gnome-session-binary
├─25177 dbus-launch --autolaunch 98c684d1ace64647a9df44e5b61d8590 --
binary-syntax --close-stderr
├─25178 /usr/bin/dbus-daemon --syslog-only --fork --print-pid 5 --
print-address 7 --session
├─25182 dbus-launch --exit-with-session /usr/libexec/gnome-session binary
├─25183 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-
address 7 --session
├─25191 /usr/libexec/at-spi-bus-launcher
├─25196 /bin/dbus-daemon --config-file=/usr/share/defaults/at-
spi2/accessibility.conf --nofork --print-address 3
├─25199 /usr/libexec/at-spi2-registryd --use-gnome-session
├─25203 /usr/libexec/gvfsd
├─25222 /usr/bin/gnome-keyring-daemon --start --components=secrets
├─25242 /usr/libexec/gnome-settings-daemon
├─25252 /usr/bin/pulseaudio --start --log-target=syslog
├─25296 /usr/libexec/tracker-extract
├─25301 /usr/libexec/tracker-store
├─25318 /usr/libexec/tracker-miner-apps
├─25320 /usr/libexec/evolution/evolution-alarm-notify
├─25324 /usr/libexec/deja-dup/deja-dup-monitor
├─25329 /usr/libexec/gsd-printer
├─25335 /usr/libexec/imsettings-daemon
├─25336 /usr/libexec/tracker-miner-user-guides
├─25378 abrt-applet
├─25418 /usr/libexec/tracker-miner-fs
├─25438 /usr/libexec/gvfs-udisks2-volume-monitor
├─25462 /usr/bin/seapplet
├─25529 /usr/libexec/gvfs-gphoto2-volume-monitor
├─25559 /usr/bin/ibus-daemon -r --xim
There were several threads a few years back. Those have been reviewed and tried. They do not seem applicable to this situation.
You can find an answer here: https://www.server-world.info/en/note?os=Fedora_25&p=desktop&f=6 - on my case the replacement at /home/USER/.vnc/xstartup
...
# end line: comment out and add like follows
#exec /etc/X11/xinit/xinitrc
#exec /usr/bin/mate-session
exec /usr/bin/gnome-session
so I used gnome-session instead of mate-session as I am using gnome-desktop.
No more blank screen (wait some time until transmitted).
I am using Fedora 27 and having the same issue "Black Screen". I tried a lot of 'workaround', none of them works for me. then I switched to use MATE desktop environment, and got it working in seconds. if you had struggled with the issue for a long time, i would suggest to try MATE desktop.
if you don't have MATE installed, you should install MATE:
dnf -y group install "MATE Desktop"
here is the help of installing MATE.
update xstartup as follows.
#!/bin/sh
#def
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec /usr/bin/mate-session
remember to restart VNC service, it should work.
#systemctl start vncserver#:1.service
Hope it helps somebody.
I also had the issue in F25 with gnome. I just modified the xstartup like the following, and it started working well:
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec gnome-session
#exec /etc/X11/xinit/xinitrc
what about to add a config for xstartup in ~/.vcn/
!/bin/sh
#
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
# exec /etc/X11/xinit/xinitrc
#
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &

Boot to shell with Ubuntu MATE 15.04 on Raspberry PI 2

Is it possible to boot to the terminal? I've tried to look for a grub file but I could not find it. Also /boot/firmware/config.txt does not seem to have such option.
Thanks to Rohith Madhavan and AceFace on Ubuntu-mate bitbucket issues:
You can boot to shell using the following commands:
systemctl set-default multi-user.target --force
systemctl disable lightdm.service --force
systemctl disable graphical.target --force
systemctl disable plymouth.service --force
Replace disable with enable to boot with GUI again.
The proposed solution doesn't work on Ubuntu MATE 16.04 and the "Welcome" application mentions a non-existent "graphical" command. The following worked for me :
#!/bin/bash
if [[ "$1" == 'enable' || "$1" == 'disable' ]]; then
if [ "$1" == 'disable' ]; then
systemctl set-default multi-user.target --force
fi
systemctl $1 lightdm.service --force
systemctl $1 graphical.target --force
systemctl $1 plymouth.service --force
if [ "$1" == 'enable' ]; then
if [ ! -h /etc/systemd/system/display-manager.service ]; then
ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
fi
systemctl set-default graphical.target --force
fi
else
echo 'Enables or disables GUI at boot.'
echo "Usage : $(basename) {enable | disable}"
fi

Resources