Compare commits

...

3 Commits

Author SHA1 Message Date
efaa9759c9 Add shims to path 2025-06-27 18:31:15 +02:00
845230529c Ditch "sh -c" since we have no sh 2025-06-27 18:28:21 +02:00
26ec0e38b2 Resolve .cron in cwd 2025-06-27 18:26:27 +02:00
5 changed files with 31 additions and 12 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.log
*.cron

3
crontabd/build.sh Normal file
View File

@@ -0,0 +1,3 @@
nssm stop crontabd
go build .
nssm start crontabd

BIN
crontabd/crontabd.exe (Stored with Git LFS)

Binary file not shown.

View File

@@ -119,7 +119,7 @@ func loadCronJobs() error {
func createJobFunc(job CronJob) func() {
return func() {
cmd := exec.Command("sh", "-c", job.Command)
cmd := exec.Command(job.Command)
output, err := cmd.CombinedOutput()
if err != nil {
logger.Error("Failed to execute command '%s': %v", job.Command, err)
@@ -133,17 +133,31 @@ func createJobFunc(job CronJob) func() {
func resolveCrontabPath() (string, error) {
// Resolve crontab file location
homeDir, err := os.UserHomeDir()
// homeDir, err := os.UserHomeDir()
// if err != nil {
// return "", fmt.Errorf("failed to get user home directory: %v", err)
// }
// userName := os.Getenv("USERNAME")
// crontabFile = filepath.Join(homeDir, "crontab", userName+".cron")
// crontabFile, err = filepath.Abs(crontabFile)
// if err != nil {
// return "", fmt.Errorf("failed to get absolute path: %v", err)
// }
// crontabFile = filepath.Clean(crontabFile)
// Never mind this fucking noise
// When running shit with nssm we have to run it with a system account
// And the home of that one is deep within system32
// I'm not going to poke around in system32
// To make it run with the local account requires the password of the account
// Even if the account has no fucking password
// So we're just going to look for it in the cwd and call it a day
cwd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get user home directory: %v", err)
return "", fmt.Errorf("failed to get current working directory: %v", err)
}
userName := os.Getenv("USERNAME")
crontabFile = filepath.Join(homeDir, "crontab", userName+".cron")
crontabFile, err = filepath.Abs(crontabFile)
if err != nil {
return "", fmt.Errorf("failed to get absolute path: %v", err)
}
crontabFile = filepath.Clean(crontabFile)
crontabFile = filepath.Join(cwd, "crontab.cron")
return crontabFile, nil
}

View File

@@ -2,6 +2,7 @@ nssm install crontabd 'C:\Users\Administrator\Seafile\Projects-Go\GoProjects\cro
nssm set crontabd AppDirectory 'C:\Users\Administrator\Seafile\Projects-Go\GoProjects\crontab\crontabd'
nssm set crontabd AppExit Default Restart
nssm set crontabd DisplayName crontabd
nssm set crontabd AppEnvironmentExtra :PATH='C:\Users\Administrator\scoop\shims'
nssm set crontabd ObjectName LocalSystem
nssm set crontabd Start SERVICE_AUTO_START
nssm set crontabd Type SERVICE_WIN32_OWN_PROCESS