Solved

Scripted configuration of TightVNC with Start on boot

Posted on 2016-11-08
7
81 Views
Last Modified: 2016-11-14
Hi,

I'm trying to develop a script that I can work into an unattended build that will configure TightVNC on Kali linux (based on Debian) and then ensure that it runs on boot

Here is what I have currently in my bash script (deploy.sh)

# Configure VNC Password
umask 0077                                        # use safe default permissions
mkdir -p "$HOME/.vnc"                             # create config directory
chmod go-rwx "$HOME/.vnc"                         # enforce safe permissions
vncpasswd -f <<<"remotecl" >"$HOME/.vnc/passwd"  # generate and write a password

# Start VNC 
/usr/bin/tightvncserver -geometry 1500x700 -depth 16

Open in new window


This is setting the password and starting the VNC server however when the machine is restarted, the service does not start back up

Can someone help me with this please
0
Comment
Question by:aideb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
Scott Silva earned 450 total points
ID: 41879604
I'm not fully vetted on Debian, but you will need to get a startup script or at least a link into the init process...
I assume it is using System V init...   This might help.
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html
0
 
LVL 2

Author Comment

by:aideb
ID: 41879628
Thanks Scott,

That has moved me along nicely - I used the info in your link and discovered another post

I did

sudo nano /etc/initd/vncserver

and populated this with

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     3 4 5
# Default-Stop:      0 6
### END INIT INFO

PATH="$PATH:/usr/X11R6/bin/"

# The Username:Group that will run VNC
export USER="labuser"
#${RUNAS}

# The display that VNC will use
DISPLAY="1"

# Color depth (between 8 and 32)
DEPTH="16"

# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
#GEOMETRY="800x600"
GEOMETRY="1024x768"
#GEOMETRY="1280x1024"

# The name that the VNC Desktop will have.
NAME="my-vnc-server"

OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"

. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on   localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/tightvncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/tightvncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac

exit 0

Open in new window


I can now start the service with

/etc/initd/vncserver start

and stop with

/etc/initd/vncserver stop


How can I get the start command to execute on boot?

Cheers
0
 
LVL 10

Assisted Solution

by:Scott Silva
Scott Silva earned 450 total points
ID: 41879632
You need a link to that script in /etc/rcx.d  where x is the run level you are starting in... Usually 3 for a headless server, and 5 for a graphical desktop... The link is named with an "S" and a number corresponding with what order it should start... Higher numbers start later... This is so you can make sure dependent services start earlier...  You also technically should have a shortcut in /etc/rc0.d starting with a "K" so the process can be shutdown in an orderly manner...
1
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 2

Author Comment

by:aideb
ID: 41879649
Great - Thanks Scott

I ran this

sudo ln -s /etc/initd/vncserver /etc/rc5.d/S08vncserver
sudo ln -s /etc/initd/vncserver /etc/rc0.d/K01vncserver

and it started on boot!

How am I best automating this so that I can add it all to my deploy.sh
0
 
LVL 10

Assisted Solution

by:Scott Silva
Scott Silva earned 450 total points
ID: 41879722
You would just have to add all the steps you did into your script... You could either copy a script in from a server, or use whatever you feel comfortable to echo the lines into the scripts, or maybe sed...  I would just make a tar file with all the shortcuts in it and untar it relative to where everything goes...
0
 
LVL 29

Assisted Solution

by:serialband
serialband earned 50 total points
ID: 41880877
You should be able to do the following on debian based systems that use Sys V init:
update-rc.d vncserver defaults

To remove it
update-rc.d vncserver defaults

They should be a little less error prone than manually linking them in the directories.
1
 
LVL 2

Author Closing Comment

by:aideb
ID: 41886167
Thanks for all your assistance to resolve this!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question