Запуск PHP скрипта с использованием nohup

Debian / Ubuntu

SysV

nano /etc/init.d/price_parser
chmod +x /etc/init.d/price_parser

#!/bin/sh ### BEGIN INIT INFO # Provides: price_parser # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Stop/start price_parser ### END INIT INFO # Author: Mirocow <mr.mirocow@gmail.com> . /lib/init/vars.sh . /lib/lsb/init-functions PNAME="price_parser" PPATH="/home/some/path/to/app" SCRIPT="/usr/bin/php ./yii some/cotroller/action" PIDFILE="/var/run/${PNAME}.pid" LOCKFILE="/var/lock/${PNAME}" RETVAL=0 start() { echo -n "Starting $PNAME : " if [ -s ${PIDFILE} ]; then RETVAL=1 echo -n "Already running !" echo else cd ${PPATH} && nohup ${SCRIPT} >/dev/null 2>&1 & RETVAL=$? PID=$! [ $RETVAL -eq 0 ] && touch ${LOCKFILE} echo echo $PID > ${PIDFILE} fi } stop() { if [ -s ${PIDFILE} ]; then echo -n "Shutting down ${PNAME} : " kill -9 `cat ${PIDFILE}` RETVAL="$?" if [ $RETVAL -eq 0 ]; then rm -f ${LOCKFILE} rm -f ${PIDFILE} fi else RETVAL=1 echo -n "Already stoped !" echo fi return "$RETVAL" } restart() { echo -n "Restarting ${PNAME} : " stop sleep 2 start } case "$1" in start) start ;; stop) stop ;; status) status ${PNAME} ;; restart) restart ;; *) echo "Usage: $0 {start|stop|status|restart}" ;; esac exit 0

systemd

nano /etc/systemd/system/yii-some-listen.service

[Unit] Description=Yii some-listen After=mysql.service apache2.service Requires= [Service] PIDFile=/var/run/yii-some-listen.pid WorkingDirectory=/home/some/path/to/app ExecStart=/usr/bin/php /home/some/path/to/app/yii some/cotroller/action start >/dev/null 2>&1 ExecStop=/usr/bin/php /home/some/path/to/app/yii some/cotroller/action stop >/dev/null 2>&1 #Restart=always #RestartSec=5 RemainAfterExit=yes User=user Group=www-data [Install] WantedBy=multi-user.target Alias=yii-some-listen.service

CentOS / Fedora