Ticket #35183: MySQL_Stop_Start.applescript

File MySQL_Stop_Start.applescript, 1.7 KB (added by ctreleaven (Craig Treleaven), 12 years ago)

plain text

Line 
1(*  Applescript to stop/start MySQL Server app
2Author:  Craig Treleaven, ctreleaven at cogeco.ca
3Modified: 2012Jul13
4
5NB - if mysqld is running, we only stop it if it was launched under launchd
6*)
7set mysqld to " not running on this machine."
8set mysqlButton to "Donno"
9set newline to "
10"
11set indent to space & space & space & space
12set myResult to ""
13
14repeat until (myResult contains "Close")
15        set processes to do shell script "ps -Ac"
16        if the processes contains "mysqld" then
17                set mysqld to " running."
18                set mysqlButton to "Stop MySQL"
19        else
20                set mysql to " not running."
21                set mysqlButton to "Start MySQL"
22        end if
23       
24        set myResult to display dialog "Simple tool to start and stop the MySQL database server" & newline & newline & "Currently... " & Â
25                newline & newline & indent & "MySQL server is" & mysqld Â
26                with icon note with title Â
27                "Stop/Start MySQL Server" buttons {mysqlButton, "Close"} Â
28                default button "Close" -- cancel button "Close"
29        set myResult to button returned of myResult
30        if myResult contains "Start MySQL" then
31                do shell script "sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist" with administrator privileges
32                delay 2 -- a little time to start up
33        else if myResult contains "Stop MySQL" then
34                if ((do shell script "sudo launchctl list" with administrator privileges) contains "mysql5") then
35                        do shell script "sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist" with administrator privileges
36                else
37                        display alert " MySQL Server appears not to have been started in the normal fashion.  Unable to shut down." message "Was mysqld started directly from a command line session?" as warning
38                end if
39                set myResult to "Close"
40        end if
41end repeat