centos关机执行seafile stop脚本避免访问故障及seafile开机启动脚本

时间:2021-03-10 阅读:2220 评论:0 作者:hkear

seafile-pro-server 6.3.9 1000用户版

seafile服务开机启动脚本


启用rc.local


vi /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
rm -rf /tmp/seahub_cache/* && /bin/sleep 20 &&  cd /seafile/installed && /seafile/installed/seafile.sh start >>/seafile/logs/seafile-startup-`date +%Y%m%d%H%M`.log && cd /seafile/installed && /seafile/installed/seahub.sh start >>/seafile/logs/seahub-startup-`date +%Y%m%d%H%M`.log && cd /seafile/installed && /seafile/installed/seafile-background-tasks.sh start >>/seafile/logs/sea-background-startup-`date +%Y%m%d%H%M`.log
touch /var/lock/subsys/local


*之所以rm -rf /tmp/seahub_cache/*是因为要清理下seahub缓存,避免出错,这个也可以解决系统重启后导致的seahub无法启动的问题;


tips:强制重启seafile虚拟机后,重启seahub服务提示一堆错误,网站可以访问但是不能获取资料库,fsck没问题,查了一下需要清理缓存,所以删除掉/tmp/seahub_cache/*后解决


sleep 20是因为用的mysql数据库,避免mysql还没启动seafile先启动了,会造成启动失败;



:关机重启 shutdown reboot halt自动运行脚本


新建stopSrv.service关机服务

vi /usr/lib/systemd/system/stopSrv.service
[Unit]
Description=close services before reboot and shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
# This works because it is installed in the target and will be
#   executed before the target state is entered
# Also consider kexec.target

[Service]
Type=oneshot
ExecStart= /seafile/installed/stop.sh

[Install]
WantedBy=halt.target reboot.target shutdown.target


启用服务

 systemctl enable stopSrv


建立停止服务脚本

vi /seafile/installed/stop.sh
#!/bin/bash
/seafile/installed/seafile.sh stop >>/seafile/logs/seafile-stop-`date +%Y%m%d%H%M`.log && /seafile/installed/seahub.sh stop >>/seafile/logs/seahub-stop-`date +%Y%m%d%H%M`.log && /seafile/installed/seafile-background-tasks.sh stop >>/seafile/logs/sea-background-stop-`date +%Y%m%d%H%M`.log


修改脚本权限

chmod +x /seafile/installed/stop.sh && chmod +x   /usr/lib/systemd/system/stopSrv.service


reboot之后查看是否有停止日志

ls /seafile/logs
/seafile/logs/seahub-stop-202103101320.log
/seafile/logs/seafile-stop-202103101320.log
/seafile/logs/sea-background-stop-202103101320.log


本文链接: https://dkicloud.com/?id=23 转载请注明出处!

评论区 交流一下吧!

共有0条评论来说两句吧...

欢迎 发表评论: