custom init script and status exit codes

659 views
Skip to first unread message

florian....@bt.com

unread,
Jan 14, 2010, 4:17:02 AM1/14/10
to puppet...@googlegroups.com, sven....@bt.com
Hello,
we are running a custom ssh server on another port than the original
sshd on all of our hosts. We use puppet to roll out this configuration.
It is just creating a symbolic link to the original sshd and does copy
its custom config file and its own init script. This works on all our
different operating systems (Solaris 8, 9, 10, Debian 4, 5 and Red Hat
4, 5).

The problem is on Debian puppet is not able to handle the exit codes of
this custom init script the right way. This is a part of my manifest:

service { btsh:
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
#pattern => "/opt/BTsh/bin/btsh",
#restart => "/etc/init.d/btsh restart",
#stop => "/etc/init.d/btsh stop",
#start => "/etc/init.d/btsh start",
subscribe => File [ "/opt/BTsh/conf/btsh_config"
],
require => Exec [ "/bin/ln -s /usr/sbin/sshd
/opt/BTsh/bin/btsh" ],
#require => Service [ "sshd" ],
require => $os ? {
RedHat => Package ["openssh"],
Debian => Package ["ssh"]
},
}

The init script does exit with code 0 if the process is running and with
exit code 3 if the process is not running.

#> /etc/init.d/btsh status; echo $?
btsh is running.
0

But running puppetd -td shows me these lines:

debug: Service[btsh](provider=debian): Executing 'ps -ef'
debug: Service[btsh](provider=debian): PID is 24079
debug: Puppet::Type::Service::ProviderDebian: Executing
'/usr/sbin/update-rc.d -n -f btsh remove'
notice: //Node[defr1glvnms31]/ssh/Service[btsh]: Triggering 'refresh'
from 4 dependencies
debug: Service[btsh](provider=debian): Executing 'ps -ef'
debug: Service[btsh](provider=debian): PID is 24079
debug: Service[btsh](provider=debian): Executing '/etc/init.d/btsh
restart'
err: //Node[defr1glvnms31]/ssh/Service[btsh]: Failed to call refresh on
Service[btsh]: Could not restart Service[btsh]: Execution of
'/etc/init.d/btsh restart' returned 1: at
/pkg/nagios/puppet/manifests/classes/ssh.pp:74

If I enable hasstatus I get these messages:

debug: Service[btsh](provider=debian): Executing '/etc/init.d/btsh
status'
debug: Puppet::Type::Service::ProviderDebian: Executing
'/usr/sbin/update-rc.d -n -f btsh remove'
debug: //Node[defr1glvnms31]/ssh/Service[btsh]: Changing ensure
debug: //Node[defr1glvnms31]/ssh/Service[btsh]: 1 change(s)
debug: Service[btsh](provider=debian): Executing '/etc/init.d/btsh
start'
err: //Node[defr1glvnms31]/ssh/Service[btsh]/ensure: change from stopped
to running failed: Could not start Service[btsh]: Execution of
'/etc/init.d/btsh start' returned 1: at
/pkg/nagios/puppet/manifests/classes/ssh.pp:74
notice: //Node[defr1glvnms31]/ssh/Service[btsh]: Triggering 'refresh'
from 4 dependencies
debug: Service[btsh](provider=debian): Executing '/etc/init.d/btsh
status'
debug: //Node[defr1glvnms31]/ssh/Service[btsh]: Skipping restart;
service is not running


Does naybody know what is wrong with my init script? The original ssh
init script is working fine but I do not want to use this one because it
is Debian specific and I want one script on all operating systems.

Thank you for your help.

Regards,
Flo

Silviu Paragina

unread,
Jan 14, 2010, 5:45:57 AM1/14/10
to puppet...@googlegroups.com
I'm guessing you did
/etc/init.d/btsh start; echo $?
and it works fine. (also for stop and restart)

What you should do is add some debugging code. I think echo debug stuff
>2 would be just enough, if not write in a separate file (for execs is
enough).
The most likely cause for the script to work on command line and not in
puppet is environment, so you should start by checking the environment
variable (especially path) and the current directory.

Other than there is a 99% chance that the script is at fault, and not
puppet.

Silviu

> Regards,err: //Node[defr1glvnms31]/ssh/Service[btsh]/ensure: change from stopped

florian....@bt.com

unread,
Jan 14, 2010, 7:45:51 AM1/14/10
to puppet...@googlegroups.com
Hello Silviu,
thank you for your fast answer. The problem is fixed now. The script was
starting with some comment and not "#!/bin/sh". On Red Hat this was no
problem but on Debian it did not work.

Regards,
Florian

Reply all
Reply to author
Forward
0 new messages