PDA

View Full Version : chkconfig help



whoa
29th December 2006, 12:37 PM
hallo, i have some trouble adding custom services on start-up. I'm going to put up a half-life server (hlds) on my machine and, as some may know, you would also like to run some application-related commands (i.e. if i would start my server from terminal, i would type ./run_hlds -game cstrike -secure -autoupdate +port 27015 +maxplayers 14 +map de_dust2); how can i add these extra commands with chkconfig? help would be greately appreciated :)

johno12345
29th December 2006, 12:47 PM
you need to create a script in /etc/rc.d/init.d
have a look at the files in there to get an idea of what you are doing first as most of the syntax will be the same for the script you will need to create

johno12345
29th December 2006, 12:49 PM
you could also use xinet.d wrapper
create a file in /etc/xinet.d/
for example /etc/xinet.d/halflife



# default: on
# description: launch half life server

service halflife {
flags = REUSE
socket_type = stream
wait = no
user = root
server = /path/to/binary/run_hlds -game cstrike -secure -autoupdate +port 27015 +maxplayers 14 +map de_dust2
server_args = -5

}



then simply put your command in the server = line
then start xinetd

service start xinetd

chkconfig xinetd on

whoa
29th December 2006, 01:14 PM
thanks for your quick replies! the rc.d/init.d folder files contains a programming language (vb?) that i have no experience with, so ill probably try to start the service with xinetd, but when i run the command service xinetd start, i get the error message service not found :(

johno12345
29th December 2006, 01:36 PM
the "programming language" is simply (or not) bash scripting.

if you just have a look though it you will see a structure. its basically the equivalent of a windows/dos batch file. (just a lot lot better)

you may not have xinetd installed try

yum install xinetd

what also may be an idea is to check the other files in the /etc/xinet.d folder to ensure they all have the line

disable = yes
you don't want to be enabling anything you don't need for security reasons.

let me know how you get on.

whoa
29th December 2006, 02:28 PM
thanks again for a quick reply :)
xinetd wasn't installed, but I think i will try to go with the bash scripting in any case, it seems a bit better (dont know why though :rolleyes: ), so ive made a little bash script, that you maybe can help me correct :p

RETVAL=0
progname="Half-life Dedicated Server 1"

start() {
if [ ! -f /usr/hlds/hlds_run ]; then
echo -n $"Starting $progname"
daemon /usr/hlds/hlds_run -game cstrike -secure -autoupdate +maxplayers 14 +map de_dust2 +port 27015
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /usr/hlds/hlds_run
echo
fi
return $RETVAL
}

stop() {
echo -n $"Stopping $progname"
killproc hlds_run
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /usr/hlds/hlds_run
echo
return $RETVAL
}

restart() { stop start }

case "$1" in
start) start ;;
stop) stop ;;
restart) restart ;;
esac

exit $RETVAL

probably missed something out :)..
one newbie-question: how do i save the file as a shell script (or whatever it is called :p)?

johno12345
29th December 2006, 03:10 PM
at first glance it looks ok...

what are you using to edit the file?

whoa
29th December 2006, 03:18 PM
using gedit :)

johno12345
29th December 2006, 03:20 PM
ok in that case just simply save the file in /etc/rc.d/init.d as the filename you desire ie. halflife

whoa
29th December 2006, 03:33 PM
thanks, works fine but the icon is not the same.. does it matter? :)
got the unexpected end of file error when trying to run, so i changed

restart() { stop start } to
restart() {
stop
start
}
and now no errors show up, in fact nothing shows up (shouldn't it say Starting Half-life Dedicated Server 1?? :confused: ). dosen't seem to work in any case :(

EDIT: Noticed that many shellscripts has included the functions library (. /etc/rc.d/init.d/functions), is it necessary for this script?

johno12345
29th December 2006, 03:40 PM
try opening a terminal and typing
service status halflife

whoa
29th December 2006, 03:42 PM
nothing happens, just a new line :(

whoa
29th December 2006, 03:51 PM
ok, a little update:
tried the service hlds restart command, and it said "Stopping Half-life Dedicated Server 1/etc/init.d/hlds: line 17: killproc: command not found", so i figured it would be best to include the functions library and so i did and now it is behaving a little different... this is the output from service hlds start:
Starting Half-life Dedicated Server 1/bin/bash: /usr/hlds/hlds_run: Filen eller katalogen finns inte
[MISSLYCKADES]
(Filen eller katalogen finns inte is swedish for "the file or folder dosen't exist" and MISSLYCKADES is, as you may have figured out, "failed" :))
this /bin/bash: in front looks a bit odd, maybe the error lies there :)

johno12345
29th December 2006, 04:50 PM
i'm going to have a look at this when i get home this weekend.. I'll set up a similar situation

whoa
29th December 2006, 05:12 PM
ok, thanks alot :)

whoa
29th December 2006, 08:31 PM
UPDATE:
tried running the script with -x flag and here is the output:

+ . /etc/rc.d/init.d/functions
++ TEXTDOMAIN=initscripts
++ umask 022
++ PATH=/sbin:/usr/sbin:/bin:/usr/bin
++ export PATH
++ '[' -z '' ']'
++ COLUMNS=80
++ '[' -z '' ']'
+++ /sbin/consoletype
++ CONSOLETYPE=pty
++ '[' -f /etc/sysconfig/i18n -a -z '' ']'
++ . /etc/profile.d/lang.sh
+++ sourced=0
+++ for langfile in /etc/sysconfig/i18n '$HOME/.i18n'
+++ '[' -f /etc/sysconfig/i18n ']'
+++ . /etc/sysconfig/i18n
++++ LANG=sv_SE.UTF-8
++++ SYSFONT=latarcyrheb-sun16
+++ sourced=1
+++ for langfile in /etc/sysconfig/i18n '$HOME/.i18n'
+++ '[' -f /.i18n ']'
+++ '[' -n '' ']'
+++ '[' 1 = 1 ']'
+++ '[' -n sv_SE.UTF-8 ']'
+++ export LANG
+++ '[' -n '' ']'
+++ unset LC_ADDRESS
+++ '[' -n '' ']'
+++ unset LC_CTYPE
+++ '[' -n '' ']'
+++ unset LC_COLLATE
+++ '[' -n '' ']'
+++ unset LC_IDENTIFICATION
+++ '[' -n '' ']'
+++ unset LC_MEASUREMENT
+++ '[' -n '' ']'
+++ unset LC_MESSAGES
+++ '[' -n '' ']'
+++ unset LC_MONETARY
+++ '[' -n '' ']'
+++ unset LC_NAME
+++ '[' -n '' ']'
+++ unset LC_NUMERIC
+++ '[' -n '' ']'
+++ unset LC_PAPER
+++ '[' -n '' ']'
+++ unset LC_TELEPHONE
+++ '[' -n '' ']'
+++ unset LC_TIME
+++ '[' -n '' ']'
+++ unset LC_ALL
+++ '[' -n '' ']'
+++ unset LANGUAGE
+++ '[' -n '' ']'
+++ unset LINGUAS
+++ '[' -n '' ']'
+++ unset _XKB_CHARSET
++++ /sbin/consoletype
+++ consoletype=pty
+++ '[' -n '' ']'
+++ '[' -n '' ']'
+++ '[' -n sv_SE.UTF-8 ']'
+++ case $LANG in
+++ '[' xterm = linux ']'
+++ unset SYSFONTACM SYSFONT
+++ unset sourced
+++ unset langfile
++ '[' -z '' ']'
++ '[' -f /etc/sysconfig/init ']'
++ . /etc/sysconfig/init
+++ BOOTUP=color
+++ GRAPHICAL=yes
+++ RES_COL=60
+++ MOVE_TO_COL='echo -en \033[60G'
+++ SETCOLOR_SUCCESS='echo -en \033[0;32m'
+++ SETCOLOR_FAILURE='echo -en \033[0;31m'
+++ SETCOLOR_WARNING='echo -en \033[0;33m'
+++ SETCOLOR_NORMAL='echo -en \033[0;39m'
+++ LOGLEVEL=3
+++ PROMPT=yes
+++ AUTOSWAP=no
++ '[' pty = serial ']'
++ '[' color '!=' verbose ']'
++ INITLOG_ARGS=-q
++ __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave \)$/d'
+ RETVAL=0
+ progname='Half-life Dedicated Server 1'
+ case "$1" in
+ start
+ '[' '!' -f /usr/hlds/hlds_run ']'
+ echo -n 'Starting Half-life Dedicated Server 1'
Starting Half-life Dedicated Server 1+ daemon /usr/hlds/hlds_run -game cstrike -secure -autoupdate +maxplayers 14 +map de_dust2 +port 27015
+ local gotbase= force= nicelevel corelimit
+ local pid base= user= nice= bg= pid_file=
+ nicelevel=0
+ '[' /usr/hlds/hlds_run '!=' /usr/hlds/hlds_run ']'
+ '[' -z '' ']'
+ base=hlds_run
+ __pids_var_run hlds_run ''
+ local base=hlds_run
+ local pid_file=/var/run/hlds_run.pid
+ pid=
+ '[' -f /var/run/hlds_run.pid ']'
+ return 3
+ '[' -n '' -a -z '' ']'
+ corelimit='ulimit -S -c 0'
+ '[' -n '' ']'
+ '[' color = verbose -a -z '' ']'
+ '[' -z '' ']'
+ /bin/bash -c 'ulimit -S -c 0 >/dev/null 2>&1 ; /usr/hlds/hlds_run -game cstrike -secure -autoupdate +maxplayers 14 +map de_dust2 +port 27015'
/bin/bash: /usr/hlds/hlds_run: Filen eller katalogen finns inte
+ '[' 127 -eq 0 ']'
+ failure 'uppstart av hlds_run'
+ local rc=1
+ '[' color '!=' verbose -a -z '' ']'
+ echo_failure
+ '[' color = color ']'
+ echo -en '\033[60G'
+ echo -n '['
[+ '[' color = color ']'
+ echo -en '\033[0;31m'
+ echo -n MISSLYCKADES
MISSLYCKADES+ '[' color = color ']'
+ echo -en '\033[0;39m'
+ echo -n ']'
]+ echo -ne '\r'
+ return 1
+ '[' -x /usr/bin/rhgb-client ']'
+ /usr/bin/rhgb-client --details=yes
+ return 1
+ RETVAL=1
+ '[' 1 -eq 0 ']'
+ echo
not sure how to interpret it though :). also i have noticed that the file hlds_run is removed every time i try to run the script..

EDIT: sorry, that was after hlds_run was deleted, here is a new one :)

+ . /etc/rc.d/init.d/functions
++ TEXTDOMAIN=initscripts
++ umask 022
++ PATH=/sbin:/usr/sbin:/bin:/usr/bin
++ export PATH
++ '[' -z '' ']'
++ COLUMNS=80
++ '[' -z '' ']'
+++ /sbin/consoletype
++ CONSOLETYPE=pty
++ '[' -f /etc/sysconfig/i18n -a -z '' ']'
++ . /etc/profile.d/lang.sh
+++ sourced=0
+++ for langfile in /etc/sysconfig/i18n '$HOME/.i18n'
+++ '[' -f /etc/sysconfig/i18n ']'
+++ . /etc/sysconfig/i18n
++++ LANG=sv_SE.UTF-8
++++ SYSFONT=latarcyrheb-sun16
+++ sourced=1
+++ for langfile in /etc/sysconfig/i18n '$HOME/.i18n'
+++ '[' -f /.i18n ']'
+++ '[' -n '' ']'
+++ '[' 1 = 1 ']'
+++ '[' -n sv_SE.UTF-8 ']'
+++ export LANG
+++ '[' -n '' ']'
+++ unset LC_ADDRESS
+++ '[' -n '' ']'
+++ unset LC_CTYPE
+++ '[' -n '' ']'
+++ unset LC_COLLATE
+++ '[' -n '' ']'
+++ unset LC_IDENTIFICATION
+++ '[' -n '' ']'
+++ unset LC_MEASUREMENT
+++ '[' -n '' ']'
+++ unset LC_MESSAGES
+++ '[' -n '' ']'
+++ unset LC_MONETARY
+++ '[' -n '' ']'
+++ unset LC_NAME
+++ '[' -n '' ']'
+++ unset LC_NUMERIC
+++ '[' -n '' ']'
+++ unset LC_PAPER
+++ '[' -n '' ']'
+++ unset LC_TELEPHONE
+++ '[' -n '' ']'
+++ unset LC_TIME
+++ '[' -n '' ']'
+++ unset LC_ALL
+++ '[' -n '' ']'
+++ unset LANGUAGE
+++ '[' -n '' ']'
+++ unset LINGUAS
+++ '[' -n '' ']'
+++ unset _XKB_CHARSET
++++ /sbin/consoletype
+++ consoletype=pty
+++ '[' -n '' ']'
+++ '[' -n '' ']'
+++ '[' -n sv_SE.UTF-8 ']'
+++ case $LANG in
+++ '[' xterm = linux ']'
+++ unset SYSFONTACM SYSFONT
+++ unset sourced
+++ unset langfile
++ '[' -z '' ']'
++ '[' -f /etc/sysconfig/init ']'
++ . /etc/sysconfig/init
+++ BOOTUP=color
+++ GRAPHICAL=yes
+++ RES_COL=60
+++ MOVE_TO_COL='echo -en \033[60G'
+++ SETCOLOR_SUCCESS='echo -en \033[0;32m'
+++ SETCOLOR_FAILURE='echo -en \033[0;31m'
+++ SETCOLOR_WARNING='echo -en \033[0;33m'
+++ SETCOLOR_NORMAL='echo -en \033[0;39m'
+++ LOGLEVEL=3
+++ PROMPT=yes
+++ AUTOSWAP=no
++ '[' pty = serial ']'
++ '[' color '!=' verbose ']'
++ INITLOG_ARGS=-q
++ __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave \)$/d'
+ RETVAL=0
+ progname='Half-life Dedicated Server 1'
+ case "$1" in
+ start
+ '[' '!' -f /usr/hlds/hlds_run ']'
+ return 0
+ exit 0