Adding a Service for Runlevels 3 and 5

I have to run this post as two pieces because the BBoard has a bug, and it’s the only way to get this combination of symbols into a post. So here’s part one:

I have a simple script called tightvnc.sh at location /home/john/scripts/tightvnc.sh

The script contains this:

#!/bin/sh
/usr/bin/vncserver -geometry 800x600 :1 -depth 8

It works fine when called manually, starting a TightVNC server.

I want to start it as a service. So I copy the file /etc/init.d/skeleton to /etc/init.d/tightvnc. I make sure the new file is executable. I edit the segment titled “### BEGIN INIT INFO” so it now reads like this:

BEGIN INIT INFO

Provides: vncserver

Required-Start: $syslog $remote_fs

Should-Start: $time ypbind smtp

Required-Stop: $syslog $remote_fs

Should-Stop: $time ypbind smtp

Default-Start: 3 5

Default-Stop: 0 1 2 6

Short-Description: TightVNC server (vncserver)

Description: file:///home/john/scripts/tightvnc.sh

END INIT INFO

I speak again, here’s another bit:

I change only one other line in the file, from this:

FOO_BIN=/usr/sbin/FOO

to this

FOO_BIN=/home/john/scripts/tightvnc.sh

In case you’re wondering I did not change this line:

FOO_CONFIG=/etc/sysconfig/FOO

Then I activae with this root CLI command → chkconfig -a tightvnc which responds like so:

suse110:/home/john # chkconfig -a tightvnc
insserv: script skeleton.compat: service FOO already provided!
tightvnc here it shows runlevels 3 & 5 on – wretched vile bulletin board won’t work properly

I reboot and the service has not started. It exists in Yast → System → Runlevels with the status “Enabled = Yes*”. The asterisk means there’s some problem. I use the button to “Enable” again and get a message that “program is not configured”

I open a shell as root and issue command “/etc/init.d/tightvnc start” and get this message: “/etc/sysconfig/FOO not existing”.

This was done on guesswork, so please help me fix this. Looks like the /etc/sysconfig thing I suppose, but I’m out of guesses.

Thanks
Swerdna

You need to change all instances of FOO to whatever your service is called, say myservice. That message is caused by the line Provides: FOO. Since the skeleton already provides FOO… In some places if it’s not appropriate to have say an /etc/sysconfig/myservice then you should delete the code. It’s ok to modify the template code to suit your situation.

Hi
You will also need to modify the init script to run as your user with
the su command…


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.2-default
up 1 day 21:01, 1 user, load average: 0.27, 0.32, 0.27
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82

Or better still with the appropriate arguments to startproc, which is designed to be a wrapper around service executables.

Thanks guys. I changed it as per malcolmlewis advice. I moved the script to root’s territory and ran all as root. I still got the display in Yast’s runlevels display as “Yes*” with an asterisk and it wouldn’t start at boot time. However if i ran the command “/etc/init.d/tightvnc start” the service started fine.

I tested the form of startproc but couldn’t get an advantage.

I’m beyond my depth now. I feel there’s a clue in that it starts with “/etc/init.d/tightvnc start”, but I don’t know enough to track it down.

Any thoughts?

Swerdna

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Usually if something is configured to start at boot and doesn’t, but
then does start immediately once you are booted, it’s because some
dependency was not met. For example VNC requires the network so was
networking fully functional by the time VNC tried to start? In your
/etc/init.d/tightvnc script at the top are a few lines that are
commented out, but which are understood and handled by ‘chkconfig’ and
therefore Yast.

Required-Start:

This line is the most important and, for most networking apps, includes
a requirement that $network be up and running.

You can test this theory manually by renaming your startup softlink in
/etc/init.d/rc<runlevelNumber>.d/S??tightvnc to
/etc/init.d/rc<runlevelNumber>.d/S99tightvnc, effectively making
tightvnc the last thing to load in this way (or at least nearly tied for
last). Give it a shot and post back.

Good luck.

swerdna wrote:
> Thanks guys. I changed it as per malcolmlewis advice. I moved the script
> to root’s territory and ran all as root. I still got the display in
> Yast’s runlevels display as “Yes*” with an asterisk and it wouldn’t
> start at boot time. However if i ran the command “/etc/init.d/tightvnc
> start” the service started fine.
>
> I tested the form of startproc but couldn’t get an advantage.
>
> I’m beyond my depth now. I feel there’s a clue in that it starts with
> “/etc/init.d/tightvnc start”, but I don’t know enough to track it down.
>
> Any thoughts?
>
> Swerdna
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJNTuN3s42bA80+9kRAt6NAJ9ENx4Yo3FEZxWmuUi5wbtaiS58xgCfQD9B
OxgbtV81xE17YrZlDO0wxXg=
=talP
-----END PGP SIGNATURE-----

If necessary you can insert some debug statements in the init file to let you know what it’s up to. Write the report to a temp file so you don’t have to figure which log file it went to:


echo Starting tightvnc >> /tmp/debug.log
# you can also capture error messages from your program
# I'm guessing the syntax of your tightvnc command, fix it to suit
tightvnc >> /tmp/debug.log 2>&1 &
echo Finished starting tightvnc >> /tmp/debug.log

and so forth

Hi
In the past I’ve used this to start applications as a different user;


su - <username> -c "nohup /path/to/somefile &"

You might also look at some of the other scripts in the init.d on how
the run using startproc.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.2-default
up 2 days 13:01, 1 user, load average: 0.09, 0.19, 0.21
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82

Malcolm wrote:
> [QUOTE=swerdna]
> Thanks guys. I changed it as per malcolmlewis advice. I moved the script
> to root’s territory and ran all as root. I still got the display in
> Yast’s runlevels display as “Yes*” with an asterisk and it wouldn’t
> start at boot time. However if i ran the command “/etc/init.d/tightvnc
> start” the service started fine.
>
> I tested the form of startproc but couldn’t get an advantage.
>
> I’m beyond my depth now. I feel there’s a clue in that it starts with
> “/etc/init.d/tightvnc start”, but I don’t know enough to track it down.
>

Now that your script works, you need to su to root, change directory to
/etc/init.d/rc5.d, and create a link back to that script in /etc/init.d. The
stuff in the rcX.d directories is run in alphabetical order, thus you need to
start it after all the prerequisites are started. It should be safe to start it
last by issuing the command

ln -s S99tightvnc …/tightvnc

If you want to kill the service when shutting down, then you will need

ln -s K01tightvnc …/tightvnc

The above two commands will take care of run level 5. Do the same two commands
in /etc/init.d/rc3.d to get tightvnc started and stopped at run level 3.

Larry

Here’s what I did:

ab@novell.com → I have it set only for runlevel 5 now. I looked in rc5.d and nothing of note was after the link back to /etc/init.d/tightvnc. Nevertheless I renamed the link to S99tightvnc. I also added $network to the list of services that start first in the line “# Required-Start:”
There was no improvement. The service still starts later via the command /etc/init.d/tightvnc start.

@lwfinger → as above covers your link back suggestion I think

@malcolmlewis → I’m reserving the issue of su and startproc to later, preferring to uncomplicate things by running as root first. It’s totally unsatisfactory to serve a root desktop via VNC, so I have to confront the issue, but later when the service is at least starting.

@ken_yap The log file shows a very interesting clue:

Starting tightvnc
Finished starting tightvnc
vncserver: The USER environment variable is not set.

The script invokes the program /usr/bin/vncserver. The program vncserver itself invokes the program /usr/bin/Xvnc. Man vncserver and man Xvnc have no reference to an environment variable. Before I track those further, could the log relate to a problem within the ecript /etc/init.d/tightvnc?

And of course – my sincere thanks

swerdna wrote:
> Here’s what I did:
>
> ab@novell.com → I have it set only for runlevel 5 now. I looked in
> rc5.d and nothing of note was after the link back to
> /etc/init.d/tightvnc. Nevertheless I renamed the link to S99tightvnc. I
> also added $network to the list of services that start first in the line
> “# Required-Start:”
> There was no improvement. The service still starts later via the
> command /etc/init.d/tightvnc start.
>
> @lwfinger → as above covers your link back suggestion I think
>
> @malcolmlewis → I’m reserving the issue of su and startproc to later,
> preferring to uncomplicate things by running as root first. It’s totally
> unsatisfactory to serve a root desktop via VNC, so I have to confront
> the issue, but later when the service is at least starting.
>
> @ken_yap The log file shows a very interesting clue:
>> Starting tightvnc
>> Finished starting tightvnc
>> vncserver: The USER environment variable is not set.
> The script invokes the program /usr/bin/vncserver. The program
> vncserver itself invokes the program /usr/bin/Xvnc. Man vncserver and
> man Xvnc have no reference to an environment variable. Before I track
> those further, could the log relate to a problem within the ecript
> /etc/init.d/tightvnc?

During these startup routines, you cannot assume any environment variables. If
you know what user should be running this procedure (perhaps root), you should
add the following:

USER=root
export USER

If this doesn’t fix it, it could be that the startup process is still occurring
too early despite the S99… You might try adding a sleep statement to the start
portion of tightvnc.

Larry

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps it has dependencies on X then… and X isn’t loaded yet. Maybe
throw in a pause… thirty seconds or so… at the top of
/etc/init.d/tightvnc ?

Good luck.

Larry Finger wrote:
> swerdna wrote:
>> Here’s what I did:
>>
>> ab@novell.com → I have it set only for runlevel 5 now. I looked in
>> rc5.d and nothing of note was after the link back to
>> /etc/init.d/tightvnc. Nevertheless I renamed the link to S99tightvnc. I
>> also added $network to the list of services that start first in the line
>> “# Required-Start:”
>> There was no improvement. The service still starts later via the
>> command /etc/init.d/tightvnc start.
>>
>> @lwfinger → as above covers your link back suggestion I think
>>
>> @malcolmlewis → I’m reserving the issue of su and startproc to later,
>> preferring to uncomplicate things by running as root first. It’s totally
>> unsatisfactory to serve a root desktop via VNC, so I have to confront
>> the issue, but later when the service is at least starting.
>>
>> @ken_yap The log file shows a very interesting clue:
>>> Starting tightvnc
>>> Finished starting tightvnc
>>> vncserver: The USER environment variable is not set.
>> The script invokes the program /usr/bin/vncserver. The program
>> vncserver itself invokes the program /usr/bin/Xvnc. Man vncserver and
>> man Xvnc have no reference to an environment variable. Before I track
>> those further, could the log relate to a problem within the ecript
>> /etc/init.d/tightvnc?
>
> During these startup routines, you cannot assume any environment variables. If
> you know what user should be running this procedure (perhaps root), you should
> add the following:
>
> USER=root
> export USER
>
> If this doesn’t fix it, it could be that the startup process is still occurring
> too early despite the S99… You might try adding a sleep statement to the start
> portion of tightvnc.
>
> Larry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJNbmk3s42bA80+9kRAp1DAJ0Qs+ZlO6h5R6BGQ+FgnD1Q5OncUACeK/OW
vRefmxpoFNPI8U7A8EF49AY=
=1Cdt
-----END PGP SIGNATURE-----

Thanks. I’ve tried sleeping/pausing. Doesn’t help.

There is some form of dependency. I’ve found lock files in /tmp/.X11-unix of form X0 and X1. X0 is a lock for the standard XWindow and X1 is a lock for TightVNC window on port 5901. They are only generated after the windows start. So X1 shows that the VNC window did start – but despite the X1 evidence that a TightVNC windows did start, it doesn’t exist after the boot process settles.

So I will investigate further, but in interests of sanity I’ll take a few days off first.

Thanks very much everyone.

swerdna