summary refs log tree commit diff stats
path: root/CHANGELOG
Commit message (Expand)AuthorAgeFilesLines
* The hard work of the electrons must be respected. v1.5.2hut2011-10-241-0/+4
* The hard work of the computer must be respected. v1.5.1hut2011-10-241-0/+11
* FOR THE HURD v1.5.0hut2011-10-111-12/+30
* api.commands: finished merging ext.command_parser into apihut2011-10-101-0/+13
* CHANGELOG: sorted itemshut2011-10-021-7/+7
* One in five ranger users use it exclusively for browsing porn v1.4.4hut2011-10-021-4/+17
* This gonna be cool once it's finished v1.4.3hut2011-04-051-0/+5
* Next version will run on pure Lisp Machines only v1.4.2hut2011-03-051-0/+5
* If ranger won't run, you still got peanut butter to live for. v1.4.1hut2011-01-041-0/+4
* We are not authorized to disclose the commit message v1.4.0hut2010-12-221-3/+20
* HOW DO I TURN OFF CAPS LOCK? v1.2.3hut2010-12-131-0/+7
* Tea, Earl Grey, Hot. v1.2.2hut2010-10-101-8/+16
* CHANGELOG updatedhut2010-09-161-0/+3
* Beware of low-flying butterflies v1.2.0hut2010-09-131-0/+18
* Why did the astrophysicist order three hamburgers? v1.1.2hut2010-07-121-0/+6
* version = version + 1 v1.1.1hut2010-06-181-0/+1
* added CHANGELOGhut2010-06-181-0/+21
/gbmor/getwtxt/commit/init.go?h=v0.4.12&id=cf6c8491063db9f96aac139beb3dbb296ae795c3'>cf6c849 ^
8630499 ^
cf6c849 ^
69217dd ^


a0be15e ^

cd635e6 ^
06cffd8 ^

d083ce6 ^
06cffd8 ^
bd23ef0 ^

887c25e ^
bd23ef0 ^
e34697c ^
920306c ^
efa99ed ^

7410b8c ^



df1d1ef ^
4695425 ^
2b0d4a5 ^
6c1b09b ^











6753171 ^



f2d85b6 ^
1f8b2ce ^
06cffd8 ^
06cffd8 ^
c896e6b ^
71971db ^
e34697c ^
5310d08 ^
7410b8c ^
06cffd8 ^

f2d85b6 ^
1f8b2ce ^
f2d85b6 ^




bd23ef0 ^

f2d85b6 ^
67864b2 ^
cf6c849 ^





f2d85b6 ^

5310d08 ^







5310d08 ^
c896e6b ^
cd635e6 ^
cd635e6 ^
887c25e ^
b29e1c1 ^
887c25e ^

887c25e ^
78f4d8a ^


c896e6b ^

cd635e6 ^
d083ce6 ^
5310d08 ^

cd635e6 ^
b29e1c1 ^
d083ce6 ^
efa99ed ^

c896e6b ^
5310d08 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
                                                      

        
                       

             
                   
              
              
 
                                     
                                

 
                       
 
     
                                                                                                            
                                                                                                
                                                                                                     
                                                                                                                           


                                                                                                               

 
                              

                                
                                 
 

                                          
                                
 
                            
 

                                    



                                         
 
                                 
 











                                                       



                                       
                    
                     
                    
                     
                      
                         
                               
                           
                    

 
                   
                     




                             

                             
                          
         





                              

 







                                       
 
                                                                              
                                          
                                                                                            
 
                                      

                                                    
                                      


                                                             

                         
                                                   
                                                

                         
                                            
                                     
                                       

                                                  
                                                          



                                  
package svc // import "github.com/getwtxt/getwtxt/svc"

import (
	"html/template"
	"log"
	"os"
	"os/signal"
	"sync"
	"time"

	"github.com/getwtxt/registry"
	"github.com/spf13/pflag"
)

const getwtxt = "0.3.0"

var (
	flagVersion  *bool   = pflag.BoolP("version", "v", false, "Display version information, then exit.")
	flagHelp     *bool   = pflag.BoolP("help", "h", false, "Display the quick-help screen.")
	flagMan      *bool   = pflag.BoolP("manual", "m", false, "Display the configuration manual.")
	flagConfFile *string = pflag.StringP("config", "c", "", "The name/path of the configuration file you wish to use.")
	flagAssets   *string = pflag.StringP("assets", "a", "", "The location of the getwtxt assets directory")
	flagDBPath   *string = pflag.StringP("db", "d", "", "Path to the getwtxt database")
	flagDBType   *string = pflag.StringP("dbtype", "t", "", "Type of database being used")
)

var confObj = &Configuration{}

// signals to close the log file
var closeLog = make(chan bool, 1)

// used to transmit database pointer after
// initialization
var dbChan = make(chan dbase, 1)

var tmpls *template.Template

var twtxtCache = registry.NewIndex()

var remoteRegistries = &RemoteRegistries{
	Mu:   sync.RWMutex{},
	List: make([]string, 0),
}

var staticCache = &staticAssets{}

func errFatal(context string, err error) {
	if err != nil {
		log.Fatalf(context+"%v\n", err.Error())
	}
}

func errLog(context string, err error) {
	if err != nil {
		log.Printf(context+"%v\n", err.Error())
	}
}

// I'm not using init() because it runs
// even during testing and was causing
// problems.
func initSvc() {
	checkFlags()
	titleScreen()
	initConfig()
	initLogging()
	initDatabase()
	go cacheAndPush()
	tmpls = initTemplates()
	watchForInterrupt()
	pingAssets()
}

func checkFlags() {
	pflag.Parse()
	if *flagVersion {
		titleScreen()
		os.Exit(0)
	}
	if *flagHelp {
		titleScreen()
		helpScreen()
		os.Exit(0)
	}
	if *flagMan {
		titleScreen()
		helpScreen()
		manualScreen()
		os.Exit(0)
	}
}

// Watch for SIGINT aka ^C
// Close the log file then exit
func watchForInterrupt() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	go func() {
		for sigint := range c {

			log.Printf("\n\nCaught %v. Cleaning up ...\n", sigint)
			confObj.Mu.RLock()
			log.Printf("Closing database connection to %v...\n", confObj.DBPath)

			db := <-dbChan

			switch dbType := db.(type) {
			case *dbLevel:
				errLog("", dbType.db.Close())
			case *dbSqlite:
				errLog("", dbType.db.Close())
			}

			if !confObj.StdoutLogging {
				closeLog <- true
			}

			confObj.Mu.RUnlock()
			close(dbChan)
			close(closeLog)

			// Let everything catch up
			time.Sleep(100 * time.Millisecond)
			os.Exit(0)
		}
	}()
}