0
votes

Thanks in advance for reading my post. I'm having an issue with my program performing differently when it is started from my init.d script. It is a C++ program that I'm storing in the /usr/local/bin directory along with two properties files. One of the properties files is needed to run the program correctly. Everything works fine when the program is called from the command line such as:

myprogram or ./myprogram

but when my init.d script is used to start the program the binary won't open the needed properties files. I have checked the permissions on the init.d script (chmod 755) and made sure I updated the rc.d (sudo update-rc.d myprogram defaults) but I have not been able to figure this out. The LSB header of the init script looks like this:

#!/bin/bash 
### BEGIN INIT INFO
# Provides:         myprogram (where myprogram is the name of the init script)
# Required-Start:       $local_fs $network $remote_fs $syslog
# Required-Stop:        $local_fs $network $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    myprogram short description
# Description:      Enable service provided by daemon
### END INIT INFO

Any help is really appreciated. Thanks.

2
I assume the script is not in the same directory as the executable?Borgleader
What goes wrong when you try to open the file?David Schwartz
No, the init script is in the /etc/init.d directory with permissions 755. The binary it calls is in /usr/local/bin. I'm using ifstream to open the file and I throw an error and print out "Can't open input file. Please check file and permissions!" if it can't open the infile. Of course I have checked the permissions multiple time and even set them to 777 just to see if that was it but to no avail.infohound
Are you using relative or absolute paths? (to open the property files)Borgleader
Relative paths, just ./myfile.properties. The thing is that it works well if I were to just execute the binary from the command line.infohound

2 Answers

1
votes

Since you're using relative paths to open the file here is what is most likely the issue. The working directory when you launch the application from your script is the directory in which the script is found and not the directory in which the application is. And so when you use relative paths to find the file they're relative to the directory of the script which is why it can't find them when you execute from script but can when you execute directly from command line.

You can test this theory by moving the script to the application's directory and trying to run it. If it works from script while the script and application are in the same directory then I'm right.

nothing can be sure since we don't have your code.

0
votes

The problem is for your LBS signature: if LBS not compelete THEN even cat command cant find init.d scripts

from init.d READ.ME:

All init.d scripts are expected to have a LSB style header documenting dependencies and default runlevel settings. The header look like this (not all fields are required):

### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $portmap
# Should-Stop:       $portmap
# X-Start-Before:    nis
# X-Stop-After:      nis
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

enter image description here