github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/conf/deploy/supervisor/supervisor_program.go (about)

     1  package supervisor
     2  
     3  import (
     4  	"syscall"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/base/cmd"
     7  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
     8  	"github.com/machinefi/w3bstream/pkg/depends/conf/section_config"
     9  )
    10  
    11  type Program struct {
    12  	section_config.Section
    13  	// Command which will be run when supervisord started
    14  	Command cmd.Command `name:"command"`
    15  	// AutoStart if true, program will start automatically when supervisor start
    16  	AutoStart bool `name:"autostart"`
    17  	// AutoRestart Specifies if supervisord should automatically restart program
    18  	AutoRestart bool `name:"autorestart"`
    19  	// StartSecs The total seconds which the program needs to stay running after
    20  	// a startup to consider the start successful (moving the process from the
    21  	// `STARTING` state to the `RUNNING` state)
    22  	StartSecs types.Second `name:"startsecs"`
    23  	// StartRetries The number of serial failure attempts before program started
    24  	StartRetries int `name:"startretries"`
    25  	// User Instruct supervisord to switch users to this UNIX user account
    26  	// before doing any meaningful processing
    27  	User string `name:"user"`
    28  	// Priority the relative priority of the program in the start and shutdown ordering
    29  	Priority int `name:"priority"`
    30  	// ExitCodes The list of expected exit codes for this program used with `autorestart`.
    31  	ExitCodes types.CommaSplitInts `name:"exitcodes"`
    32  	//
    33  	// StopSignal The signal used to kill the program. It is normally one of:
    34  	// `TERM`, `HUP`, `INT`, `QUIT`, `KILL`, `USR1`, or `USR2`
    35  	StopSignal types.Signal `name:"stopsignal"`
    36  	// Envs program's env vars
    37  	Envs types.CommaSplitStrings `name:"environment"`
    38  	// StdoutLogFile Put process stdout output in this file
    39  	StdoutLogFile string `name:"stdout_logfile"`
    40  	// StdoutLogFileMaxBytes The maximum number of bytes that may be consumed by
    41  	// `StdoutLogFile`
    42  	StdoutLogFileMaxBytes types.MB `name:"stdout_logfile_maxbytes"`
    43  	// StdLogFileBackups The number of `stdout_logfile` backups to keep around
    44  	// resulting from process stdout log file rotation
    45  	StdoutLogFileBackups int `name:"stdout_logfile_backups"`
    46  }
    47  
    48  func (c Program) GetSection() *section_config.Section { return &c.Section }
    49  
    50  func (c *Program) SetSection(name, val string) {
    51  	c.Section.Name, c.Section.Value = name, val
    52  }
    53  
    54  func (c *Program) SetDefault() {
    55  	if c.Priority == 0 {
    56  		c.Priority = 500
    57  	}
    58  	if c.User == "" {
    59  		c.User = "root"
    60  	}
    61  	if c.ExitCodes == nil {
    62  		c.ExitCodes = types.CommaSplitInts{0}
    63  	}
    64  	if c.StopSignal == 0 {
    65  		c.StopSignal = types.Signal(syscall.SIGTERM)
    66  	}
    67  }
    68  
    69  func (c *Program) Write(filename string) error {
    70  	return section_config.NewEncoder('=').MarshalToFile(c, filename)
    71  }
    72  
    73  func (c *Program) Name() string { return "supervisor.conf" }
    74  
    75  func (c *Program) Bytes() ([]byte, error) {
    76  	return section_config.NewEncoder('=').Marshal(c)
    77  }