MySQL启动后在启动时运行脚本

时间:2015-01-10 18:06:31

标签: linux raspberry-pi boot

我想在我的Raspberry Pi启动时启动Seafile(需要MySQL的云服务器)。我的问题是,Seafile开始使用mysql并导致许多错误,因为seafile需要mysql。 我采用了推荐的脚本:

#! /bin/sh
# /etc/init.d/seafile

### BEGIN INIT INFO
# Provides:          seafile
# Required-Start:    $local_fs $remote_fs $network mysql
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Script to start/stop/restart seafile
# Description:       Simple script to start, stop or restart seafile for the cloud
### END INIT INFO

# Change the value of "user" to your linux user name
user=chromo

# Change the value of "script_path" to your path of seafile installation
seafile_dir=/home/chromo/cloud
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log

# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=true
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000

case "$1" in
    start)
            sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [  $fastcgi = true ];
            then
                    sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
            else
                    sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
            fi
    ;;
    restart)
            sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
            if [  $fastcgi = true ];
            then
                    sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
            else
                    sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
            fi
    ;;
stop)
            sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
            sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
    ;;
    *)
            echo "Usage: /etc/init.d/seafile {start|stop|restart}"
            exit 1
    ;;
esac

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:-1)

最好的办法是在/etc/rc[runlevel].d文件中设置启动这些服务的优先级。

在您的情况下,首先要检查的是您已启动的运行级别。您可以使用命令" runlevel"进行检查。你也可以检查

说,您已经被启动到运行级别3.您可以在目录" /etc/rc3.d"。

中重命名当前的seafile文件。

例如:

如果这两个文件是

/etc/rc3.d/20seafile
/etc/rc3.d/50mysql

将文件重命名为70seafile或任何高于50的文件。

这应该可以解决您现在面临的问题。

另一个解决方法是删除/etc/init.d目录中的seafile链接并添加一行说

/etc/init.d/seafile start 

在文件/etc/rc.local

请检查一下,如果已经为您解决了问题,请告诉我。