Skip to content

Commit ae073ae

Browse files
Schedule user logged in (#470)
* refactoring handler darwin * refactoring string permission into an enum move detectSchedulePermission to the handler which broke many tests using the mock handler * fix tests * trying to use bootstrap commands * investigations * fix permissions * fix launchctl system job * parse launchctl print * print schedule status * remove agent before re-creating * update documentation with new features on launchd * check permission on cron scheduler * add user permission on test profile * move permission check to handler (as crond is different than systemd) * add tests on DetectSchedulePermission * docs: inform we can set the cron user manually in config * detect user after sudo * fix getting username on windows * use root user on system jobs * docs: explain how systemd services are generated * generate systemd service with User field * don't display epoch when there's no next run * fix wording * detect systemd service type (system or user) * systemd unit type system for background user * add a few new tests * simplify String method * add user parameter to CheckPermission * remove support for crond on windows * fix tests references to crond for windows * avoid checking links not already available :facepalm * nitpick comments * add a few more tests
1 parent edbea57 commit ae073ae

68 files changed

Lines changed: 2162 additions & 895 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
url: "https://${{ env.BRANCH_NAME }}.resticprofile.pages.dev/"
5757
pages_path: ./public/
58-
cmd_params: '--exclude="(linux.die.net|stackoverflow.com|scoop.sh)" --buffer-size=8192 --max-connections=10 --color=always --skip-tls-verification --header="User-Agent:curl/7.54.0" --timeout=20'
58+
cmd_params: '--exclude="(linux\.die\.net|stackoverflow\.com|scoop\.sh|0-18)" --buffer-size=8192 --max-connections=10 --color=always --skip-tls-verification --header="User-Agent:curl/7.54.0" --timeout=20'
5959

6060
- name: Publish to pages.dev
6161
continue-on-error: true # secrets are not set for PRs from forks

.github/workflows/release-doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
url: https://creativeprojects.github.io/resticprofile/
5151
pages_path: ./www/
52-
cmd_params: '--exclude="(linux.die.net|stackoverflow.com|scoop.sh)" --buffer-size=8192 --max-connections-per-host=5 --rate-limit=5 --timeout=20 --header="User-Agent:curl/7.54.0" --skip-tls-verification'
52+
cmd_params: '--exclude="(linux\.die\.net|stackoverflow\.com|scoop\.sh|0-18)" --buffer-size=8192 --max-connections-per-host=5 --rate-limit=5 --timeout=20 --header="User-Agent:curl/7.54.0" --skip-tls-verification'
5353

5454
- name: Deploy to GitHub Pages
5555
uses: peaceiris/actions-gh-pages@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
.DS_Store
55
/examples/private
6+
/examples/*-log.txt
67
/build/restic*
78
/build/rclone*
89
/dist
10+
/crontab
911

1012
# binary
1113
/resticprofile*

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ${TMP_MOUNT_DARWIN}:
194194
# Mount tmpfs on linux
195195
${TMP_MOUNT_LINUX}:
196196
mkdir -p ${TMP_MOUNT_LINUX}
197-
sudo mount -t tmpfs -o "rw,relatime,size=2097152k" tmpfs ${TMP_MOUNT_LINUX}
197+
sudo mount -t tmpfs -o "rw,relatime,size=2097152k,uid=`id -u`,gid=`id -g`" tmpfs ${TMP_MOUNT_LINUX}
198198

199199
rest-server:
200200
@echo "[*] $@"
@@ -298,7 +298,7 @@ checkdoc:
298298
.PHONY: checklinks
299299
checklinks:
300300
@echo "[*] $@"
301-
muffet -b 8192 --max-connections=10 --exclude="(linux.die.net|stackoverflow.com|scoop.sh)" http://localhost:1313/resticprofile/
301+
muffet -b 8192 --max-connections=10 --exclude="(linux\.die\.net|stackoverflow\.com|scoop\.sh|0-18)" http://localhost:1313/resticprofile/
302302

303303
.PHONY: lint
304304
lint: $(GOBIN)/golangci-lint

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ignore:
1212
- syslog.go
1313
- syslog_windows.go
1414
- schtasks/permission.go
15+
- user/user_systemd.go
1516
- "**/mocks/*.go"
1617

1718
codecov:

commands_schedule_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package main
24

35
import (
@@ -40,11 +42,13 @@ profiles:
4042
profile-schedule-inline:
4143
backup:
4244
schedule: "*:00,30"
45+
schedule-permission: "user"
4346
4447
profile-schedule-struct:
4548
backup:
4649
schedule:
4750
at: "*:20,50"
51+
permission: "user"
4852
4953
`
5054

constants/value.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package constants
22

33
// Parameter values
44
const (
5+
SchedulePermissionAuto = "auto"
6+
SchedulePermissionSystem = "system"
57
SchedulePermissionUser = "user"
68
SchedulePermissionUserLoggedOn = "user_logged_on"
79
SchedulePermissionUserLoggedIn = "user_logged_in"
8-
SchedulePermissionSystem = "system"
9-
SchedulePriorityBackground = "background"
10-
SchedulePriorityStandard = "standard"
10+
11+
SchedulePriorityBackground = "background"
12+
SchedulePriorityStandard = "standard"
1113

1214
VerbosityNone = 0
1315
VerbosityLevel1 = 1

crond/crontab.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
//go:build !windows
2+
13
package crond
24

35
import (
46
"errors"
57
"fmt"
68
"io"
7-
"os/user"
89
"regexp"
910
"strings"
1011

12+
"github.com/creativeprojects/resticprofile/user"
1113
"github.com/spf13/afero"
1214
)
1315

@@ -172,9 +174,9 @@ func (c *Crontab) LoadCurrent() (content string, err error) {
172174

173175
func (c *Crontab) username() string {
174176
if len(c.user) == 0 {
175-
if current, err := user.Current(); err == nil {
176-
c.user = current.Username
177-
}
177+
current := user.Current()
178+
c.user = current.Username
179+
178180
if len(c.user) == 0 || strings.ContainsAny(c.user, "\t \n\r") {
179181
c.user = "root"
180182
}

crond/crontab_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package crond
24

35
import (

crond/entry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package crond
24

35
import (

0 commit comments

Comments
 (0)