创建软链接
()
| 296 | |
| 297 | // 创建软链接 |
| 298 | func (this *AppCmd) createSymLinks() error { |
| 299 | if runtime.GOOS != "linux" { |
| 300 | return nil |
| 301 | } |
| 302 | |
| 303 | var exe, _ = os.Executable() |
| 304 | if len(exe) == 0 { |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | var errorList = []string{} |
| 309 | |
| 310 | // bin |
| 311 | { |
| 312 | var target = "/usr/bin/" + teaconst.ProcessName |
| 313 | old, _ := filepath.EvalSymlinks(target) |
| 314 | if old != exe { |
| 315 | _ = os.Remove(target) |
| 316 | err := os.Symlink(exe, target) |
| 317 | if err != nil { |
| 318 | errorList = append(errorList, err.Error()) |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // log |
| 324 | { |
| 325 | var realPath = filepath.Dir(filepath.Dir(exe)) + "/logs/run.log" |
| 326 | var target = "/var/log/" + teaconst.ProcessName + ".log" |
| 327 | old, _ := filepath.EvalSymlinks(target) |
| 328 | if old != realPath { |
| 329 | _ = os.Remove(target) |
| 330 | err := os.Symlink(realPath, target) |
| 331 | if err != nil { |
| 332 | errorList = append(errorList, err.Error()) |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if len(errorList) > 0 { |
| 338 | return errors.New(strings.Join(errorList, "\n")) |
| 339 | } |
| 340 | |
| 341 | return nil |
| 342 | } |
| 343 | |
| 344 | func (this *AppCmd) callDirective(code string) { |
| 345 | for _, directive := range this.directives { |