LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   start and stop sections of init scripts (https://www.linuxquestions.org/questions/linux-newbie-8/start-and-stop-sections-of-init-scripts-4175560161/)

shakozzz 11-29-2015 01:47 PM

start and stop sections of init scripts
 
I have a normal script /home/pi/startVNC.sh which contains the following:
Code:

#!/bin/sh
vncserver :1 -geometry 1280x720

So obviously it starts the vncserver with the given options. Now, I want to write an init script, say startVNCinit, that does the exact same thing automatically at start up. I have a general idea that within the start and stop sections of the init script, startVNC.sh would need to be started and stopped respectively. However, it's unknown to me how this should be achieved. There seem to be many examples online, but none of them explain this point thoroughly. This is one of the articles I was reading. I copied and pasted his script while doing the needed modifications in the INIT INFO block as fits my needs. I just have no idea what to write in the start and stop sections. Any tips are highly appreciated.

Code:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          startVNCinit
# Required-Start:    $local_fs $network
# Required-Stop:    $local_fs
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts vnc server at boot
# Description:      starts vnc server at boot
### END INIT INFO

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting startVNC"
    #I assume startVNC should be started here somewhere

    ;;
  stop)
    echo "Stopping startVNC"
    #I assume startVNC should be stopped here somewhere

    ;;
  *)
    echo "Usage: /etc/init.d/foobar {start|stop}"
    exit 1
    ;;
esac

exit 0


berndbausch 11-29-2015 06:06 PM

What distro is this? Many distros should provide initialization scripts for vnc servers out of the box. Then, it's just a question of setting up a config file such as /etc/sysconfig/vncservers.

To answer your question, just put vncserver :1 -geometry 1280x720 into the start branch, and something like vncserver -kill :1 in the stop branch (check the syntax though, the precise command might depend on your particular vnc server). This does the job but doesn't separate config data and executable, thus provides little flexibility.

shakozzz 11-30-2015 04:53 AM

Well this is Raspbian, so it's based on Debian. I had already tried what you said, but it doesn't work. In the log/error file it would say that the USER variable isn't defined. After inserting the variable, it starts complaining that the HOME variable isn't. After supplying that it just says "vncserver: Wrong type or access mode of /home/pi/.vnc." On the Raspberrypi website it's done differently. Have a look. I tried this and it works. But when switching the start and stop sections here with your recommendations it still stops working and gives the same error.

pan64 11-30-2015 06:00 AM

so the link you posted contains a start/stop script too. Is this what you need or?

berndbausch 11-30-2015 08:29 AM

Quote:

Originally Posted by shakozzz (Post 5457269)
Well this is Raspbian, so it's based on Debian. I had already tried what you said, but it doesn't work. In the log/error file it would say that the USER variable isn't defined. After inserting the variable, it starts complaining that the HOME variable isn't. After supplying that it just says "vncserver: Wrong type or access mode of /home/pi/.vnc." On the Raspberrypi website it's done differently. Have a look. I tried this and it works. But when switching the start and stop sections here with your recommendations it still stops working and gives the same error.

In case you use the newest raspbian, it doesn't use SystemV initialization but systemd, totally different.

So what is the problem with the solution at the link you provided?

shakozzz 12-04-2015 07:18 PM

The script at the provided link works fine. Now I'm just wondering why your starting and stopping methods
Code:

vncserver :1 -geometry 1280x720
and
Code:

vncserver -kill :1
don't work because that was what occurred to me at the very beginning, but obviously the script in the link uses
Code:

su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
to start and
Code:

/usr/bin/vncserver -kill :0
to stop. Is there a difference? Or is there perhaps a certain syntax used in init scripts?
PS: Yes I am using the newest Raspian, Jessie. To what degree would that affect what the script looks like?


All times are GMT -5. The time now is 06:31 AM.