thankyou
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!

Author Topic: Fully Debian integrated start-stop script  (Read 26694 times)

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Fully Debian integrated start-stop script
« on: March 25, 2009, 07:31:04 PM »
« Last Edit: May 29, 2009, 07:22:04 PM by Courgette »

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #1 on: December 05, 2009, 09:23:45 PM »
THX  :D
Comment
You have 1 fi too much :( Line 47.


Your first step, for starters:
Explations
Go to the folder;
Make a new file named b3;
Go into a editor like vi, in this example nano;
Copy above code in Windows;
!Important just Right Mouse Click to past it into Nano editor;
Save it, press ctrl+x choose Y(es). Confirm by press the Enter key;
Set the good rights;

In Commands
cd /etc/init.d
sudo touch b3 (you can also skip this step, and just directly go to nano)
sudo nano b3
chmod +x b3


However its not working :(
Quote
*user*@server:~$ sudo /etc/init.d/b3 start
 * Starting BigBrotherBot b3                                                                                                                          [ OK ]
*user*@server:~$ sudo /etc/init.d/b3 stop
 * Stopping BigBrotherBot b3                                                                                                                                 start-stop-daemon: warning: failed to kill 1502: No such process
                                                                        

And

Quote
*user*@server:~$ sudo update-rc.d b3 defaults
update-rc.d: warning: b3 stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (S 0 1 6)
 Adding system startup for /etc/init.d/b3 ...
   /etc/rc0.d/K20b3 -> ../init.d/b3
   /etc/rc1.d/K20b3 -> ../init.d/b3
   /etc/rc6.d/K20b3 -> ../init.d/b3
   /etc/rc2.d/S20b3 -> ../init.d/b3
   /etc/rc3.d/S20b3 -> ../init.d/b3
   /etc/rc4.d/S20b3 -> ../init.d/b3
   /etc/rc5.d/S20b3 -> ../init.d/b3
« Last Edit: December 05, 2009, 10:17:02 PM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: Fully Debian integrated start-stop script
« Reply #2 on: December 06, 2009, 01:16:52 AM »
user*@server:~$ sudo /etc/init.d/b3 start
 * Starting BigBrotherBot b3                                                                                                                          [ OK ]
*user*@server:~$ sudo /etc/init.d/b3 stop
 * Stopping BigBrotherBot b3                                                                                                                                 start-stop-daemon: warning: failed to kill 1502: No such process
If your B3 config is incorrect and the bot fails to start up. Then it would make sence that the stop command find no process to kill. Can you make sure the bot was started ?

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #3 on: December 06, 2009, 01:56:52 AM »
First of all, thank you for the fast support.

Second, I'm sure the config is completely right. Because the following is working:
Code: [Select]
python /home/*user*/b3/b3_run.py -c /home/*user*/b3/b3/conf/b3.xml
(NOT as root user)

That works, but I know 100% sure the bot doesn't start with the script above.

EDIT:
Please fix your code, remove line 47:
Code: [Select]
    fi

But its not working as a daemon  :-\
I think here goes something wrong:
Code: [Select]
   start-stop-daemon --start --quiet --chuid $DAEMON_USER:$DAEMON_GROUP --pidfi$
        --background --chdir $B3_BASEDIR --startas $DAEMON -- $DAEMON_ARGS
    return $?

Maybe it will return a zero, but actually it's not started  ???

Need it set quotes before & after the b3_basedir or something? Or must I change DAEMON=`which python` for example? Can I see somewhere a error log?
« Last Edit: December 06, 2009, 02:26:23 AM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: Fully Debian integrated start-stop script
« Reply #4 on: December 06, 2009, 02:39:53 AM »
to investigate further, can you start the script enabling bash debug mode :
Code: [Select]
bash -x /etc/init.d/b3 start
Then you will see if something looks weird with the variables values.

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #5 on: December 06, 2009, 03:03:28 AM »
That returns this:
Code: [Select]
root@server:/home/*user*/b3/b3/conf# bash -x /etc/init.d/b3 start
+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ DESC=BigBrotherBot
+ NAME=b3
+ SCRIPTNAME=/etc/init.d/b3
++ which python
+ DAEMON=/usr/bin/python
+ DAEMON_USER=*user*
+ DAEMON_GROUP=*user*
+ B3_BASEDIR=/home/*user*/b3
+ B3_CONFIGFILE=/home/*user*/b3/b3/conf/b3.xml
+ DAEMON_ARGS='/home/*user*/b3/b3_run.py -c /home/*user*/b3/b3/conf/b3.xml'
+ B3_PID_FILE=/var/run/bigbrotherbot/b3.pid
+ '[' '!' -x /usr/bin/python ']'
++ dirname /var/run/bigbrotherbot/b3.pid
+ PIDDIR=/var/run/bigbrotherbot
+ '[' /var/run/bigbrotherbot -a /var/run/bigbrotherbot '!=' /var/run ']'
+ '[' '!' -d /var/run/bigbrotherbot ']'
+ '[' *user* ']'
+ chown *user* /var/run/bigbrotherbot
+ '[' *user* ']'
+ chgrp *user* /var/run/bigbrotherbot
+ . /lib/lsb/init-functions
++ FANCYTTY=
++ '[' -e /etc/lsb-base-logging.sh ']'
++ . /etc/lsb-base-logging.sh
+ case "$1" in
+ log_daemon_msg 'Starting BigBrotherBot' b3
+ '[' -z 'Starting BigBrotherBot' ']'
+ log_use_usplash
+ '[' n = y ']'
+ type usplash_write
+ log_to_console log_daemon_msg 'Starting BigBrotherBot' b3
+ '[' n '!=' y ']'
+ '[' no '!=' yes ']'
++ readlink /proc/self/fd/0
+ stdin=/dev/pts/0
+ '[' /dev/pts/0 '!=' /dev/pts/0 ']'
+ return 0
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ '[' -t 1 ']'
+ '[' xxterm '!=' x ']'
+ '[' xxterm '!=' xdumb ']'
+ '[' -x /usr/bin/tput ']'
+ '[' -x /usr/bin/expr ']'
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ '[' -z ']'
+ FANCYTTY=1
+ case "$FANCYTTY" in
+ true
+ /usr/bin/tput xenl
++ /usr/bin/tput cols
+ COLS=157
+ '[' 157 ']'
+ '[' 157 -gt 6 ']'
++ /usr/bin/expr 157 - 7
+ COL=150
+ printf ' * Starting BigBrotherBot b3       '
 * Starting BigBrotherBot b3       ++ /usr/bin/expr 157 - 1
+ /usr/bin/tput hpa 156
                                                                                                                                                            + printf ' '
 + do_start
+ start-stop-daemon --start --quiet --chuid *user*:*user* --pidfile /var/run/bigbrotherbot/b3.pid --make-pidfile --background --chdir /home/*user*/b3 --startas /usr/bin/python -- /home/*user*/b3/b3_run.py -c /home/*user*/b3/b3/conf/b3.xml
+ return 0
+ case "$?" in
+ log_end_msg 0
+ '[' -z 0 ']'
+ log_use_usplash
+ '[' n = y ']'
+ type usplash_write
+ log_to_console log_end_msg 0
+ '[' n '!=' y ']'
+ '[' no '!=' yes ']'
++ readlink /proc/self/fd/0
+ stdin=/dev/pts/0
+ '[' /dev/pts/0 '!=' /dev/pts/0 ']'
+ return 0
+ '[' 150 ']'
+ '[' -x /usr/bin/tput ']'
+ printf '\r'
+ /usr/bin/tput hpa 150
                                                                                                                                                      + '[' 0 -eq 0 ']'
+ echo '[ OK ]'
[ OK ]
+ return 0
+ :

Its looks OK, right? Strange... Is the daemon auto-quit or destroy?

Quote
I changed my username to *user*.
« Last Edit: December 07, 2009, 10:50:45 PM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: Fully Debian integrated start-stop script
« Reply #6 on: December 06, 2009, 03:13:35 AM »
login as *user*, type :
Code: [Select]
cd /home/*user*/b3
/usr/bin/python /home/*user*/b3/b3_run.py -c /home/*user*/b3/b3/conf/b3.xml

If this works, then I have no clue why the script fails to do take the same actions...

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #7 on: December 06, 2009, 03:22:07 AM »
OK thx, I will try that. Result:

Running  :)
After I deleted the log file, otherwise I get a premission denied.

------

And I also tried this:

Code: [Select]
start-stop-daemon -S -q -c melroy:melroy -p /var/run/bigbrotherbot/b3.pid -m -b -d /home/melroy/b3 -a /usr/bin/python /home/melroy/b3/b3_run.py -c /home/melroy/b3/b3/conf/b3.xml
(updated)

With as result:
Code: [Select]
start-stop-daemon: user `/home/*user*/b3/b3/conf/b3.xml' not found

BUT,
Code: [Select]
nano /home/*user*/b3/b3/conf/b3.xml
IS working...
« Last Edit: December 06, 2009, 03:43:39 AM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: Fully Debian integrated start-stop script
« Reply #8 on: December 06, 2009, 03:25:39 AM »
does your true username (the one you replaced with *user*) contains weird characters like blank characters ?

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #9 on: December 06, 2009, 03:27:45 AM »
ok sorry its just:
melroy

That is my username


And this will result to "....b3.xml not found":
Code: [Select]
start-stop-daemon -S -q -c melroy:melroy -p /var/run/bigbrotherbot/b3.pid -m -b -c -d /home/melroy/b3 -a python /home/melroy/b3/b3_run.py  -c /home/melroy/b3/b3/conf/b3.xml
JoinMyServer.com
Call of Duty 4 Game Servers

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #10 on: December 06, 2009, 03:31:07 AM »
I GOT IT!
You use -c at YOUR program  to get the config file. But.... start-stop-daemon uses also -c parameter!

Quote
  -c|--chuid <name|uid[:group|gid]>
                                change to this user/group before starting
                                  process
JoinMyServer.com
Call of Duty 4 Game Servers

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Re: Fully Debian integrated start-stop script
« Reply #11 on: December 06, 2009, 03:32:20 AM »
There is something wrong with your test. You are using the "-c" option twice. Use the long options in place of the short ones for readability sake.
Code: [Select]
start-stop-daemon -S -q -c melroy:melroy -p /var/run/bigbrotherbot/b3.pid -m -b -c -d /home/melroy/b3 -a python /home/melroy/b3/b3_run.py  -c /home/melroy/b3/b3/conf/b3.xml

also, start-stop-daemon distinguishes its own parameters from the parameters of the program it has to start with the " -- " which are not in your test
« Last Edit: December 06, 2009, 03:34:35 AM by Courgette »

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #12 on: December 06, 2009, 03:34:05 AM »
Yep sorry. It make no differences same error, but again:

Quote
You use -c at YOUR program  to get the config file. But.... start-stop-daemon uses also -c parameter!

Quote
  -c|--chuid <name|uid[:group|gid]>
                                change to this user/group before starting
                                  process


 ::)

This works:
Code: [Select]
sudo start-stop-daemon -S -q -c melroy:melroy -p /var/run/bigbrotherbot/b3.pid -m -b -d /home/melroy/b3 -a /usr/bin/python /home/melroy/b3/b3_run.py
Aleast it's running in the background  ;)

Uhm I see I don't need the:
Code: [Select]
 -c /home/melroy/b3/b3/conf/b3.xml
at the end.
But when I am going to run multiple server (I going to) I think I need to set the conf as parameter.
« Last Edit: December 06, 2009, 04:08:03 AM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #13 on: December 06, 2009, 04:08:21 AM »
UPDATE:  ;D
Find:
Code: shell [Select]
DAEMON_ARGS="$B3_BASEDIR/b3_run.py -c $B3_CONFIGFILE"


Change it to:
Code: shell [Select]
DAEMON_ARGS="$B3_BASEDIR/b3_run.py"


I hope there will be a solution fast.  8)
JoinMyServer.com
Call of Duty 4 Game Servers

Offline danger89

  • Full Member
  • ***
  • Posts: 129
    • JoinMyServer - Game Servers
Re: Fully Debian integrated start-stop script
« Reply #14 on: December 08, 2009, 01:38:06 AM »
I don't What I did wrong, but the daemon looks like its working normal  :D
I still think it as something to do with rights & that config file, I still doesn't know  ???

But I want to update my rc.local again and I get this message:
Quote
sudo update-rc.d rc.local defaults
update-rc.d: warning: rc.local stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (none)
 System start/stop links for /etc/init.d/rc.local already exist.

A warning? And I just want to make a start/stop link again to be sure :S?

EDIT:
I see you need for that last part monit, but its software what you need to install first:
sudo apt-get install monit

Beside that, I need to set startup to 1 in the file /etc/init.d/monit right ? It it correct if I add those 4 lines in /etc/monit/monitrc? Sorry if its sounds noobie  :-[
« Last Edit: December 08, 2009, 01:51:43 AM by danger89 »
JoinMyServer.com
Call of Duty 4 Game Servers

 


Rate this page +1 at Google Search