This commit is contained in:
Aliberk Sandıkçı 2023-07-30 14:09:14 +03:00
parent 667b057a19
commit f4635a5463
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
2 changed files with 7 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"os"
"runtime"
@ -21,16 +22,7 @@ func checkExists(path string) (bool, error) {
}
func Info() {
// A SAMPLE COMMAND FOR LOGGING OS INFORMATION TO A DEDICATED FILE
userhome, err := os.UserHomeDir() // TODO $HOME is not defined while running as daemon !!!
if err != nil {
log.Fatal(err)
}
// userhome := "/home/asandikci" // TEMPORARY
configDir := userhome + "/.config/" + ProgramName + "/"
// TODO Will be replaced with a Go Config Library
log.Print(configDir)
configDir := "/etc/godaemon1/"
if flag, err := checkExists(configDir); flag {
if err != nil {
log.Fatal(err)
@ -44,6 +36,10 @@ func Info() {
}{
{"OS", runtime.GOOS},
{"Time", time.Now().Format("2006.01.02 15:04:05")},
{"Go Root", runtime.GOROOT()},
{"Go Version", runtime.Version()},
{"Go Arch", runtime.GOARCH},
{"CPU Num", fmt.Sprintf("%v", runtime.NumCPU())},
}
f, err := os.Create(configDir + "godaemon1.conf")

View File

@ -23,7 +23,7 @@ sudo touch /etc/godaemon1/userdata.conf
sudo cat << EOF | sudo tee -a /etc/godaemon1/userdata.conf > /dev/null
The current working directory is: $PWD
You are logged in as $(whoami)
$HOME | $USER | $SUDO_USER
$HOME $USER $SUDO_USER
EOF
sudo chown root:root /etc/godaemon1/userdata.conf
sudo chmod 640 /etc/godaemon1/userdata.conf