Init script not working for python command - openSUSE 11.1

Hi all,

i have a problem concerning init scripts and python.

What i have is a init script:


#!/bin/sh### BEGIN INIT INFO
# Provides:       arelle
# Required-Start:
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start Arelle Webservice
### END INIT INFO

case "$1" in
  start)
        #su -c "python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075"
        su -c "/root/start_arelle.sh"
        echo "arelle started"
        ;;
  stop)
        echo "not implemented yet"
        ;;
  restart)
        echo "not implemented yet"
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac
exit 0

This script resides in /etc/init.d. I’ve already added it to the runlevels using

chkconfig -a arelle

When i start the script in the console using

./arelle start

the arelle server starts without any issues. But when i restart my machine the server is not started! I’ve tested this using

netstat -nlp

Also i’ve written a separate file that just has the command commented out in the init file


#!/bin/sh
python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075

Also this works!

To make sure that there is nothing wrong with the init script i’ve modified it:


#!/bin/sh
### BEGIN INIT INFO
# Provides:       arelleTest
# Required-Start:
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start Arelle Webservice
### END INIT INFO


case "$1" in
  start)
        su -c "touch /root/thisIsATest"
        echo "arelle started"
        ;;
  stop)
        echo "not implemented yet"
        ;;
  restart)
        echo "not implemented yet"
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac


exit 0



As you can see, i’ve just added the touch command. This script is being executed during startup since the file exists after booting. So i guess there is an issue with the python command that starts the server. But the command as such works like a charm (also, as mentioned above, the init start works when executed by hand). Does anybody have any guess why this does not work during startup? Any ideas are very welcome! Is there any place where i can find maybe an error message in the logs?

Best regards,

Moe

On 06/17/2013 03:26 AM, MoeZarella wrote:
> Does anybody have any guess why this does not work during startup?

i guess you are either using openSUSE 11.1 which went end-of-life and
support January 14th 2011 (cite http://en.opensuse.org/Lifetime) and
you need to move to a current version (because the one you are using
should not be connected to any external network as it has had zero
security updates in two and a half years)…

or, you are using SUSE Linux Enterprise Server/Desktop 11 SP1, in
which case (since these are the openSUSE forums) you need to be
asking the SUSE Linux folks over in the correct forum, here:
http://forums.suse.com/

you are, of course welcome to hang out here and see if someone can
remember how python worked on their 11.1 three years ago (i don’t
expect anyone has a running copy to try to duplicate and then test
fix it)…and, there might be one or two SLES/D 11 users here who
might be helpful (but most here have never ever seen either SLE_
running)…


dd

Apart from the remarks about your “old” openSUSE or “not even openSUSE at all” version, I do not understand what you are doing at all. Why the su commands. init and all started by it is already running as root of course. And that brings me to the a bit tricky question: Do you realy know what you are doing?

The line

#!/bin/sh### BEGIN INIT INFO

is also messed up and thus the significant comments will most probaly not be found

Also you seem to think that python3 is available and found. Typicaly one uses absolute pathes in initd scripts and one checks if the tool exists. See the same in e.g. sshd:

SSHD_BIN=/usr/sbin/sshd
test -x $SSHD_BIN || exit 5

Carefull and defensive programming is the key to system programming.

Hi DenverD,

yes, you are right. The server uses 11.1. Don’t ask me why. I just have access to it for a short time and will of course do the dist upgrades asap. The webservice i use in the script is just for local applications so it is not connected to external networks.

you are, of course welcome to hang out here and see if someone can
remember how python worked on their 11.1 three years ago (i don’t
expect anyone has a running copy to try to duplicate and then test
fix it)…and, there might be one or two SLES/D 11 users here who
might be helpful (but most here have never ever seen either SLE_
running)…

dd

It is not(!) python from 11.1. It is python 3.2 that i had to compile because 11.1 did not have python 3.2.

Hi hcvv,

I want to start the server with an own user account so i will add a “-m” for the user. I just removed it to try to remove possible errors.

And that brings me to the a bit tricky question: Do you realy know what you are doing?

No, i have to learn this. But that’s why i am here. I guess just as most of the people who are asking things here…

The line

#!/bin/sh### BEGIN INIT INFO

is also messed up and thus the significant comments will most probaly not be found

It is just messed up in the code block here in the post. Of course it is found otherwise chkconfig would not have created the right links in rc.3

Also you seem to think that python3 is available and found. Typicaly one uses absolute pathes in initd scripts and one checks if the tool exists. See the same in e.g. sshd:

SSHD_BIN=/usr/sbin/sshd
test -x $SSHD_BIN || exit 5

Carefull and defensive programming is the key to system programming.

Thanks for the hint.

It seems like that you know what you are doing, so can you give me an answer to my question mentioned above: Is there any place where i can find maybe an error message in the logs?

Best regards,

Moe

Just a wild guess: Maybe the network is not up yet when your script starts and that’s why it doesn’t work?
Try to add $network to the “Required-Start:” line.

And have a look into /var/log/messages. Maybe there’s an error msg in there that helps you find the reason.
(I hope that’s the right log. It has been a while since I last used 11.1… ;))

On 2013-06-17 14:56, MoeZarella wrote:
>
> Hi hcvv,
>
> hcvv;2565386 Wrote:
>> Apart from the remarks about your “old” openSUSE or “not even openSUSE
>> at all” version, I do not understand what you are doing at all. Why the
>> su commands. init and all started by it is already running as root of
>> course.
>>
> I want to start the server with an own user account so i will add a
> “-m” for the user. I just removed it to try to remove possible errors.

You can not.

Init service script are run by root always, so remove those “su”. As
user, run the entire script under “su -” (not “su”).

>> And that brings me to the a bit tricky question: Do you realy know
>> what you are doing?
>>
> No, i have to learn this. But that’s why i am here. I guess just as
> most of the people who are asking things here…

But 11.1 is obsolete technology, we are already forgetting how it was
done. Look, the English documentation has been removed:


http://doc.opensuse.org/
-->
https://www.suse.com/de-de/documentation/opensuse111/
-->
> https://www.suse.com/de-de/documentation/opensuse111/opensuse111_reference/?page=/de-de/documentation/opensuse111/opensuse111_reference/data/opensuse111_reference.html

It is Deutch, the English version has disappeared. I doubt you can ask
them to put it back. You need chapter 14. You might have it on the DVD,
though, or the online repos if you can still find them.

> Code:
> --------------------
> > > #!/bin/sh### BEGIN INIT INFO
> --------------------
>>>
>> is also messed up and thus the significant comments will most probaly
>> not be found
>>
> It is just messed up in the code block here in the post. Of course it
> is found otherwise chkconfig would not have created the right links in
> rc.3

You have to be careful how you post or you get the wrong answers.

Please use code tags for printouts and commands. Advanced forum editor,
‘#’ button. Posting in Code Tags - A Guide

> It seems like that you know what you are doing, so can you give me an
> answer to my question mentioned above: Is there any place where i can
> find maybe an error message in the logs?

/var/log/boot.msg, I think.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

It is what you show us, thus you will get comment about what you show us, not about what you intend to do, but do not show. We (I at least) try to interprete what you write as if the computer would interprete it. It is the best way to avoid jumping to conclusions.

Again, you showed it. That what you show is inconsistent with what you tell is a your correct conclusion. But we can not guess which of both is correct and I prefer to think that the computer text is correct, rather then the story telling.
Check your posting as you would check your prgramming. We are spending time on your problem as volunteers.

You are welcome. But did you do what I hinted (using an absolute path to python3) and did you rerun the whole and what is the conclusion of such a test.

I may add that now we know that you are trying to run parts this as a normal user, all your code examples where we can not see if your are doing them as root or as end-user are rather useless for us to interprete.

Hi,

Thanks for your hints! Required-Start did not help. My script started in the last phase (as i could see in rc.3) but the server was not running
Also i couldn’t find anything in /var/log/messages.

Hi,

Everything i did up to know was as root! So don’t be confused. I’ve seen the

su -c -m

stuff in startup scripts written by Atlassian (Jira, Crowd and so on) and i wanted to test this after i got the server running.

Yes, i did but i did not finish testing while writing the post you refer to. But now i am so here are my results :wink: Since i do not know how to log events in init scripts as it should be done, i’ve added a simple logger, just for testing purposes:


#!/bin/bash
### BEGIN INIT INFO
# Provides:       arelle
# Required-Start: bamboo
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start Arelle Webservice
### END INIT INFO


ARELLE_LOG=/root/arelle_log


# creates a log entry
log(){
while read data
do
echo $(getDate) - $data>>$ARELLE_LOG
done
}


# creates the current timestamp
getDate(){
  echo $(date "+%d.%m.%Y %H:%M:%S")
}


case "$1" in
  start)
        touch $ARELLE_LOG
        cat /dev/null>$ARELLE_LOG


        MSG=`python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075 2>&1 &`
        RESPONSE=$?


        echo $MSG | log
        echo $RESPONSE | log
        ;;
  stop)
        echo "not implemented yet"
        ;;
  restart)
        echo "not implemented yet"
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac


exit 0


Using this i could find out that you were right concerning the paths. When starting the server with this script, i get

17.06.2013 17:14:35 - /etc/init.d/rc3.d/S10arelle: line 42: python3: command not found

When executing this in the console it works.

whereis python3

gives me

whereis python3
python3: /usr/local/bin/python3.2 /usr/local/bin/python3 /usr/local/bin/python3.2m-config /usr/local/bin/python3.2m /usr/local/bin/python3.2-config /usr/local/lib/python3.2

So i’ve changed the command used in the script mentioned at the top of this post

MSG=`python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075 2>&1 &`

to

MSG=`/usr/local/bin/python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075 2>&1 &`

When i execute the script in the console using

./arelle

i get no feedback on the console and the script does not end. It would be great if you could give me a hint what is wrong.

Best regards,

Moe

My only suggestion was to call python3 with it’s full path. But you changed a lot more then and made it more complicated in my opinion… What happens nopw is IMHO that

MSG=`/usr/local/bin/python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075 2>&1 &`

Works as you inteneded. But as this is something running in the background and MSG is only filled with the results of the finished command, MSG is not filled and the script hangs until the background job is finished (when this works at all, I never tried to catch the output of a background run in the scriptthat starts that background job in this way).

Just leave out that MSG= and make it a normal statement.

(BTW when you ever want to use this construct again, my advice would be to use $( ) instead. Much better to read. I had to read this line of code again and again reading ’ ’ instead of

And I want to add that you could also use startproc to start the server.
That’s how it’s normally done in openSUSE’s init scripts AFAIK.

It will then be started in the background (so you can omit the ‘&’) and only if it is not already running.
You can specify the ‘-u user’ option to run it as a user different than root.
And with the ‘-l log_file’ option the output (stdout and stderr) will be redirected to log_file.

So use something like:

startproc -u arelle -l /var/log/arelle.log /usr/local/bin/python3 /opt/Arelle/arelleCmdLine.py --webserver localhost:8075

See also “man startproc”.

Additionally you can then use “checkproc” to see if it is running and “killproc” to stop it.

On 2013-06-17 17:36, MoeZarella wrote:

> Yes, i did but i did not finish testing while writing the post you
> refer to. But now i am so here are my results :wink: Since i do not know how
> to log events in init scripts as it should be done,

man logger.

Example:


logger -t boot.local -p syslog.warn "Booting the system"

More:


grep logger /etc/init.d/*


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I think this advice is very sound and worth trying out.

Awesome! This works! Thank you very much for this solution! And also thank you to all others for your ideas and possible improvements!

On 06/17/2013 09:36 PM, MoeZarella wrote:
> thank you to all others for your ideas and possible improvements!

again i suggest you retire the unpatched and unsupported and too
easily kracked 11.1 system.


dd

Please stop that. One short notice to people should be more then enough.

I have a good contribution to your next nightmare: I am running a 10.3 system.

On 06/18/2013 10:16 AM, hcvv wrote:
> Please stop that. One short notice to people should be more then
> enough.
>
> I have a good contribution to your next nightmare: I am running a 10.3
> system.

i guess we all ought to have one then.


dd