You are not logged in.

#1 2014-01-16 14:58:30

vibee
Member
Registered: 2013-06-15
Posts: 38

[solved] Running a systemd script as root on startup

Hello,

I wrote following shell script in order to restart vsftpd when my dynamic wan ip adress changes:

#!/bin/bash
oldip=`xxxdyndns.com +short`
while :
do
newip=`dig xxxdyndns.com +short`
	if [ $newip != $oldip ]; then
           echo "renewd ip. new ip: $newip"
	   oldip=$newip
 	   systemctl restart vsftpd.service
	fi
	sleep 5m
done

exit 0

The script needs to be run with root privileges (due to the systemctl restart line).

I want the script to be run when my system starts, so I thought about writing a systemd service file. Unfortunately, I could not find out how to tell systemd that it shall run the script as root. I'm sure that this is a very novice question, but my board and google search did not tun out to be successful.

Last edited by vibee (2014-01-16 15:42:02)

Offline

#2 2014-01-16 15:25:59

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] Running a systemd script as root on startup

Have you tried a service with

User=root

similar to e.g. https://wiki.archlinux.org/index.php/Sy … ces#Gitlab ?

Last edited by karol (2014-01-16 15:28:37)

Offline

#3 2014-01-16 15:42:28

vibee
Member
Registered: 2013-06-15
Posts: 38

Re: [solved] Running a systemd script as root on startup

Hooray, that's it. Thank you.

Offline

Board footer

Powered by FluxBB