我是 ubuntu 的新手,在 azure 上遇到一个问题,其中虚拟机由于 Microsoft 的维护而自动重新启动。
因此我的申请失败了。 他们(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
:
我不知道脚本是对还是错。但是代码似乎不起作用。 谁能帮我解决这个问题吗? 提前非常感谢
也许你可以使用
chkconfig
。
使用以下命令检查 thin
是否为 on
:
chkconfig | grep thin
如果不是(也许在你的情况下)添加它:
chkconfig thin on
可以通过systemd“模板单元文件”来完成。
sudo nano /lib/systemd/system/[email protected]
[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
重新加载守护进程:
sudo systemctl daemon-reload
查看服务状态:
sudo systemctl status mca-thin@{1..2}
验证其是否按预期工作:
sudo systemctl start mca-thin@1
然后sudo systemctl stop mca-thin@1
启用服务
sudo systemctl enable mca-thin@{1..2}
现在您有了一个系统服务,它将在系统启动时自动启动。失败时也会重新启动。从此类模板启动的服务将在端口范围 6401....640N 上运行(通过
--port=640%i
模板参数设置)。共享 Unix 套接字的服务(通过 --socket="/var/run/thin/redmine.%i.sock"
模板参数设置)。因此,将它们挂接到 nginx 应该不成问题。