Пример #1
0
func main() {
	flag.Parse() // called here in main() to allow other packages to set flags in their inits

	caddy.AppName = appName
	caddy.AppVersion = appVersion

	// set up process log before anything bad happens
	switch logfile {
	case "stdout":
		log.SetOutput(os.Stdout)
	case "stderr":
		log.SetOutput(os.Stderr)
	case "":
		log.SetOutput(ioutil.Discard)
	default:
		file, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
		if err != nil {
			log.Fatalf("Error opening log file: %v", err)
		}
		log.SetOutput(file)
	}

	if version {
		fmt.Printf("%s %s\n", caddy.AppName, caddy.AppVersion)
		os.Exit(0)
	}
	if revoke != "" {
		err := letsencrypt.Revoke(revoke)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("Revoked certificate for %s\n", revoke)
		os.Exit(0)
	}

	// Set CPU cap
	err := setCPU(cpu)
	if err != nil {
		mustLogFatal(err)
	}

	// Get Caddyfile input
	caddyfile, err := caddy.LoadCaddyfile(loadCaddyfile)
	if err != nil {
		mustLogFatal(err)
	}

	// Start your engines
	err = caddy.Start(caddyfile)
	if err != nil {
		if caddy.IsRestart() {
			log.Printf("[ERROR] Upon starting %s: %v", appName, err)
		} else {
			mustLogFatal(err)
		}
	}

	// Twiddle your thumbs
	caddy.Wait()
}
Пример #2
0
		case "stdout":
			log.SetOutput(os.Stdout)
		case "stderr":
			log.SetOutput(os.Stderr)
		case "":
			log.SetOutput(ioutil.Discard)
		default:
			file, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
			if err != nil {
				log.Fatalf("Error opening process log file: %v", err)
			}
			log.SetOutput(file)
		}

		if revoke != "" {
			err := letsencrypt.Revoke(revoke)
			if err != nil {
				log.Fatal(err)
			}
			fmt.Printf("Revoked certificate for %s\n", revoke)
			os.Exit(0)
		}

		// Set CPU cap
		err := setCPU(cpu)
		if err != nil {
			mustLogFatal(err)
		}

		// Get Caddyfile input
		caddyfile, err := caddy.LoadCaddyfile(loadCaddyfile)