Skip to content

Commit

Permalink
Add generic linux and mac build
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Feb 27, 2017
1 parent e025e74 commit 67463ab
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 152 deletions.
1 change: 1 addition & 0 deletions amc.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ update_interval = 5
database = "/Users/khosrow/projects/go/src/github.com/citrusleaf/amc/amc.db"

bind = "0.0.0.0:8081"
pidfile = "/tmp/amc.pid"
loglevel = "debug"
errorlog = "/Users/khosrow/projects/go/src/github.com/citrusleaf/amc/amc.log"
chdir = "/Users/khosrow/projects/go/src/github.com/citrusleaf/amc/"
Expand Down
4 changes: 2 additions & 2 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Config struct {
ErrorLog string `toml:"errorlog"`
Chdir string `toml:"chdir"`
Timeout int `toml:"timeout"`
PIDFile string `toml:"pidfile"`
}

Mailer struct {
Expand Down Expand Up @@ -237,10 +238,9 @@ func InitConfig(configFile, configDir string, config *Config) {
aslog.Logger.SetLogger(log.StandardLogger())

setLogLevel(config.AMC.LogLevel)
openDB(config.AMC.Database)
}

func openDB(filepath string) {
func SetupDatabase(filepath string) {
var schema = []string{`
CREATE TABLE IF NOT EXISTS alerts (
Id int64,
Expand Down
7 changes: 7 additions & 0 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var (
_defaultClientPolicy = as.NewClientPolicy()

registerEnterpriseAPI func(*echo.Echo)

_server *echo.Echo
)

func postSessionTerminate(c echo.Context) error {
Expand Down Expand Up @@ -91,6 +93,10 @@ func getAMCVersion(c echo.Context) error {
return c.JSONBlob(http.StatusOK, []byte(fmt.Sprintf(`{"amc_version": "%s", "amc_type": "%s"}`, common.AMCVersion, common.AMCEdition)))
}

func ShutdownServer() {
_server.Shutdown(_server.ShutdownTimeout)
}

func Server(config *common.Config) {
_observer = models.New(config)

Expand Down Expand Up @@ -196,6 +202,7 @@ func Server(config *common.Config) {
}

log.Infof("Starting AMC server, version: %s %s", common.AMCVersion, common.AMCEdition)
_server = e
// Start server
if config.AMC.CertFile != "" {
log.Infof("In HTTPS (secure) Mode")
Expand Down
1 change: 1 addition & 0 deletions deployment/common/amc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONF files are platform dependant; please edit all of them
32 changes: 24 additions & 8 deletions deployment/common/amc.other.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

SIGNAL=${1:-status}

PROJECT="/opt/amc"
PIDFILE="/tmp/amc.pid"
CONFIG="/etc/amc/amc.conf"
Expand All @@ -22,11 +24,25 @@ start_amc(){
fi
}

echo 0 > $PROJECT/stop_signal
finish=0
while [ $finish -eq 0 ]
do
$(start_amc)
sleep 2
finish=$(cat $PROJECT/stop_signal)
done
stop_amc(){
status=$(check_amc_status)
if [ $status -nq 0 ] ; then
"${CMD} -signal stop"
fi
}

case $SIGNAL in
'start')
start_amc()
;;
'stop')
stop_amc()
;;
'status')
check_amc_status()
;;
*)
echo "Unrecognized signal"
exit 1
;;
esac
111 changes: 0 additions & 111 deletions deployment/release/amc/etc/init.d/amc

This file was deleted.

28 changes: 28 additions & 0 deletions deployment/release/darwin/LaunchAgents/com.aerospike.amc.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.aerospike.amc</string>
<key>ProgramArguments</key>
<array>
<string>/Library/amc/amc</string>
<string>-config-file=/Library/amc/amc.conf</string>
</array>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockServiceName</key>
<string>6060</string>
</dict>
</dict>
<key>KeepAlive</key>
<true />
<key>StandardOutPath</key>
<string>/Library/amc/amc.txt</string>
<key>StandardErrorPath</key>
<string>/Library/amc/amc.txt</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ update_interval = 5
#backup_host_public_key_file =

bind = "0.0.0.0:8081"
#pidfile = "/tmp/amc.pid"
pidfile = "/tmp/amc.pid"
loglevel = "info"
errorlog = "/var/log/amc/amc.log"
#proc_name = "amc"
Expand Down
48 changes: 48 additions & 0 deletions deployment/release/linux/etc/init.d/amc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

SIGNAL=${1:-status}

PROJECT="/opt/amc"
PIDFILE="/tmp/amc.pid"
CONFIG="/etc/amc/amc.conf"

CMD="${PROJECT}/amc -daemon -config-file=${CONFIG}"
port="8081"
check_amc_status(){
status=1
if [ -z "`ps aux | grep amc | grep -v grep`" ]; then
status=0
fi
echo $status
}

start_amc(){
status=$(check_amc_status)
if [ $status -eq 0 ] ; then
rm -f $PIDFILE
${CMD}
fi
}

stop_amc(){
status=$(check_amc_status)
if [ $status -nq 0 ] ; then
"${CMD} -signal stop"
fi
}

case $SIGNAL in
'start')
start_amc()
;;
'stop')
stop_amc()
;;
'status')
check_amc_status()
;;
*)
echo "Unrecognized signal"
exit 1
;;
esac
12 changes: 9 additions & 3 deletions main.go → main_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build darwin

package main

import (
Expand All @@ -14,9 +16,12 @@ import (
)

var (
configFile = flag.String("config-file", "", "Configuration file.")
configDir = flag.String("config-dir", "", "Configuration dir.")
profileMode = flag.Bool("profile", false, "Run benchmarks with profiler active on port 6060.")
configFile = flag.String("config-file", "/etc/amc/amc.conf", "Configuration file.")
configDir = flag.String("config-dir", "/etc/amc/", "Configuration dir.")
profileMode = flag.Bool("profile", false, "Run benchmarks with profiler active on port 6060.")
daemonMode = flag.Bool("daemon", false, "Run AMC in daemon mode.")
daemonSignal = flag.String("signal", "", `send signal to the daemon
stop — graceful shutdown.`)
)

func main() {
Expand All @@ -42,5 +47,6 @@ func main() {
config := common.Config{}
common.InitConfig(*configFile, *configDir, &config)

common.SetupDatabase(config.AMC.Database)
controllers.Server(&config)
}
Loading

0 comments on commit 67463ab

Please sign in to comment.