启动服务未启动所有进程 Ubuntu

启动服务未启动所有进程 Ubuntu

我需要有关 ubuntu 中自定义服务的帮助,我想在启动时运行它。但我遇到了服务问题,因为它没有启动所有进程。当我手动启动服务时,它运行正常,但在启动时却不行。

/etc/init.d有文件埃博特

#!/bin/sh
USER="freeman"
DIR='/home/freeman/'

case "$1" in
'start')
su $USER -c "cd $DIR; ./ebotv3 start"
;;
'stop')
su $USER -c "cd $DIR; ./ebotv3 stop"
;;
'restart')
su $USER -c "cd $DIR; ./ebotv3 restart"
;;
'status')
su $USER -c "cd $DIR; ./ebotv3 status"
;;
*)
echo "Usage $0 start|stop|restart|status"
esac

在我的主目录中我有另一个文件ebotv3

# Leave this alone. 
NAME=ebotv3 

# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS! 
DIR="/home/freeman/ebot/ebot-csgo/" 

# Leave this alone. 
DAEMON=php

# Internet-server: 
PARAMS=bootstrap.php

# Leave this alone. 
DESC="ebotv3 server" 

case "$1" in 
start) 
if [[ `screen -ls |grep $NAME` ]] 
   then 
   echo "ebot is already running!" 
else  
   `cd $DIR; screen -m -d -S ebotv3 $DAEMON $PARAMS`
   echo "Starting $DESC:  ...done."
fi
;; 
stop) 
if [[ `screen -ls |grep $NAME` ]] 
   then  
   kill `ps aux | grep -v grep | grep -i freeman | grep -i screen | grep -i $NAME | awk '{print $2}'` 
   echo "Stopping $DESC:  ...done." 
else 
   echo "Coulnd't find a running $DESC" 
fi 
;; 
restart) 
if [[ `screen -ls |grep $NAME` ]] 
   then  
   kill `ps aux | grep -v grep | grep -i freeman | grep -i screen | grep -i $NAME | awk '{print $2}'` 
   echo "Stopping $DESC:  ...done." 
else 
   echo "Coulnd't find a running $DESC" 
fi 
   `cd $DIR; screen -m -d -S ebotv3 $DAEMON $PARAMS` 
   echo -n "Starting $DESC:  ...done." 
;; 
status) 
ps aux | grep -v grep | grep php > /dev/null 
CHECK=$? 
[ $CHECK -eq 0 ] && echo "$DESC is UP" || echo "$DESC is DOWN" 
;; 
*) 
echo "Usage: $0 {start|stop|status|restart}" 
exit 1 
;; 
esac 

exit 0

在我的进程启动时ps x我有这个:

1052 ?        Ss     0:00 SCREEN -m -d -S ebotv3 php bootstrap.php
1067 pts/2    Ssl+   0:00 php bootstrap.php
1191 pts/2    Z+     0:00 [sh] <defunct>
1192 pts/2    Sl+    0:00 node /home/freeman/ebot/ebot-csgo/websocket_server.js 192.168.0.20 12360

当我在我的流程中手动启动服务时,ps x我有以下情况:

22768 ?        Ss     0:00 SCREEN -m -d -S ebotv3 php bootstrap.php
22769 pts/2    Ssl+   0:00 php bootstrap.php
22771 pts/2    S+     0:00 sh -c node /home/freeman/ebot/ebot-csgo/websocket_server.js 192.168.0.20 12360
22772 pts/2    Sl+    0:00 node /home/freeman/ebot/ebot-csgo/websocket_server.js 192.168.0.20 12360

答案1

伙计们,我找到了问题所在,该服务在 mysql 服务之前启动,但依赖于 mysql 服务。我在启动脚本中添加了睡眠功能:)

相关内容