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 package main
import ( import (
"fmt"
"log" "log"
"os" "os"
"runtime" "runtime"
@ -21,16 +22,7 @@ func checkExists(path string) (bool, error) {
} }
func Info() { func Info() {
// A SAMPLE COMMAND FOR LOGGING OS INFORMATION TO A DEDICATED FILE configDir := "/etc/godaemon1/"
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)
if flag, err := checkExists(configDir); flag { if flag, err := checkExists(configDir); flag {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -44,6 +36,10 @@ func Info() {
}{ }{
{"OS", runtime.GOOS}, {"OS", runtime.GOOS},
{"Time", time.Now().Format("2006.01.02 15:04:05")}, {"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") 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 sudo cat << EOF | sudo tee -a /etc/godaemon1/userdata.conf > /dev/null
The current working directory is: $PWD The current working directory is: $PWD
You are logged in as $(whoami) You are logged in as $(whoami)
$HOME | $USER | $SUDO_USER $HOME $USER $SUDO_USER
EOF EOF
sudo chown root:root /etc/godaemon1/userdata.conf sudo chown root:root /etc/godaemon1/userdata.conf
sudo chmod 640 /etc/godaemon1/userdata.conf sudo chmod 640 /etc/godaemon1/userdata.conf