Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
url: "https://${{ env.BRANCH_NAME }}.resticprofile.pages.dev/"
pages_path: ./public/
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'
cmd_params: '--exclude="(linux\.die\.net|scoop\.sh|0-18)" --buffer-size=8192 --max-connections-per-host=8 --color=always --skip-tls-verification --header="User-Agent: Muffet/2.10.8" --timeout=20'

- name: Publish to pages.dev
continue-on-error: true # secrets are not set for PRs from forks
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
url: https://creativeprojects.github.io/resticprofile/
pages_path: ./www/
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'
cmd_params: '--exclude="(linux\.die\.net|scoop\.sh|0-18)" --buffer-size=8192 --max-connections-per-host=8 --timeout=20 --header="User-Agent: Muffet/2.10.8" --skip-tls-verification'

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ checkdoc:
.PHONY: checklinks
checklinks:
@echo "[*] $@"
muffet -b 8192 --max-connections=10 --exclude="(linux\.die\.net|stackoverflow\.com|scoop\.sh|0-18)" http://localhost:1313/resticprofile/
muffet -b 8192 --max-connections-per-host=8 \
--exclude="(linux\.die\.net|scoop\.sh|0-18)" \
--header="User-Agent: Muffet/$$(muffet --version)" \
http://localhost:1313/resticprofile/

.PHONY: lint
lint: $(GOBIN)/golangci-lint
Expand Down
2 changes: 2 additions & 0 deletions examples/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ longrun:
self:
inherit: default
status-file: /tmp/status.json
# systemd-drop-in-files: [ drop-in-example.conf ]
backup:
extended-status: true
source: ./
schedule:
at: "*:15,20,25"
permission: system
after-network-online: true
check:
schedule-permission: user
schedule:
Expand Down
2 changes: 1 addition & 1 deletion schedule/handler_crond.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *HandlerCrond) CheckPermission(user user.User, p Permission) bool {
return true

default:
if user.SudoRoot || user.Uid == 0 {
if user.IsRoot() {
return true
}
// last case is system (or undefined) + no sudo
Expand Down
3 changes: 1 addition & 2 deletions schedule/handler_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ func (h *HandlerLaunchd) CheckPermission(user user.User, p Permission) bool {
return true

default:
if user.SudoRoot || user.Uid == 0 {
// user has sudoed
if user.IsRoot() {
return true
}
// last case is system (or undefined) + no sudo
Expand Down
41 changes: 34 additions & 7 deletions schedule/handler_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,33 @@ func (h *HandlerSystemd) DisplayStatus(profileName string) error {

// CreateJob is creating the systemd unit and activating it
func (h *HandlerSystemd) CreateJob(job *Config, schedules []*calendar.Event, permission Permission) error {
unitType, user := permissionToSystemd(user.Current(), permission)
u := user.Current()
unitType, user := permissionToSystemd(u, permission)

if unitType == systemd.UserUnit && job.AfterNetworkOnline {
return fmt.Errorf("after-network-online is not available for \"user_logged_on\" permission schedules")
}

err := systemd.Generate(systemd.Config{
// check the user hasn't changed the permission, which could duplicate the unit (system & user)
otherUnitType := systemd.SystemUnit
if unitType == systemd.SystemUnit {
otherUnitType = systemd.UserUnit
}
if cfgs, _ := getConfigs(job.ProfileName, otherUnitType); len(cfgs) > 0 { // ignore errors here
for _, cfg := range cfgs {
if cfg.CommandName == job.CommandName && cfg.ProfileName == job.ProfileName {
// we'd better remove this schedule first
clog.Infof("removing existing unit with different permission")
err := h.RemoveJob(&cfg, PermissionFromConfig(cfg.Permission))
if err != nil {
return fmt.Errorf("cannot remove existing unit before scheduling with different permission. You might want to retry using sudo.")
}
}
}
}

unit := systemd.NewUnit(u)
err := unit.Generate(systemd.Config{
CommandLine: job.Command + " --no-prio " + job.Arguments.String(),
Environment: job.Environment,
WorkingDirectory: job.WorkingDirectory,
Expand Down Expand Up @@ -169,7 +189,9 @@ func (h *HandlerSystemd) CreateJob(job *Config, schedules []*calendar.Event, per
// RemoveJob is disabling the systemd unit and deleting the timer and service files
func (h *HandlerSystemd) RemoveJob(job *Config, permission Permission) error {
var err error
unitType, _ := permissionToSystemd(user.Current(), permission)
unit := systemd.NewUnit(user.Current())
u := user.Current()
unitType, _ := permissionToSystemd(u, permission)
serviceFile := systemd.GetServiceFile(job.ProfileName, job.CommandName)
unitLoaded, err := unitLoaded(serviceFile, unitType)
if err != nil {
Expand All @@ -195,7 +217,7 @@ func (h *HandlerSystemd) RemoveJob(job *Config, permission Permission) error {

systemdPath := systemd.GetSystemDir()
if unitType == systemd.UserUnit {
systemdPath, err = systemd.GetUserDir()
systemdPath, err = unit.GetUserDir()
if err != nil {
return nil
}
Expand Down Expand Up @@ -241,7 +263,12 @@ func (h *HandlerSystemd) DisplayJobStatus(job *Config) error {
if !unitLoaded {
return ErrScheduledJobNotFound
}
_ = runJournalCtlCommand(timerName, systemdType) // ignore errors on journalctl
if systemdType == systemd.UserUnit && user.Current().IsRoot() {
// journalctl doesn't accept the parameter "-M user@" (yet?)
clog.Warning("cannot load the journal from a user service as root")
} else {
_ = runJournalCtlCommand(timerName, systemdType) // ignore errors on journalctl
}
return runSystemctlCommand(timerName, systemctlStatus, systemdType, false)
}

Expand Down Expand Up @@ -294,7 +321,7 @@ func (h *HandlerSystemd) CheckPermission(user user.User, p Permission) bool {
return true

default:
if user.SudoRoot || user.Uid == 0 {
if user.IsRoot() {
return true
}
// last case is system (or undefined) + no sudo
Expand Down Expand Up @@ -476,7 +503,7 @@ func getConfigs(profileName string, unitType systemd.UnitType) ([]Config, error)
if unit.Load == unitNotFound {
continue
}
cfg, err := systemd.Read(unit.Unit, unitType)
cfg, err := systemd.NewUnit(user.Current()).Read(unit.Unit, unitType)
if err != nil {
clog.Errorf("cannot read information from unit %q: %s", unit.Unit, err)
continue
Expand Down
16 changes: 8 additions & 8 deletions systemd/drop_ins.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func getOwnedName(basename string) string {
return fmt.Sprintf("%s.resticprofile.conf", strings.TrimSuffix(basename, ext))
}

func IsTimerDropIn(file string) bool {
if f, err := fs.Open(file); err == nil {
func (u Unit) IsTimerDropIn(file string) bool {
if f, err := u.fs.Open(file); err == nil {
defer func() { _ = f.Close() }()
for reader := bufio.NewScanner(f); reader.Scan(); {
if timerDropInRegex.Match(reader.Bytes()) {
Expand All @@ -37,8 +37,8 @@ func IsTimerDropIn(file string) bool {
return false
}

func CreateDropIns(dir string, files []string) error {
if err := fs.MkdirAll(dir, 0o755); err != nil {
func (u Unit) createDropIns(dir string, files []string) error {
if err := u.fs.MkdirAll(dir, 0o755); err != nil {
return err
}

Expand All @@ -47,7 +47,7 @@ func CreateDropIns(dir string, files []string) error {
fileBasenamesOwned[getOwnedName(filepath.Base(file))] = struct{}{}
}

d, err := fs.Open(dir)
d, err := u.fs.Open(dir)
if err != nil {
return err
}
Expand All @@ -66,7 +66,7 @@ func CreateDropIns(dir string, files []string) error {
if createdByUs && !notOrphaned {
orphanPath := filepath.Join(dir, f.Name())
clog.Debugf("deleting orphaned drop-in file %v", orphanPath)
if err := fs.Remove(orphanPath); err != nil {
if err := u.fs.Remove(orphanPath); err != nil {
return err
}
}
Expand All @@ -79,13 +79,13 @@ func CreateDropIns(dir string, files []string) error {
dropInFileOwned := getOwnedName(dropInFileBase)
dstPath := filepath.Join(dir, dropInFileOwned)
clog.Debugf("writing %v", dstPath)
dst, err := fs.Create(dstPath)
dst, err := u.fs.Create(dstPath)
if err != nil {
return err
}
defer dst.Close()

src, err := fs.Open(dropInFilePath)
src, err := u.fs.Open(dropInFilePath)
if err != nil {
return err
}
Expand Down
Loading