-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support pid file. #610
Conversation
Why we need a pid file? |
You can also use that information (just do a |
I never needed that before but LGTM |
What happening if PID file already exist (ie: the app crash) ? app can be restarted without manually delete PID file ? To avoid any issue or conflict with System D, supervisor, or other kind of tools. I think PID file could be created only if -p flag or explicit configuration on app.ini are specified |
@0xBAADF00D You don't worry about the PID file exists or not. App can be restarted successfully if you remove the pid file. Just try the following command. gitea web
rm -rf custom/run/app.pid
kill -USR2 gitea_pid
cat custom/run/app.pid |
@appleboy What happens when a startup script also sets a PID? |
@Bwko What kind of start script do you use? |
what about windows ? it's work ? |
@ekozan Yes. Also working on Windows platform. |
Also working on start-stop-daemon command |
@@ -471,6 +472,19 @@ func IsRunUserMatchCurrentUser(runUser string) (string, bool) { | |||
return currentUser, runUser == currentUser | |||
} | |||
|
|||
func createPIDFile(pidPath string) { | |||
currentPid := os.Getpid() | |||
os.MkdirAll(filepath.Dir(pidPath), os.ModePerm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the error returned by os.MkdirAll()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@metalmatze Done! Please review again.
@appleboy Thanks 👍 When you add metalmatze suggestions I'll LGT-M 😄 |
@Bwko Done! |
log.Fatal(4, "Can' create PID folder on %s", err) | ||
} | ||
|
||
file, err := os.Create(pidPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting bkcsoft on this one:
Overall, change the format to this instead whenever possible. Keeps errors(variables) bound to their context(block).
if err := os.Create(...); err != nil { [...] }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bwko We need file
variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my bad 😅
func createPIDFile(pidPath string) { | ||
currentPid := os.Getpid() | ||
if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil { | ||
log.Fatal(4, "Can' create PID folder on %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicking: missing a t
here
LGTM |
need @metalmatze approve |
@lunny @Bwko @metalmatze Thanks |
We can restart the app automatically by the following command.