ubuntu 精简服务器自动重启脚本

y0u0uwnf  于 6个月前  发布在  其他
关注(0)|答案(3)|浏览(88)

我是ubuntu的新手,我在azure上遇到了一个问题,因为微软的维护,虚拟机会自动重启。
正因为如此,我的应用程序正在下降。也没有确认从他们的(windows)方面何时重新启动/系统更新将发生。
即使我启动瘦服务器,我如何保持它打开一个特定的端口,即端口3000,3001,3002,3003等。请让我知道。
我浏览了各种博客,并在init.d中进行了更改,以使瘦服务器在重新启动时自动启动。

user: root
group: webuser
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 1
threaded: true
no-epoll: true
daemonize: true
socket: tmp/sockets/thin.sock
chdir: webuser/app
tag: hey aux

字符串
我尝试过上面的方法,但失败了。
下面是我的etc/init.d thin文件:

# Do NOT "set -e"

DAEMON=/usr/bin/thin
SCRIPT_NAME=/etc/init.d/thin

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

run_action() {
        ACTION="$1"

    if [ -x /usr/bin/ruby1.8 ]; then
        /usr/bin/ruby1.8 $DAEMON $ACTION --all /etc/thin1.8
    fi

    if [ -x /usr/bin/ruby1.9.1 ]; then
        /usr/bin/ruby1.9.1 $DAEMON $ACTION --all /etc/thin1.9.1
    fi

}

case "$1" in
  start)
    run_action start
    ;;
  stop)
    run_action stop
    ;;
  restart|force-reload|reload)
    run_action restart
    ;;
  *)
    echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
    exit 3
    ;;
esac

:


我不知道如果脚本是正确的或错误的。但代码似乎不工作。任何人都可以请帮助我与此。提前感谢很多

odopli94

odopli941#

你可能想使用this script来精简。但根据我的经验,最好将Foreman沿着upstart来管理 Boot 上的启动应用程序。效果更好,更容易配置。
除此之外,我不确定我是否理解了你的堆栈:你正在部署一个ruby web应用程序,在一个运行在Windows 2012服务器上的Ubuntu VM上,在Azure上?

uqzxnwby

uqzxnwby2#

可以通过systemd“模板单元文件”完成。
1.定义单位:sudo nano /lib/systemd/system/ [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)

[Unit]
After=network.target

[Service]
Type=simple
User=ec2-user
# Notice "+-" or "+" command prefixes. They defines privileges and tolerance.
# See: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines 
ExecStartPre=+-/usr/bin/mkdir /var/run/thin
ExecStartPre=+-/usr/bin/mkdir /var/log/thin
ExecStartPre=+/usr/bin/chown ec2-user:ec2-user /var/run/thin
# Notice placeholder "%i" It is used when running service from template.
# See: https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Specifiers
ExecStart=/usr/bin/thin start --chdir="/opt/mca/redmine" --address=0.0.0.0 --port=640%i --socket="/var/run/thin/redmine.%i.sock" --environment="production" --max-conns=1024 --max-persistent-conns=100 --threadpool-size=20 --timeout=30
Restart=on-failure
StandardOutput=truncate:/var/log/thin/stdout.%i.log
StandardError=truncate:/var/log/thin/stderr.%i.log

[Install]
WantedBy=multi-user.target

字符串
1.插件守护进程:sudo systemctl daemon-reload
1.检查服务状态:sudo systemctl status mca-thin@{1..2}
1.验证它是否按预期工作:sudo systemctl start mca-thin@1然后sudo systemctl stop mca-thin@1
1.启用服务sudo systemctl enable mca-thin@{1..2}
现在你有一个系统服务,它会在系统启动时自动启动。失败时也会重新启动。从这样的模板启动的服务将在端口范围6401.640N(通过--port=640%i模板参数设置)上运行。服务共享Unix套接字(通过--socket="/var/run/thin/redmine.%i.sock"模板参数设置)。因此将它们挂接到nginx应该没有问题。

nszi6y05

nszi6y053#

也许你可以使用chkconfig。用命令检查thin是否是on

chkconfig | grep thin

字符串
如果不是(也许在你的情况下)添加它:

chkconfig thin on

相关问题