feat(logging): add log path configuration and implement logrotate policy
This commit is contained in:
+24
-1
@@ -78,10 +78,12 @@ ExecStart=%s -c %s
|
||||
User=%s
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
StandardOutput=append:%s/superfrpc_%d.log
|
||||
StandardError=append:%s/superfrpc_%d.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`, instanceID, frpcPath, configPath, runUser)
|
||||
`, instanceID, frpcPath, configPath, runUser, global.CurrentConfig.LogsPath, instanceID, global.CurrentConfig.LogsPath, instanceID)
|
||||
|
||||
servicePath := filepath.Join("/etc/systemd/system", serviceName+".service")
|
||||
if err := os.WriteFile(servicePath, []byte(serviceContent), 0644); err != nil {
|
||||
@@ -102,6 +104,27 @@ WantedBy=multi-user.target
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLogrotatePolicy() error {
|
||||
logrotatePath := "/etc/logrotate.d/superfrpc_frpclog"
|
||||
policyContent := fmt.Sprintf(`%s/superfrpc_*.log {
|
||||
daily
|
||||
rotate 7
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
}
|
||||
`, global.CurrentConfig.LogsPath)
|
||||
if err := os.WriteFile(logrotatePath, []byte(policyContent), 0644); err != nil {
|
||||
return fmt.Errorf("failed to create logrotate policy file: %w", err)
|
||||
}
|
||||
|
||||
if err := exec.Command("logrotate", "-f", logrotatePath).Run(); err != nil {
|
||||
return fmt.Errorf("failed to apply logrotate policy: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createInitDService(instanceID int, configPath, runUser string) error {
|
||||
frpcPath, err := GetFrpcPath()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user