fix(pidproxy): handle new line
example: sshd
This commit is contained in:
parent
e2275ef05e
commit
b15066b513
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -130,8 +132,6 @@ func readPid(pidFile string) (int, error) {
|
|||||||
var (
|
var (
|
||||||
file *os.File
|
file *os.File
|
||||||
err error
|
err error
|
||||||
buf []byte
|
|
||||||
n int
|
|
||||||
pid64 int64
|
pid64 int64
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -142,18 +142,15 @@ func readPid(pidFile string) (int, error) {
|
|||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
buf = make([]byte, 1024)
|
scanner := bufio.NewScanner(file)
|
||||||
n, err = file.Read(buf)
|
if scanner.Scan() {
|
||||||
if err != nil {
|
if pid64, err = strconv.ParseInt(scanner.Text(), 10, 64); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pid64, err = strconv.ParseInt(string(buf[:n]), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return int(pid64), nil
|
return int(pid64), nil
|
||||||
|
} else {
|
||||||
|
return 0, errors.New("invalid scanner")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startProcess(arg0 string, args ...string) {
|
func startProcess(arg0 string, args ...string) {
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
FROM suyono/wingmate:alpine as source
|
||||||
|
|
||||||
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
RUN apk update && apk add tzdata openssh-server && \
|
||||||
|
ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime && ssh-keygen -A
|
||||||
|
|
||||||
|
COPY --from=source /usr/local/bin/wingmate /usr/local/bin/
|
||||||
|
COPY --from=source /usr/local/bin/wmpidproxy /usr/local/bin/
|
||||||
|
ADD --chmod=755 example/ssh-docker/entry.sh /usr/local/bin/entry.sh
|
||||||
|
ADD --chmod=755 example/ssh-docker/etc /etc
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
|
||||||
|
CMD [ "/usr/local/bin/wingmate" ]
|
||||||
7
example/ssh-docker/entry.sh
Normal file
7
example/ssh-docker/entry.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
exec "$@"
|
||||||
|
else
|
||||||
|
exec /usr/local/bin/wingmate
|
||||||
|
fi
|
||||||
3
example/ssh-docker/etc/wingmate/service/sshd.sh
Normal file
3
example/ssh-docker/etc/wingmate/service/sshd.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
exec /usr/local/bin/wmpidproxy --pid-file /var/run/sshd.pid -- /usr/sbin/sshd
|
||||||
Loading…
x
Reference in New Issue
Block a user