如果手动启动服务,是否可以通过启动停止服务?


0

我正在使用launchd在启动时启动mysql,它工作正常。我可以使用“ launchctl卸载”和“ launchctl加载”命令停止和启动服务。我也可以通过在终端中键入“ mysqld_safe”命令来启动服务。但是,如果我通过“ launchctl stop”停止服务,然后通过“ mysqld_safe”命令启动服务,则无法通过“ launchctl stop”停止服务。这可能吗?我在这里做错了什么?

我的清单是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>mysql.service</string>
        <key>ProgramArguments</key>
        <array>
                <string>/path/to/mysql/bin/mysqld_safe</string>
                <string>--defaults-file=/path/to/mysql/my.cnf</string>
                <string>--port=3306</string>
                <string>--socket=/path/to/mysql/tmp/mysql.sock</string>
                <string>--datadir=/path/to/mysql/data</string>
                <string>--log-error=/path/to/mysql/data/mysqld.log</string>
                <string>--pid-file=/path/to/mysql/data/mysqld.pid</string>
       </array>
       <key>RunAtLoad</key>
       <true/>
       <key>KeepAlive</key>
       <false/>
       <key>UserName</key>
       <string>_mysql</string>
       <key>GroupName</key>
       <string>_mysql</string>
    <key>StandardOutPath</key>
    <string>/tmp/mysql_start.out</string>
    <key>StandardErrorPath</key>
    <string>/tmp/mysql_start.err</string>

</dict>
</plist>

通过终端启动mysql的命令是:

mysqld_safe --defaults-file=/path/to/mysql/my.cnf --port=3306 --socket=/path/to/mysql/tmp/mysql.sock --datadir=/path/to/mysql/data --pid-file=/path/to/mysql/data/mysqld.pid

Answers:



0

我必须添加以下行:

<key>ExitTimeOut</key>       <integer>30</integer>

如果拖尾error_log,您将看到在此超时之后什么也不会发生。您可以减小此值。

您将看到以下内容

2016-09-13 13:42:09 14055 [Note] Giving 0 client threads a chance to die gracefully
2016-09-13 13:42:09 14055 [Note] Event Scheduler: Purging the queue. 0 events
2016-09-13 13:42:09 14055 [Note] Shutting down slave threads
2016-09-13 13:42:09 14055 [Note] Forcefully disconnecting 0 remaining clients
...
2016-09-13 13:42:10 14055 [Note] Shutting down plugin 'sha256_password'
2016-09-13 13:42:10 14055 [Note] Shutting down plugin 'mysql_old_password'
2016-09-13 13:42:10 14055 [Note] Shutting down plugin 'mysql_native_password'
2016-09-13 13:42:10 14055 [Note] Shutting down plugin 'binlog'
2016-09-13 13:42:10 14055 [Note] /usr/local/mysql-5.6.33-osx10.11-x86_64/bin/mysqld: Shutdown complete

为什么事情在超时值之前不能正常消失-我不知道,但我一直在使用它,它也与mysql.server start / stop命令兼容。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.