Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
image board
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
random asynchronous nightmare distributor
image board
Commits
e962cfbc
Commit
e962cfbc
authored
Jul 6, 2021
by
Ophestra
Browse files
Options
Downloads
Patches
Plain Diff
lock store after opening, implement windows-specific restart function
parent
e774140e
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
cleanup.go
+26
-0
26 additions, 0 deletions
cleanup.go
restart.go
+2
-18
2 additions, 18 deletions
restart.go
restart_windows.go
+30
-0
30 additions, 0 deletions
restart_windows.go
store/paths.go
+5
-0
5 additions, 0 deletions
store/paths.go
store/store.go
+22
-0
22 additions, 0 deletions
store/store.go
with
85 additions
and
18 deletions
cleanup.go
0 → 100644
+
26
−
0
View file @
e962cfbc
package
main
import
(
"context"
log
"github.com/sirupsen/logrus"
"time"
)
func
cleanup
(
restart
bool
)
{
var
err
error
// Set restart
d
=
true
r
=
restart
// Close store
instance
.
Close
()
// Shutdown web server
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
err
=
server
.
Shutdown
(
ctx
)
if
err
!=
nil
{
log
.
Errorf
(
"Error while shutting down web server, %s"
,
err
)
}
}
This diff is collapsed.
Click to expand it.
restart.go
+
2
−
18
View file @
e962cfbc
// +build !windows
package
main
import
(
"context"
log
"github.com/sirupsen/logrus"
"os"
"syscall"
"time"
)
func
cleanup
(
restart
bool
)
{
var
err
error
// Set restart
d
=
true
r
=
restart
// Shutdown web server
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
err
=
server
.
Shutdown
(
ctx
)
if
err
!=
nil
{
log
.
Errorf
(
"Error while shutting down web server, %s"
,
err
)
}
}
func
restart
()
{
var
err
error
...
...
This diff is collapsed.
Click to expand it.
restart_windows.go
0 → 100644
+
30
−
0
View file @
e962cfbc
package
main
import
(
log
"github.com/sirupsen/logrus"
"os"
)
func
restart
()
{
if
_
,
err
:=
os
.
Stat
(
executable
);
err
!=
nil
{
log
.
Fatalf
(
"Unable to get executable path, %s"
,
err
)
os
.
Exit
(
1
)
}
log
.
Infof
(
"Program found at %s."
,
executable
)
wd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
log
.
Fatalf
(
"Unable to get working directory, %s"
,
err
)
os
.
Exit
(
1
)
}
log
.
Infof
(
"Current working directory is %s."
,
wd
)
_
,
err
=
os
.
StartProcess
(
executable
,
[]
string
{},
&
os
.
ProcAttr
{
Dir
:
wd
,
Env
:
nil
,
Files
:
[]
*
os
.
File
{
os
.
Stderr
,
os
.
Stdin
,
os
.
Stdout
},
Sys
:
nil
,
})
if
err
!=
nil
{
log
.
Fatalf
(
"Unable to create new process, %s"
,
err
)
os
.
Exit
(
1
)
}
}
This diff is collapsed.
Click to expand it.
store/paths.go
+
5
−
0
View file @
e962cfbc
...
...
@@ -4,6 +4,11 @@ import (
"strconv"
)
// LockPath returns path to lock file.
func
(
s
*
Store
)
LockPath
()
string
{
return
s
.
Path
+
"/lock"
}
// TagsDir returns path to tags.
func
(
s
*
Store
)
TagsDir
()
string
{
return
s
.
Path
+
"/tags"
...
...
This diff is collapsed.
Click to expand it.
store/store.go
+
22
−
0
View file @
e962cfbc
...
...
@@ -146,9 +146,31 @@ func NewStore(path string, single bool) *Store {
mutex
:
make
(
map
[
string
]
*
sync
.
RWMutex
),
}
}
if
store
.
file
(
store
.
LockPath
())
{
if
pid
,
err
:=
os
.
ReadFile
(
store
.
LockPath
());
err
!=
nil
{
log
.
Fatalf
(
"Store locked, lock file unreadable, %s"
,
err
)
log
.
Exit
(
1
)
}
else
{
log
.
Fatalf
(
"Store locked by process %s."
,
string
(
pid
))
log
.
Exit
(
1
)
}
}
if
err
:=
os
.
WriteFile
(
store
.
LockPath
(),
[]
byte
(
strconv
.
Itoa
(
os
.
Getpid
())),
store
.
PermissionFile
);
err
!=
nil
{
log
.
Fatalf
(
"Error locking store, %s"
,
err
)
log
.
Exit
(
1
)
}
return
store
}
// Close closes the store.
func
(
s
*
Store
)
Close
()
{
if
err
:=
os
.
Remove
(
s
.
LockPath
());
err
!=
nil
{
log
.
Fatalf
(
"Error unlocking store, %s"
,
err
)
log
.
Exit
(
1
)
}
log
.
Info
(
"Store closed."
)
}
// create sets up the store directory if it does not exist.
func
(
s
*
Store
)
create
()
error
{
// Check if exists
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment