├── osx-dev.plugin.zsh └── readme.md /osx-dev.plugin.zsh: -------------------------------------------------------------------------------- 1 | 2 | local MAMPDIR=/Applications/MAMP/bin 3 | local MYSQLPID=/usr/local/var/mysql/Robotop.local.pid 4 | local APACHEPID=/Applications/MAMP/Library/logs/httpd.pid 5 | local MONGODBPID=${HOME}/.mongodb/mongodb.pid 6 | local MONGODBCONF=${HOME}/.mongodb/mongod.conf 7 | local NGINX=/usr/local/sbin/nginx 8 | local NGINX_BASE=/usr/local/etc/nginx 9 | local NGINXPID=/usr/local/var/run/nginx.pid 10 | 11 | ## Used in echo -e statements 12 | local E_PURPLE="\033[0;35m" 13 | local E_NC="\033[0m" 14 | local E_RED="\033[1;31m" 15 | local E_GREEN="\033[0;32m" 16 | 17 | local STARTED="${E_GREEN}Started${E_NC}" 18 | local STOPPED="${E_RED}Stopped${E_NC}" 19 | 20 | function devstatus() 21 | { 22 | echo -e "DEV Server Status" 23 | echo -e "-----------------" 24 | 25 | status-nginx 26 | status-mysql 27 | #status-apache 28 | #status-mongodb 29 | } 30 | 31 | function restart-nginx() 32 | { 33 | sudo kill -HUP $( cat $NGINXPID ) 34 | } 35 | 36 | function restart-nginx-launchctl() 37 | { 38 | stop-nginx 39 | sleep 1 40 | start-nginx 41 | } 42 | 43 | function stop-nginx() 44 | { 45 | echo -e "Stopping nginx..." 46 | sudo launchctl stop homebrew.mxcl.nginx 47 | sleep 1 48 | status-nginx 49 | } 50 | 51 | function start-nginx() 52 | { 53 | echo -e "Starting nginx..." 54 | echo -e " May need to run:" 55 | echo -e " ${E_PURPLE}sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist${E_NC}" 56 | sudo launchctl start homebrew.mxcl.nginx 57 | sleep 1 58 | status-nginx 59 | } 60 | 61 | function status-nginx() 62 | { 63 | _print-dev-server-status "${NGINXPID}" "nginx" 64 | } 65 | 66 | function stop-apache() 67 | { 68 | echo -e "Stopping Apache..." 69 | sudo ${MAMPDIR}/stopApache.sh 70 | sleep 1 71 | status-apache 72 | } 73 | 74 | function start-apache() 75 | { 76 | echo -e "Starting Apache..." 77 | sudo ${MAMPDIR}/startApache.sh 78 | sleep 1 79 | status-apache 80 | } 81 | 82 | function restart-apache() 83 | { 84 | stop-apache 85 | start-apache 86 | } 87 | 88 | function status-apache() 89 | { 90 | _print-dev-server-status "${APACHEPID}" "httpd" 91 | } 92 | 93 | function start-mysql() 94 | { 95 | echo -e "Starting MySql..." 96 | launchctl start homebrew.mxcl.mysql 97 | sleep 1 98 | status-mysql 99 | } 100 | 101 | function stop-mysql() 102 | { 103 | echo -e "Stopping MySql..." 104 | launchctl stop homebrew.mxcl.mysql 105 | sleep 1 106 | status-mysql 107 | } 108 | 109 | function restart-mysql() 110 | { 111 | stop-mysql 112 | start-mysql 113 | } 114 | 115 | function status-mysql() 116 | { 117 | _print-dev-server-status "${MYSQLPID}" "mysql" 118 | } 119 | 120 | function start-mongodb() 121 | { 122 | echo -e "Starting MongoDB..." 123 | mongod --fork -f ${MONGODBCONF} 124 | status-mongodb 125 | } 126 | 127 | function stop-mongodb() 128 | { 129 | echo -e "Stopping MongoDB..." 130 | mongo localhost/admin --eval "db.shutdownServer();" 131 | sleep 1 132 | status-mongodb 133 | } 134 | 135 | function restart-mongodb() 136 | { 137 | stop-mongodb 138 | start-mongodb 139 | } 140 | 141 | function status-mongodb() 142 | { 143 | _print-dev-server-status "${MONGODBPID}" "mongod" 144 | } 145 | 146 | _print-dev-server-status() { 147 | pidfile="$1" 148 | service="$2" 149 | if [ -e "${pidfile}" ]; then 150 | PID=`cat "${pidfile}"` 151 | running=`ps | grep -v "grep" | grep "${service}" | grep -c "${PID}"` 152 | if [ "1" -eq "${running}" ]; then 153 | _print-status-for-cmd ${service} ${STARTED} 154 | else 155 | echo -e "${service} is ${STOPPED} - PID file present, but no process found" 156 | fi 157 | else 158 | _print-status-for-cmd ${service} ${STOPPED} 159 | fi 160 | } 161 | 162 | _print-status-for-cmd() { 163 | service="$1" 164 | readonly mystat=$2 165 | #addtl="$3" 166 | echo -e "${E_NC}${service} is ${mystat}" 167 | } 168 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # OSX-Dev Oh-My-ZSH Plugin 2 | 3 | This plugin adds some commands for maintaining various server programs 4 | on my OSX install. It was cobbled together from my previous 5 | [mamp-control](https://github.com/marshallmick007/mamp-control) project, and various other sources, and "Works On My Machine™" 6 | 7 | ## Installation 8 | 9 | ### Antigen 10 | 11 | Add `antigen bundle marshallmick007/osx-dev-zsh-plugin` to your `.zshrc` 12 | 13 | ### oh-my-zsh 14 | Fork this repo and add a git submodule to your Oh-My-ZSH 15 | `custom/plugins` directory 16 | 17 | ... Or, use this repo as is 18 | 19 | ```shell 20 | cd ~/.oh-my-zsh/custom/plugins 21 | git submodule add git@github.com:marshallmick007/osx-dev-zsh-plugin.git osx-dev 22 | ``` 23 | 24 | Then, add `osx-dev` to your loaded plugins in your `.zshrc` file 25 | 26 | ### zgen 27 | 28 | If you're using [zgen](https://github.com/tarjoilija/zgen), add `zgen load marshallmick007/osx-dev-zsh-plugin` to your .zshrc with your other plugins. 29 | 30 | ## Commands 31 | 32 | ```shell 33 | devstatus 34 | ``` 35 | 36 | Prints the current status of all of the servers below 37 | 38 | ### NGINX 39 | 40 | ```shell 41 | start-nginx 42 | stop-nginx 43 | restart-nginx 44 | status-nginx 45 | ``` 46 | 47 | ### Apache 48 | 49 | ```shell 50 | start-apache 51 | stop-apache 52 | restart-apache 53 | status-apache 54 | ``` 55 | 56 | ### MySQL 57 | 58 | ```shell 59 | start-mysql 60 | stop-mysql 61 | restart-mysql 62 | status-mysql 63 | ``` 64 | 65 | ### MongoDB 66 | 67 | ```shell 68 | start-mongodb 69 | stop-mongodb 70 | restart-mongodb 71 | status-mongodb 72 | ``` 73 | 74 | ## Contributing 75 | 76 | Any additions or bug-fixes are welcome, just create an issue and a Pull 77 | request 78 | 79 | ## TODO 80 | 81 | - [ ] Add PID file locations to a user-configurable config file 82 | - [ ] Support for Unicode symbols 83 | - [ ] Extensibility for other server processes 84 | --------------------------------------------------------------------------------