You are not logged in.

#1 2012-10-22 12:32:31

capoeira
Member
From: Vila Velha - Brasil
Registered: 2010-05-25
Posts: 470

problem substituting crond with systemd

trying to run a script 3 minutes after startup


acording to journal the timer starts fine but systemctl reports:


ntpd_packages_backintime.service                         loaded failed failed        ntpd, packages and backintime

the timer:

[studio@localhost ~]$ cat /etc/systemd/system/ntpd_packages_backintime.timer 
[Timer]
OnStartupSec=180

[Install]
WantedBy=multi-user.target

the service

[studio@localhost ~]$ cat /etc/systemd/system/ntpd_packages_backintime.service 
[Unit]
Description=ntpd, packages and backintime

[Service]
ExecStart=/usr/bin/script_ntpd_packages_backintime 

[Install]
WantedBy=multi-user.target 

the script

[studio@localhost ~]$ cat /usr/bin/script_ntpd_packages_backintime 
#!/bin/sh

ntpd -q && hwclock -w
pacman -Qqe | grep -vx "$(pacman -Qqm)" > /home/backup/Packages
pacman -Qqm > /home/backup/Packages.aur
/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime  --backup-job

I'm not very into all this stuff, so if there is an obvious error, please be so kind to tell me.

Offline

#2 2012-10-22 14:13:10

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: problem substituting crond with systemd

It is better to create a service file for every single task you try to achieve instead of appending all commands to one script.
You can read more about how to write your service files here .
Have a look at this option:

wiki wrote:

Type=oneshot: This is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit= as well so that systemd still considers the service as active after the process has exited.

capoeira wrote:

pacman -Qqe | grep -vx "$(pacman -Qqm)" > /home/backup/Packages
pacman -Qqm > /home/backup/Packages.aur

Create a seperate script and service file for this.
Also write a seperate service for adjusting the time.

capoeira wrote:

/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime  --backup-job

Backup jobs can be done by cron, too. It makes sense to backup more frequently, especially if you do not reboot every day.

Offline

#3 2012-10-23 18:25:26

capoeira
Member
From: Vila Velha - Brasil
Registered: 2010-05-25
Posts: 470

Re: problem substituting crond with systemd

teateawhy wrote:

It is better to create a service file for every single task you try to achieve instead of appending all commands to one script.
You can read more about how to write your service files here .
Have a look at this option:

wiki wrote:

Type=oneshot: This is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit= as well so that systemd still considers the service as active after the process has exited.

capoeira wrote:

pacman -Qqe | grep -vx "$(pacman -Qqm)" > /home/backup/Packages
pacman -Qqm > /home/backup/Packages.aur

Create a seperate script and service file for this.
Also write a seperate service for adjusting the time.

I created seperate files but it didn't work.
but then, after looking in journal I realized that I didn't make the scripts executable. stupid me, but I must say, this is still very unhandy.
now the scripts work, though backintime gives an error message it isn't configured, It's strange because it works in terminal under root. It doesn't work in terminal with sudo though.

teateawhy wrote:

It is better to create a service file for every single task you try to achieve instead of appending all commands to one script.

Backup jobs can be done by cron, too. It makes sense to backup more frequently, especially if you do not reboot every day.

I'm glad I can live without cron now. I do audio work and a starting cron job can ruin a recording session. I also boot every morning, at least.

Offline

#4 2012-10-23 19:45:23

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: problem substituting crond with systemd

Good you could solve the problem with the scripts. I am sorry i did not understand before, why you do not want to use cron, the title "substituting cron with systemd" says all.
As systemd runs its services as root unless using the "user=" option, it is strange backintime does not work, indeed.

Offline

#5 2012-10-23 20:21:23

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: problem substituting crond with systemd

For the backintime problem: It might be that backintime looks for config files under $HOME somewhere. When starting a job with systemd, $HOME is not set for you. Try putting:

Environment=HOME=/root

into the Service section of the backintime service unit so that not only will it run as root, but will also know where root's home directory is.

Offline

#6 2012-10-24 10:29:09

capoeira
Member
From: Vila Velha - Brasil
Registered: 2010-05-25
Posts: 470

Re: problem substituting crond with systemd

ataraxia wrote:

For the backintime problem: It might be that backintime looks for config files under $HOME somewhere. When starting a job with systemd, $HOME is not set for you. Try putting:

Environment=HOME=/root

into the Service section of the backintime service unit so that not only will it run as root, but will also know where root's home directory is.

unfortuanatly this didn't work

the comand also didn't work with cron AFTER e uninstalled the gnome dependencies for the backintime gui. Before it worked

I'll ask on the backintime page

Offline

Board footer

Powered by FluxBB