seafile 配置开机自启
环境:ubuntu 18.04
seafile版本:seafile-server-7.0.5
1.切入seafile 安装目录
注意 切入的是自己的安装目录
cd /opt/seafile/seafile-server-7.0.5
2. 创建存放脚本文件夹
mkdir systemd
3.创建启动和关闭脚本
3.1创建启动脚本
sudo vim start.seafile.sh
3.2 复制脚本内容
#!/bin/bash path_base="/opt/seafile/seafile-server-7.0.5" path_seafile="${path_base}/seafile.sh" path_seahub="${path_base}/seahub.sh" echo "Seafile Starting..." # TODO: Determine if the script exists echo "$(date "+%Y-%m-%d %H:%M:%S"): Determine if the script exists." if ! [ -f "${path_seafile}" ] then echo "$(date "+%Y-%m-%d %H:%M:%S"): Missing script main file: ${path_seafile}." exit 1 fi if ! [ -f "${path_seahub}" ] then echo "$(date "+%Y-%m-%d %H:%M:%S"): Missing script main file: ${path_seahub}." exit 1 fi echo "$(date "+%Y-%m-%d %H:%M:%S"): The script exists." #cd "${path_base}" # TODO: Stop all service. cmd_seahub=`${path_seahub} stop` if [[ $cmd_seahub =~ "Seahub is not running" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seahub server not running, Start it." else echo "$(date "+%Y-%m-%d %H:%M:%S"): Seahub server is running, stop and restart it." fi cmd_seafile=`${path_seafile} stop` if [[ $cmd_seafile =~ "seafile server not running yet" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seafile server not running, Start it." else echo "$(date "+%Y-%m-%d %H:%M:%S"): Seafile server is running, stop and restart it." fi # TODO: Start seafile. cmd_seafile=`${path_seafile} start` echo $cmd_seafile if [[ $cmd_seafile =~ "Seafile server started" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seafile server started." else echo "$(date "+%Y-%m-%d %H:%M:%S"): Seafile server Startup failed, Exit." exit 1 fi # TODO: Start seahub. cmd_seahub=`${path_seahub} start` echo $cmd_seahub if [[ $cmd_seahub =~ "Seahub is started" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seahub server started." else echo "$(date "+%Y-%m-%d %H:%M:%S"): Seahub server Startup failed, Exit." exit 1 fi echo "$(date "+%Y-%m-%d %H:%M:%S"): All services started successfully." # TODO: Cycling detection service. echo "$(date "+%Y-%m-%d %H:%M:%S"): Cycling detection service." while true do sleep 30s cmd_seafile=`${path_seafile} start` if ! [[ $cmd_seafile =~ "Seafile controller is already running" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seafile server err, Stop all services and exit." ${path_seahub} stop ${path_seafile} stop exit 1 fi cmd_seahub=`${path_seahub} start` if ! [[ $cmd_seahub =~ "Seahub is already running" ]]; then echo "$(date "+%Y-%m-%d %H:%M:%S"): Seahub server err, Stop all services and exit." ${path_seahub} stop ${path_seafile} stop exit 1 fi done
注意:将path 更改为自己seafile的安装目录
3.3创建停止服务脚本 stop-seafile.sh
sudo vim stop-seafile.sh
3.4 复制脚本至stop-seafile.sh
注意:path 目录为 seafile根目录
path_base="/opt/seafile/seafile-server-7.0.5" path_seafile="${path_base}/seafile.sh" path_seahub="${path_base}/seahub.sh" ${path_seahub} stop ${path_seafile} stop
4.给脚本添加执行权限
sudo chmod +x start.seafile.sh sudo chmod +x stop.seafile.sh
5.创建开机自启服务 seafile.service
[Unit] Description=seafile service #Requires=syslog.socket #Documentation=man:rsyslogd(8) Documentation= Wants=network-online.target After=network-online.target [Service] Type=simple User=root Group=root PermissionsStartOnly=true ExecStart=/opt/seafile/seafile-server-7.0.5/systemd/start-seafile.sh StandardOutput=journal StandardError=inherit #Restart=on-failure Restart=always # Specifies the maximum file descriptor number that can be opened by this process. LimitNOFILE=65536 # Disable timeout logic and wait until process is stopped TimeoutStopSec=0 # SIGTERM signal is used to stop soft #KillMode=process KillSignal=SIGTERM SendSIGKILL=no SuccessExitStatus=0 [Install] WantedBy=multi-user.target
6.查看开关服务是否正常
#开机自启
sudo systemctl enable seafile.service
#启动服务
sudo systemctl start seafile.service
#停止服务
sudo systemctl stop seafile.service
#查看服务状态
sudo systemctl status seafile.service