0

我正在尝试为我的 screeps 私人服务器创建一个 init.d 脚本。我有几件事有问题。

  1. 我想用守护程序用户而不是 root 运行 screepsscreeps-daemon
  2. 我想确保它在正确的工作目录中运行。

使用initd-forever我生成了以下内容:

#!/bin/bash
### BEGIN INIT INFO
# If you wish the Daemon to be lauched at boot / stopped at shutdown :
#
#    On Debian-based distributions:
#      INSTALL : update-rc.d scriptname defaults
#      (UNINSTALL : update-rc.d -f  scriptname remove)
#
#    On RedHat-based distributions (CentOS, OpenSUSE...):
#      INSTALL : chkconfig --level 35 scriptname on
#      (UNINSTALL : chkconfig --level 35 scriptname off)
#
# chkconfig:         2345 90 60
# Provides:          /usr/local/bin/screeps
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: forever running /usr/local/bin/screeps
# Description:       /usr/local/bin/screeps
### END INIT INFO
#
# initd a node app
# Based on a script posted by https://gist.github.com/jinze at https://gist.github.com/3748766
#

if [ -e /lib/lsb/init-functions ]; then
  # LSB source function library.
  . /lib/lsb/init-functions
fi;

pidFile="/var/run/forever/screeps.pid"
logFile="/var/run/Screeps.log"
workingDir="/var/local/screeps"

command="start"
nodeApp="/usr/local/bin/screeps"
foreverApp="/usr/local/bin/forever"

start() {
  echo "Starting $nodeApp"

  # Notice that we change the PATH because on reboot
  # the PATH does not include the path to node.
  # Launching forever with a full path
  # does not work unless we set the PATH.
  PATH=/usr/local/bin:$PATH
  export NODE_ENV=production

  su - screeps-daemon -c \
    `foreverApp start --workingDir $workingDir --pidFile $pidFile -l $logFile -a -d -c "$command" $nodeApp`
  RETVAL=$?
}

restart() {
  echo -n "Restarting $nodeApp"
  $foreverApp restart $nodeApp
  RETVAL=$?
}

stop() {
  echo -n "Shutting down $nodeApp"
   $foreverApp stop $nodeApp
   RETVAL=$?
}

status() {
   echo -n "Status $nodeApp"
   $foreverApp list
   RETVAL=$?
}

case "$1" in
   start)
        start
        ;;
    stop)
        stop
        ;;
   status)
        status
       ;;
   restart)
    restart
        ;;
  *)
       echo "Usage:  {start|stop|status|restart}"
       exit 1
        ;;
esac
exit $RETVAL

但我收到以下错误:

sudo /etc/init.d/screeps start                                                                                                                                   jcota@ubuntu
Starting /usr/local/bin/screeps
su: unrecognized option '--minUptime'
Usage: su [options] [LOGIN]

Options:
  -c, --command COMMAND         pass COMMAND to the invoked shell
  -h, --help                    display this help message and exit
  -, -l, --login                make the shell a login shell
  -m, -p,
  --preserve-environment        do not reset environment variables, and
                                keep the same shell
  -s, --shell SHELL             use SHELL instead of the default in passwd

这可能是一些简单的事情盯着我的脸,但我现在看不到它。

4

2 回答 2

1

看起来您用于 su 的命令行用反引号引用。这将导致 shell 执行命令:

foreverApp start --workingDir $workingDir --pidFile $pidFile -l $logFile -a -d -c "$command" $nodeApp

然后在“su - screeps-daemon -c”之后附加任何返回到 su 命令行的内容。

最有可能运行该 foreverApp 命令时出错,它正在返回帮助消息(这可能是生成“--minUptime”的地方)

尝试用单引号 ' 而不是反引号 ` 引用

于 2016-11-30T17:20:48.743 回答
0

我通过以下方式替换您的执行脚本来解决此问题:

sudo - screeps-daemon -c \
  "$foreverApp start --workingDir $workingDir $nodeApp $command --password <my-password> --runners_cnt 4 --processors_cnt 4"

取决于你想专用于screeps服务器的许多处理器内核的位置runners_cntprocessors_cnt应该设置的位置。

别忘了跑sudo update-rc.d <scriptname> defaults

于 2017-12-03T20:35:34.060 回答