LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-29-2015, 02:47 PM   #1
shakozzz
LQ Newbie
 
Registered: Oct 2014
Posts: 25

Rep: Reputation: Disabled
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

Last edited by shakozzz; 11-29-2015 at 02:57 PM. Reason: More detail
 
Old 11-29-2015, 07:06 PM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,132

Rep: Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161
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.
 
Old 11-30-2015, 05:53 AM   #3
shakozzz
LQ Newbie
 
Registered: Oct 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-30-2015, 07:00 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,599

Rep: Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360Reputation: 4360
so the link you posted contains a start/stop script too. Is this what you need or?
 
Old 11-30-2015, 09:29 AM   #5
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,132

Rep: Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161Reputation: 1161
Quote:
Originally Posted by shakozzz View Post
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?
 
Old 12-04-2015, 08:18 PM   #6
shakozzz
LQ Newbie
 
Registered: Oct 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
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?
 
  


Reply

Tags
boot, debian, init script, raspbian, scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Using init.d Scripts to Execute Commands at Start-Up LXer Syndicated Linux News 0 01-18-2014 12:33 AM
start init.d scripts before a chroot script using schroot? arobinson74 Linux - Software 1 10-11-2009 05:05 PM
Start/Stop/Status init scripts Rocket2DMn Solaris / OpenSolaris 2 10-17-2008 10:26 AM
Runlevel start/stop scripts vanalex Linux - General 0 01-27-2004 09:54 PM
Oracle 9i Start/Stop scripts vous Linux - Software 0 01-16-2004 02:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration