RedHat init.d script will not start with service after stop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have the service script below, which calls a shell script. We changed something in the script When I run the shell script directly, everything works fine. When I restart the servER, everything works fine. If I call sudo service my-service stop then sudo service my-service start, it will stop, but never start again. It says systemctl OK, but a process never kicks off, and no logs are ever written from the shell script. Even if I call sudo /etc/init.d/my-service it won't start. Again, mind you, this will start fine automatically on restart of the server. Any thoughts on what could be the problem, or how to get better logging from this failed start?



#!/bin/bash
#
# my-service
#
# chkconfig: 345 84 15
# description: Start up the My Service process.
# config: /etc/sysconfig/my-service
# processname: java

# Source function library.
. /etc/init.d/functions

# Loading the configuration parameters.
if [ -f /etc/sysconfig/my-service ]; then
source /etc/sysconfig/my-service
fi

RETVAL=0

case "$1" in
start)
if [ -f /opt/my-service/latest/bin/my-service-start.sh ];
then
logger -s "Starting My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/my-service
fi
;;
stop)
if [ -f /opt/my-service/latest/bin/my-service-stop.sh ];
then
logger -s "Stopping My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-stop.sh
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/my-service
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 start"
exit 1
;;
esac

exit $RETVAL









share|improve this question














bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
    – user1700494
    Apr 19 '16 at 10:43














up vote
1
down vote

favorite












I have the service script below, which calls a shell script. We changed something in the script When I run the shell script directly, everything works fine. When I restart the servER, everything works fine. If I call sudo service my-service stop then sudo service my-service start, it will stop, but never start again. It says systemctl OK, but a process never kicks off, and no logs are ever written from the shell script. Even if I call sudo /etc/init.d/my-service it won't start. Again, mind you, this will start fine automatically on restart of the server. Any thoughts on what could be the problem, or how to get better logging from this failed start?



#!/bin/bash
#
# my-service
#
# chkconfig: 345 84 15
# description: Start up the My Service process.
# config: /etc/sysconfig/my-service
# processname: java

# Source function library.
. /etc/init.d/functions

# Loading the configuration parameters.
if [ -f /etc/sysconfig/my-service ]; then
source /etc/sysconfig/my-service
fi

RETVAL=0

case "$1" in
start)
if [ -f /opt/my-service/latest/bin/my-service-start.sh ];
then
logger -s "Starting My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/my-service
fi
;;
stop)
if [ -f /opt/my-service/latest/bin/my-service-stop.sh ];
then
logger -s "Stopping My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-stop.sh
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/my-service
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 start"
exit 1
;;
esac

exit $RETVAL









share|improve this question














bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
    – user1700494
    Apr 19 '16 at 10:43












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have the service script below, which calls a shell script. We changed something in the script When I run the shell script directly, everything works fine. When I restart the servER, everything works fine. If I call sudo service my-service stop then sudo service my-service start, it will stop, but never start again. It says systemctl OK, but a process never kicks off, and no logs are ever written from the shell script. Even if I call sudo /etc/init.d/my-service it won't start. Again, mind you, this will start fine automatically on restart of the server. Any thoughts on what could be the problem, or how to get better logging from this failed start?



#!/bin/bash
#
# my-service
#
# chkconfig: 345 84 15
# description: Start up the My Service process.
# config: /etc/sysconfig/my-service
# processname: java

# Source function library.
. /etc/init.d/functions

# Loading the configuration parameters.
if [ -f /etc/sysconfig/my-service ]; then
source /etc/sysconfig/my-service
fi

RETVAL=0

case "$1" in
start)
if [ -f /opt/my-service/latest/bin/my-service-start.sh ];
then
logger -s "Starting My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/my-service
fi
;;
stop)
if [ -f /opt/my-service/latest/bin/my-service-stop.sh ];
then
logger -s "Stopping My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-stop.sh
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/my-service
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 start"
exit 1
;;
esac

exit $RETVAL









share|improve this question













I have the service script below, which calls a shell script. We changed something in the script When I run the shell script directly, everything works fine. When I restart the servER, everything works fine. If I call sudo service my-service stop then sudo service my-service start, it will stop, but never start again. It says systemctl OK, but a process never kicks off, and no logs are ever written from the shell script. Even if I call sudo /etc/init.d/my-service it won't start. Again, mind you, this will start fine automatically on restart of the server. Any thoughts on what could be the problem, or how to get better logging from this failed start?



#!/bin/bash
#
# my-service
#
# chkconfig: 345 84 15
# description: Start up the My Service process.
# config: /etc/sysconfig/my-service
# processname: java

# Source function library.
. /etc/init.d/functions

# Loading the configuration parameters.
if [ -f /etc/sysconfig/my-service ]; then
source /etc/sysconfig/my-service
fi

RETVAL=0

case "$1" in
start)
if [ -f /opt/my-service/latest/bin/my-service-start.sh ];
then
logger -s "Starting My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/my-service
fi
;;
stop)
if [ -f /opt/my-service/latest/bin/my-service-stop.sh ];
then
logger -s "Stopping My Service"
/bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-stop.sh
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/my-service
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 start"
exit 1
;;
esac

exit $RETVAL






rhel init.d chkconfig






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 4 '14 at 20:00









Spencer Kormos

1064




1064





bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community♦ 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.













  • Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
    – user1700494
    Apr 19 '16 at 10:43
















  • Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
    – user1700494
    Apr 19 '16 at 10:43















Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
– user1700494
Apr 19 '16 at 10:43




Did you ensure that /var/lock/subsys/my-service is removed after you stop the service?
– user1700494
Apr 19 '16 at 10:43










1 Answer
1






active

oldest

votes

















up vote
0
down vote













"We changed something in the script"



There is not enough information to authoritatively answer this question, since the contents of my-service-start.sh and my-service-stop.sh are a mystery.



Assuming everything you have said is true, then the case is that my-service-start.sh does not function as intended, once my-service-start.sh and my-service-stop.sh have both already been run. Even though it works fine at the first startup. This means something is altered after the scripts have been run. Things are not the same as they were when the start script ran successfully. Maybe a port your start script needs is still tied up.



I suggest looking into PID file handling to stop your script from potentially stepping on itself, and analyse your start/stop scripts for what is being altered. Try adding some error handling to your start script and see if that helps you isolate the problem.






share|improve this answer






















  • What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
    – Spencer Kormos
    Nov 4 '14 at 20:21










  • In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
    – Spencer Kormos
    Nov 4 '14 at 20:23











  • A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
    – Spencer Kormos
    Nov 4 '14 at 20:25










  • Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
    – Baazigar
    Nov 4 '14 at 20:35










  • The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
    – Spencer Kormos
    Nov 4 '14 at 20:50











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f165957%2fredhat-init-d-script-will-not-start-with-service-after-stop%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













"We changed something in the script"



There is not enough information to authoritatively answer this question, since the contents of my-service-start.sh and my-service-stop.sh are a mystery.



Assuming everything you have said is true, then the case is that my-service-start.sh does not function as intended, once my-service-start.sh and my-service-stop.sh have both already been run. Even though it works fine at the first startup. This means something is altered after the scripts have been run. Things are not the same as they were when the start script ran successfully. Maybe a port your start script needs is still tied up.



I suggest looking into PID file handling to stop your script from potentially stepping on itself, and analyse your start/stop scripts for what is being altered. Try adding some error handling to your start script and see if that helps you isolate the problem.






share|improve this answer






















  • What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
    – Spencer Kormos
    Nov 4 '14 at 20:21










  • In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
    – Spencer Kormos
    Nov 4 '14 at 20:23











  • A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
    – Spencer Kormos
    Nov 4 '14 at 20:25










  • Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
    – Baazigar
    Nov 4 '14 at 20:35










  • The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
    – Spencer Kormos
    Nov 4 '14 at 20:50















up vote
0
down vote













"We changed something in the script"



There is not enough information to authoritatively answer this question, since the contents of my-service-start.sh and my-service-stop.sh are a mystery.



Assuming everything you have said is true, then the case is that my-service-start.sh does not function as intended, once my-service-start.sh and my-service-stop.sh have both already been run. Even though it works fine at the first startup. This means something is altered after the scripts have been run. Things are not the same as they were when the start script ran successfully. Maybe a port your start script needs is still tied up.



I suggest looking into PID file handling to stop your script from potentially stepping on itself, and analyse your start/stop scripts for what is being altered. Try adding some error handling to your start script and see if that helps you isolate the problem.






share|improve this answer






















  • What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
    – Spencer Kormos
    Nov 4 '14 at 20:21










  • In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
    – Spencer Kormos
    Nov 4 '14 at 20:23











  • A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
    – Spencer Kormos
    Nov 4 '14 at 20:25










  • Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
    – Baazigar
    Nov 4 '14 at 20:35










  • The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
    – Spencer Kormos
    Nov 4 '14 at 20:50













up vote
0
down vote










up vote
0
down vote









"We changed something in the script"



There is not enough information to authoritatively answer this question, since the contents of my-service-start.sh and my-service-stop.sh are a mystery.



Assuming everything you have said is true, then the case is that my-service-start.sh does not function as intended, once my-service-start.sh and my-service-stop.sh have both already been run. Even though it works fine at the first startup. This means something is altered after the scripts have been run. Things are not the same as they were when the start script ran successfully. Maybe a port your start script needs is still tied up.



I suggest looking into PID file handling to stop your script from potentially stepping on itself, and analyse your start/stop scripts for what is being altered. Try adding some error handling to your start script and see if that helps you isolate the problem.






share|improve this answer














"We changed something in the script"



There is not enough information to authoritatively answer this question, since the contents of my-service-start.sh and my-service-stop.sh are a mystery.



Assuming everything you have said is true, then the case is that my-service-start.sh does not function as intended, once my-service-start.sh and my-service-stop.sh have both already been run. Even though it works fine at the first startup. This means something is altered after the scripts have been run. Things are not the same as they were when the start script ran successfully. Maybe a port your start script needs is still tied up.



I suggest looking into PID file handling to stop your script from potentially stepping on itself, and analyse your start/stop scripts for what is being altered. Try adding some error handling to your start script and see if that helps you isolate the problem.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 17 at 14:03









Debian_yadav

8343622




8343622










answered Nov 4 '14 at 20:17









Baazigar

52428




52428











  • What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
    – Spencer Kormos
    Nov 4 '14 at 20:21










  • In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
    – Spencer Kormos
    Nov 4 '14 at 20:23











  • A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
    – Spencer Kormos
    Nov 4 '14 at 20:25










  • Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
    – Baazigar
    Nov 4 '14 at 20:35










  • The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
    – Spencer Kormos
    Nov 4 '14 at 20:50

















  • What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
    – Spencer Kormos
    Nov 4 '14 at 20:21










  • In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
    – Spencer Kormos
    Nov 4 '14 at 20:23











  • A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
    – Spencer Kormos
    Nov 4 '14 at 20:25










  • Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
    – Baazigar
    Nov 4 '14 at 20:35










  • The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
    – Spencer Kormos
    Nov 4 '14 at 20:50
















What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
– Spencer Kormos
Nov 4 '14 at 20:21




What I meant here is that if I alter anything in the start script, the init.d service fails to start. The shell scripts continue to work when run directly, without any issues, and without any port stepping. Logging exists in the shell scripts, the service just seems to NEVER call the shell script, and there is ZERO logging from the service to indicate that the shell script has been run, or what the error is.
– Spencer Kormos
Nov 4 '14 at 20:21












In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
– Spencer Kormos
Nov 4 '14 at 20:23





In fact, if I run the command /bin/su -p -s /bin/sh myserviceuser /opt/my-service/latest/bin/my-service-start.sh "my-service" indeed runs, and logs and works as expected. The question is whether I missed a step in how the above script is written, the services it uses to act as a service, and whether something needs to be called when a slight modification is made to the target scripts.
– Spencer Kormos
Nov 4 '14 at 20:23













A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
– Spencer Kormos
Nov 4 '14 at 20:25




A pointer on what logging to add to the service script, and where to look for said logging would be appreciated. There seems to be no output other than "OK" from systemctl, which is obviously not the case.
– Spencer Kormos
Nov 4 '14 at 20:25












Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
– Baazigar
Nov 4 '14 at 20:35




Is it logging 'Starting my service' or 'Stopping my service'? logger should be writing to /var/log/messages or /var/log/syslog. Since your script works fine when you run the command, maybe you don't need all that at the top with the source function library and configuration parameters. I would aim at making the init as simple as possible and make your start/stop scripts do the rest.
– Baazigar
Nov 4 '14 at 20:35












The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
– Spencer Kormos
Nov 4 '14 at 20:50





The init script works fine initially, but the logger tip is a good one. I'll try to modify and see what the result might be. Thanks.
– Spencer Kormos
Nov 4 '14 at 20:50


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f165957%2fredhat-init-d-script-will-not-start-with-service-after-stop%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay