之前我们在ubuntu20.04系统中配置开机启动执行脚本,可以查看这个笔记:https://sulao.cn/post/882
由于购买的轻量应用服务器内存只有1G,目前跑了flask,mysql,redis和celery内存有些不够,所以每天都需要重启下服务器,目前定时重启可以参考如下配置:
crontab -l
30 1 * * * /sbin/shutdown -r now
因为我启动还要启动celery的worker和beat,所以配置开机启动这些软件,使用tmux的方式启动,方便后续查看。
启动脚本worker_start.sh内容如下:
#!/bin/bash
set -ex
current_dir=`readlink -f $(dirname $0)`
cd $current_dir
if ! command -v "tmux" >/dev/null 2>&1; then
echo -e "未检测到 tmux 命令, 请先安装(yum install tmux -y | apt install tmux -y)命令再执行本脚本!"
exit 1
fi
echo "启动异步任务框架 Celery Worker..."
tmux new-session -d -s celery_worker 'celery -A apps.tasks.celery worker -l info -c 1'
echo "启动定时异步任务 Celery Beat..."
tmux new-session -d -s celery_crontab 'celery -A apps.tasks beat -l info'
接着我们写开机启动systemctl服务配置
cat /etc/systemd/system/celery.service
[Unit]
Description=celery
[Service]
ExecStart=/data/blog/worker_start.sh
Type=forking
[Install]
WantedBy=multi-user.target
然后我们配置开机启动
systemctl daemon-reload
systemctl enable celery
systemctl start celery
启动后效果如下:
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://sulao.cn/post/1026
相关推荐
- ubuntu使用deb包安装指定版本内核
- ubuntu修改grub引导切换到指定内核的方法
- ubuntu使用nvbandwidth测试单节点gpu带宽性能
- ubuntu24.04LTS添加apt源
- ubuntu下使用qperf工具测试RDMA网络带宽和延迟
- ubuntu22.04关闭自动更新和禁止unattended-upgrades服务开机启动
- ubuntu22.04使用nccl-tests进行单机多卡通信测试
- ubuntu22.04编译安装hwloc/libevent/ucx/openpmix/openmpi
- ubuntu安装openvpn并配置连接
- ubuntu22.04使用gpu-burn进行gpu显卡测试
评论列表