Running a php file from init
up vote
0
down vote
favorite
I am trying to run a php script from init.d in centos 6.9, when I exit the terminal from which I started the service the application stops, and always the status of the application shows as stopped, even though it is running.
#!/bin/sh
#
# arrbot This shell script takes care of starting and stopping
# the arbbot
#
# chkconfig: - 65 20
# description: arbbot trader.
# processname: arbbot
# Required-Start: $network $syslog $mysqld
# Required-Stop: $network $syslog $mysqld
# Short-Description: start and stop arbbot server
# Description: arbbot trader
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
NAME=arbbot
DESC="arbbot trader"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php5"
WORK_DIRECTORY="/var/www/arbbot/"
DAEMON_OPTS="/var/www/arbbot/main.php"
ARBDIR="/var/www/arbbot"
ARBBOT="exec ${DAEMON} ${DAEMON_OPTS} > ${LOGFILE} 2>&1 > NULL"
LOCK="/var/lock/subsys/arbbot"
start() {
echo -n "Starting ${DESC}: "
cd "${WORK_DIRECTORY}"
$ARBBOT
RETVAL=$?
[ $RETVAL -eq 0 ] && touch -- "$LOCK"
return $RETVAL
}
stop() {
echo -n "Shutting down arbbot: "
killproc $ARBBOT
rm -f $LOCK
return
}
restart() {
stop
start
}
reload() {
restart
}
case "$1" in
start)
start
echo "$NAME."
;;
stop)
stop
echo "$NAME."
;;
status)
status ARBBOT
RETVAL=$?
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: {start|stop|status|reload|restart[|probe]"
exit 1
;;
esac
exit $RETVAL
linux php sysvinit php5
add a comment |
up vote
0
down vote
favorite
I am trying to run a php script from init.d in centos 6.9, when I exit the terminal from which I started the service the application stops, and always the status of the application shows as stopped, even though it is running.
#!/bin/sh
#
# arrbot This shell script takes care of starting and stopping
# the arbbot
#
# chkconfig: - 65 20
# description: arbbot trader.
# processname: arbbot
# Required-Start: $network $syslog $mysqld
# Required-Stop: $network $syslog $mysqld
# Short-Description: start and stop arbbot server
# Description: arbbot trader
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
NAME=arbbot
DESC="arbbot trader"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php5"
WORK_DIRECTORY="/var/www/arbbot/"
DAEMON_OPTS="/var/www/arbbot/main.php"
ARBDIR="/var/www/arbbot"
ARBBOT="exec ${DAEMON} ${DAEMON_OPTS} > ${LOGFILE} 2>&1 > NULL"
LOCK="/var/lock/subsys/arbbot"
start() {
echo -n "Starting ${DESC}: "
cd "${WORK_DIRECTORY}"
$ARBBOT
RETVAL=$?
[ $RETVAL -eq 0 ] && touch -- "$LOCK"
return $RETVAL
}
stop() {
echo -n "Shutting down arbbot: "
killproc $ARBBOT
rm -f $LOCK
return
}
restart() {
stop
start
}
reload() {
restart
}
case "$1" in
start)
start
echo "$NAME."
;;
stop)
stop
echo "$NAME."
;;
status)
status ARBBOT
RETVAL=$?
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: {start|stop|status|reload|restart[|probe]"
exit 1
;;
esac
exit $RETVAL
linux php sysvinit php5
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to run a php script from init.d in centos 6.9, when I exit the terminal from which I started the service the application stops, and always the status of the application shows as stopped, even though it is running.
#!/bin/sh
#
# arrbot This shell script takes care of starting and stopping
# the arbbot
#
# chkconfig: - 65 20
# description: arbbot trader.
# processname: arbbot
# Required-Start: $network $syslog $mysqld
# Required-Stop: $network $syslog $mysqld
# Short-Description: start and stop arbbot server
# Description: arbbot trader
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
NAME=arbbot
DESC="arbbot trader"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php5"
WORK_DIRECTORY="/var/www/arbbot/"
DAEMON_OPTS="/var/www/arbbot/main.php"
ARBDIR="/var/www/arbbot"
ARBBOT="exec ${DAEMON} ${DAEMON_OPTS} > ${LOGFILE} 2>&1 > NULL"
LOCK="/var/lock/subsys/arbbot"
start() {
echo -n "Starting ${DESC}: "
cd "${WORK_DIRECTORY}"
$ARBBOT
RETVAL=$?
[ $RETVAL -eq 0 ] && touch -- "$LOCK"
return $RETVAL
}
stop() {
echo -n "Shutting down arbbot: "
killproc $ARBBOT
rm -f $LOCK
return
}
restart() {
stop
start
}
reload() {
restart
}
case "$1" in
start)
start
echo "$NAME."
;;
stop)
stop
echo "$NAME."
;;
status)
status ARBBOT
RETVAL=$?
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: {start|stop|status|reload|restart[|probe]"
exit 1
;;
esac
exit $RETVAL
linux php sysvinit php5
I am trying to run a php script from init.d in centos 6.9, when I exit the terminal from which I started the service the application stops, and always the status of the application shows as stopped, even though it is running.
#!/bin/sh
#
# arrbot This shell script takes care of starting and stopping
# the arbbot
#
# chkconfig: - 65 20
# description: arbbot trader.
# processname: arbbot
# Required-Start: $network $syslog $mysqld
# Required-Stop: $network $syslog $mysqld
# Short-Description: start and stop arbbot server
# Description: arbbot trader
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
NAME=arbbot
DESC="arbbot trader"
LOGFILE="/var/log/${NAME}.log"
DAEMON="/usr/bin/php5"
WORK_DIRECTORY="/var/www/arbbot/"
DAEMON_OPTS="/var/www/arbbot/main.php"
ARBDIR="/var/www/arbbot"
ARBBOT="exec ${DAEMON} ${DAEMON_OPTS} > ${LOGFILE} 2>&1 > NULL"
LOCK="/var/lock/subsys/arbbot"
start() {
echo -n "Starting ${DESC}: "
cd "${WORK_DIRECTORY}"
$ARBBOT
RETVAL=$?
[ $RETVAL -eq 0 ] && touch -- "$LOCK"
return $RETVAL
}
stop() {
echo -n "Shutting down arbbot: "
killproc $ARBBOT
rm -f $LOCK
return
}
restart() {
stop
start
}
reload() {
restart
}
case "$1" in
start)
start
echo "$NAME."
;;
stop)
stop
echo "$NAME."
;;
status)
status ARBBOT
RETVAL=$?
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: {start|stop|status|reload|restart[|probe]"
exit 1
;;
esac
exit $RETVAL
linux php sysvinit php5
linux php sysvinit php5
edited Nov 25 at 14:58
Rui F Ribeiro
38.3k1475126
38.3k1475126
asked Feb 13 at 21:49
Som
83
83
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09
add a comment |
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09
add a comment |
2 Answers
2
active
oldest
votes
up vote
-1
down vote
accepted
I suggest you to read Run php script as daemon process
.
Also, more detailed description about writing php daemon like original system daemons - How to write a PHP Daemon.
add a comment |
up vote
0
down vote
There are a lot of features of daemon which do not apply to other process. It needs to close its stdout and stdin, and it needs to dissociate from the controlling process, and its needs to have its cwd set to root (amongst other things). There are minimal daemons which can act as a controlling process for running normal processes as if they were daemons - e.g. daemonize
You also may need custom signal handling and (if you want any dianostic/audit capability) logging capability.
However with the POSIX extensions, all the required functions are exposed - so you can setsid() and fork() from within your own code - or even just download some pre-cooked php code to do all this for you.
BEWARE: there are a lot of people publishing code and advice on the internet which is wrong - but they found it worked for them - the code I've linked above is one of the better implementations.
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
accepted
I suggest you to read Run php script as daemon process
.
Also, more detailed description about writing php daemon like original system daemons - How to write a PHP Daemon.
add a comment |
up vote
-1
down vote
accepted
I suggest you to read Run php script as daemon process
.
Also, more detailed description about writing php daemon like original system daemons - How to write a PHP Daemon.
add a comment |
up vote
-1
down vote
accepted
up vote
-1
down vote
accepted
I suggest you to read Run php script as daemon process
.
Also, more detailed description about writing php daemon like original system daemons - How to write a PHP Daemon.
I suggest you to read Run php script as daemon process
.
Also, more detailed description about writing php daemon like original system daemons - How to write a PHP Daemon.
answered Feb 13 at 22:33
Yurij Goncharuk
2,3132521
2,3132521
add a comment |
add a comment |
up vote
0
down vote
There are a lot of features of daemon which do not apply to other process. It needs to close its stdout and stdin, and it needs to dissociate from the controlling process, and its needs to have its cwd set to root (amongst other things). There are minimal daemons which can act as a controlling process for running normal processes as if they were daemons - e.g. daemonize
You also may need custom signal handling and (if you want any dianostic/audit capability) logging capability.
However with the POSIX extensions, all the required functions are exposed - so you can setsid() and fork() from within your own code - or even just download some pre-cooked php code to do all this for you.
BEWARE: there are a lot of people publishing code and advice on the internet which is wrong - but they found it worked for them - the code I've linked above is one of the better implementations.
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
add a comment |
up vote
0
down vote
There are a lot of features of daemon which do not apply to other process. It needs to close its stdout and stdin, and it needs to dissociate from the controlling process, and its needs to have its cwd set to root (amongst other things). There are minimal daemons which can act as a controlling process for running normal processes as if they were daemons - e.g. daemonize
You also may need custom signal handling and (if you want any dianostic/audit capability) logging capability.
However with the POSIX extensions, all the required functions are exposed - so you can setsid() and fork() from within your own code - or even just download some pre-cooked php code to do all this for you.
BEWARE: there are a lot of people publishing code and advice on the internet which is wrong - but they found it worked for them - the code I've linked above is one of the better implementations.
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
add a comment |
up vote
0
down vote
up vote
0
down vote
There are a lot of features of daemon which do not apply to other process. It needs to close its stdout and stdin, and it needs to dissociate from the controlling process, and its needs to have its cwd set to root (amongst other things). There are minimal daemons which can act as a controlling process for running normal processes as if they were daemons - e.g. daemonize
You also may need custom signal handling and (if you want any dianostic/audit capability) logging capability.
However with the POSIX extensions, all the required functions are exposed - so you can setsid() and fork() from within your own code - or even just download some pre-cooked php code to do all this for you.
BEWARE: there are a lot of people publishing code and advice on the internet which is wrong - but they found it worked for them - the code I've linked above is one of the better implementations.
There are a lot of features of daemon which do not apply to other process. It needs to close its stdout and stdin, and it needs to dissociate from the controlling process, and its needs to have its cwd set to root (amongst other things). There are minimal daemons which can act as a controlling process for running normal processes as if they were daemons - e.g. daemonize
You also may need custom signal handling and (if you want any dianostic/audit capability) logging capability.
However with the POSIX extensions, all the required functions are exposed - so you can setsid() and fork() from within your own code - or even just download some pre-cooked php code to do all this for you.
BEWARE: there are a lot of people publishing code and advice on the internet which is wrong - but they found it worked for them - the code I've linked above is one of the better implementations.
answered Feb 13 at 23:11
symcbean
2,26411121
2,26411121
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
add a comment |
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
… including advice like this answer about what dæmons need to do, which was first noted as wrong advice by IBM in 1995. Ali Erdinç Köroglu that you hyperlink to has a mention in the systemd House of Horror. The idea that one can "daemonize" from an interactive login session to a context outwith it grew to be a fallacy after the 1980s.
– JdeBP
Feb 14 at 8:19
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
If the right answer is systemd then we're all in trouble.
– symcbean
Feb 14 at 13:23
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f423991%2frunning-a-php-file-from-init%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It starts a application and keeps on running, like a server. "does it take an infinitely long time to run? " Yes it keeps on running printing messages to the console.
– Som
Feb 13 at 22:17
yes, it does run like that. But the result is not different.
– Som
Feb 13 at 22:24
again no changes. Thanks for your help,
– Som
Feb 13 at 22:47
Try to use 'nohup' as I suggest. It's protect your script from stopping signals after hangup happened (logout from terminal).
– Yurij Goncharuk
Feb 13 at 23:08
Yes thanks , I am trying it.
– Som
Feb 13 at 23:09