Last active
October 2, 2015 22:14
-
-
Save franciscocpg/3bef811d554ef433a042 to your computer and use it in GitHub Desktop.
Vagrant oracle service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ACTION="$1" | |
| CONFIG_FILE="/etc/default/vagrant-oracle" | |
| if [[ ! -e "$CONFIG_FILE" ]]; then | |
| echo "file $CONFIG_FILE does not exists. Create it with VAGRANT_ORACLE_HOME variable" | |
| exit 1 | |
| fi | |
| source "$CONFIG_FILE" | |
| if [[ -z "$VAGRANT_ORACLE_HOME" ]]; then | |
| echo "set VAGRANT_ORACLE_HOME environment variable" | |
| exit 1 | |
| fi | |
| function start() { | |
| echo "Starting vagrant oracle: " | |
| cd $VAGRANT_ORACLE_HOME | |
| vagrant up | |
| } | |
| function stop() { | |
| echo "Stopping vagrant oracle: " | |
| cd $VAGRANT_ORACLE_HOME | |
| vagrant halt | |
| } | |
| ################################################## | |
| # Exec as /etc/init.d to load env variables | |
| ################################################## | |
| function execInitd() { | |
| args=( $@ ) | |
| action=${args[0]} | |
| dummy=${args[1]} | |
| whoami=`whoami` | |
| if [ -z "$dummy" ]; then | |
| me=`basename $0` | |
| sudo -u ${whoami} /etc/init.d/${me} ${action} dummy | |
| else | |
| ################################################## | |
| # Do the action | |
| ################################################## | |
| case "$action" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| status) | |
| echo "Status vagrant oracle: " | |
| cd $VAGRANT_ORACLE_HOME | |
| vagrant status | |
| ;; | |
| *) | |
| echo "Usage: ${0##*/} {start|stop|restart}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit 0 | |
| fi | |
| } | |
| ################################################## | |
| # Do the action | |
| ################################################## | |
| case "$ACTION" in | |
| start|stop|restart|status) | |
| execInitd $* | |
| ;; | |
| *) | |
| echo "Usage: ${0##*/} {start|stop|restart|status}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit 0 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used with install-vagrant-oracle for creating vagrant service