func (dGroup DockerGroup) GenerateSystemdService() {
	// [Unit]
	// Description=Docker Application Container Engine
	// Documentation=https://docs.docker.com
	// After=network.target docker.socket
	// Requires=docker.socket

	// [Service]
	// Type=notify
	// ExecStart=/usr/bin/docker daemon -H fd://
	// MountFlags=slave
	// LimitNOFILE=1048576
	// LimitNPROC=1048576
	// LimitCORE=infinity

	// [Install]
	// WantedBy=multi-user.target

	conf := c.NewConfiguration()
	sectionUnit := conf.NewSection("Unit")
	descr := fmt.Sprint("Docker Application Container Engine for Team no", dGroup.Number)
	sectionUnit.Add("Description", descr)
	after := fmt.Sprint("network.target ", dGroup.Name, ".socket")
	sectionUnit.Add("After", after)

	sectionService := conf.NewSection("Service")
	sectionService.Add("Type", "notify")
	execStart := fmt.Sprint("/usr/bin/docker daemon ", dGroup.Options)
	// execStart := fmt.Sprint("/usr/bin/docker daemon -b docker", strconv.FormatInt(dGroup.Number, 10), " -g /var/lib/docker", " -G ", dGroup.Name, " --exec-root=/var/run/docker --pidfile=\"/var/run/", dGroup.Name, ".pid\" --bip 192.168.", dGroup.Number, ".1/24", " -H fd://")
	sectionService.Add("ExecStart", execStart)
	sectionService.Add("MountFlags", "slave")
	sectionService.Add("LimitNOFILE", "1048576")
	sectionService.Add("LimitNPROC", "1048576")
	sectionService.Add("LimitCORE", "infinity")

	sectionInstall := conf.NewSection("Install")
	sectionInstall.Add("WantedBy", "multi-user.target")

	fmt.Println(conf)
	confPath := fmt.Sprint("/etc/systemd/system/", dGroup.Name, ".service")
	err := c.Save(conf, confPath)
	if err != nil {
		log.Println(err)
	}
}
func (dGroup DockerGroup) GenerateSystemdSocket() {
	// [Unit]
	// Description=Docker Socket for the API
	// PartOf=docker.service

	// [Socket]
	// ListenStream=/var/run/docker.sock
	// SocketMode=0660
	// SocketUser=root
	// SocketGroup=docker

	// [Install]
	// WantedBy=sockets.target

	conf := c.NewConfiguration()
	sectionUnit := conf.NewSection("Unit")
	descr := fmt.Sprint("Docker Socket for the API for Team no", dGroup.Number)
	sectionUnit.Add("Description", descr)
	servicePath := fmt.Sprint(dGroup.Name, ".service")
	sectionUnit.Add("PartOf", servicePath)

	sectionSocket := conf.NewSection("Socket")
	socketPath := fmt.Sprint("/var/run/", dGroup.Name, ".socket")
	sectionSocket.Add("ListenStream", socketPath)
	sectionSocket.Add("SocketMode", "0660")
	sectionSocket.Add("SocketUser", "root")
	sectionSocket.Add("SocketGroup", dGroup.Name)

	sectionInstall := conf.NewSection("Install")
	sectionInstall.Add("WantedBy", "socket.target")

	fmt.Println(conf)
	socketConfigPath := fmt.Sprint("/etc/systemd/system/", dGroup.Name, ".socket")
	err := c.Save(conf, socketConfigPath)
	if err != nil {
		log.Println(err)
	}
}
Пример #3
0
// Read and modify a configuration file
func Example() {
	config, err := configparser.Read("/etc/config.ini")
	if err != nil {
		log.Fatal(err)
	}
	// Print the full configuration
	fmt.Println(config)

	// get a section
	section, err := config.Section("MYSQLD DEFAULT")
	if err != nil {
		log.Fatal(err)
	} else {
		fmt.Printf("TotalSendBufferMemory=%s\n", section.ValueOf("TotalSendBufferMemory"))

		// set new value
		var oldValue = section.SetValueFor("TotalSendBufferMemory", "256M")
		fmt.Printf("TotalSendBufferMemory=%s, old value=%s\n", section.ValueOf("TotalSendBufferMemory"), oldValue)

		// delete option
		oldValue = section.Delete("DefaultOperationRedoProblemAction")
		fmt.Println("Deleted DefaultOperationRedoProblemAction: " + oldValue)

		// add new options
		section.Add("innodb_buffer_pool_size", "64G")
		section.Add("innodb_buffer_pool_instances", "8")
	}

	// add a new section and options
	section = config.NewSection("NDBD MGM")
	section.Add("NodeId", "2")
	section.Add("HostName", "10.10.10.10")
	section.Add("PortNumber", "1186")
	section.Add("ArbitrationRank", "1")

	// find all sections ending with .webservers
	sections, err := config.Find(".webservers$")
	if err != nil {
		log.Fatal(err)
	}
	for _, section := range sections {
		fmt.Print(section)
	}
	// or
	config.PrintSection("dc1.webservers")

	sections, err = config.Delete("NDB_MGMD DEFAULT")
	if err != nil {
		log.Fatal(err)
	}
	// deleted sections
	for _, section := range sections {
		fmt.Print(section)
	}

	options := section.Options()
	fmt.Println(options["HostName"])

	// save the new config. the original will be renamed to /etc/config.ini.bak
	err = configparser.Save(config, "/etc/config.ini")
	if err != nil {
		log.Fatal(err)
	}
}