MurgaNikolay/chef-eye

View on GitHub
templates/default/init.d.bash.erb

Summary

Maintainability
Test Coverage
#!/bin/bash
#
# This file was generated by chef for <%= node['fqdn'] %>
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN BY CHEF CLIENT
#
### BEGIN INIT INFO
# Provides: <%= @service_name %>
# Required-Start: $network $remote_fs $syslog $local_fs
# Required-Stop: $network $remote_fs $syslog $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts <%= @service_name %> by eye
### END INIT INFO

EYE_BIN="/usr/bin/env <%= @eye_process.eye_bin %>"
RUN_USER=<%= @eye_process.owner %>

<% @eye_process.environment.each do |n, v| %>
export <%=n %>=<%=v %>
<% end %>

eye() {
  local cmd
  cmd="${EYE_BIN} $1"
  if [ "$USER" != 'root' ] && [ "$USER" != "$RUN_USER" ]; then
    if [ "$RUN_USER" == 'root' ] ; then
     echo "You must be a root"
    else
     echo "You must be root or $RUN_USER"
    fi
    return 0
  fi
  if [ "$USER" == "$RUN_USER" ]; then
    `$cmd`
  else
    su $RUN_USER -p -c "$cmd"
  fi
}

start() {
  eye load <%=@eye_process.config_file if @eye_process.config_file %>
}

stop() {
  eye quit
}

status() {
  eye xinfo
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;

  reload|restart)
    stop
    start
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|reload|status}"
    exit 1
    ;;
esac