Skip to main content
Topic: Start a command on boot with superuser access (Read 3272 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Start a command on boot with superuser access

Hi again everybody, I have another noobish question. I thought /etc/rc.local was the file I could use to add programs to boot? Is that only a SysV thing? Anyways, I compiled proftpd from the Arch AUR as its the only FTP daemon that I can make work the way I want it to, I'm awful at setting up config files lol. I know that proftpd works now as I can run the command via SSH & the FTP daemon starts to work. What file can I use to get programs to start with sudo?
I'm not the most tech-savvy user, please keep things simple. I'll get the hang of this stuff eventually..

Artix with OpenRC uses like 200-300mb of RAM less than Manjaro SystemD running the same stuff. That's pretty cool huh?
I'd like to give a big thank you to all of you guys here at Artix forums, thank you for answering all of my questions & helping me get setup, I am very thankful that there are so many experienced users here!

Re: Start a command on boot with superuser access

Reply #1
This is what I did, thought it would work but unfortunately its still not working.
sudo chmod +x /etc/rc.local
sudo rc-update add /etc/rc.local default
did a reboot but unfortunately its still not working. I re-edited the /etc/rc.local & added "sudo" in before proftpd but unfortunately that didn't make it work either.
When I try to do 'sudo rc-service /etc/rc.local start' it does this:
rc-service: Exec format error
I also tried doing the same thing in /etc/init.d/
sudo chmod +x /etc/init.d/proftpd
sudo rc-update add /etc/init.d/proftpd default
but this didn't work either. However I have found a work-around by adding "proftpd" in the /etc/init.d/xdm
How can I make a script bootable with sudo (superuser) access?

Re: Start a command on boot with superuser access

Reply #2
Someone can correct me on this, but I believe rc.local is generally considered unnecessary and most openrc distributions don't provide it. First of all, for packages like this, you need to check the PKGBUILD. Looking at what is in the AUR, you can see that it's specifically built with systemd meaning that you'll need to change the configuration. It may be sufficient to simply remove the "--with-systemd" line. It may not be. For example, you may want to enable pam. You'll probably have to read the documentation to determine what configuration is right for you. Whatever the case, you'll definitely need to alter the PKGBUILD since it is written specifically for systemd systems. Alternatively, you could just compile it locally yourself, but AUR is fairly convenient and it's probably easier just to slightly modify the PKGBUILD.

Additionally, you'll want to use an initscript for proftpd instead of messing with rc.local. All the init scripts on your system should be in /etc/init.d. Of course, this package isn't in Artix, so you'll have to get the init script from somewhere. Your best bet is probably just to get the one from gentoo and then modify the paths a bit for Arch-based systems. Here's what I have.

Code: [Select]
#!/usr/bin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_started_commands="reload"

depend() {
need net
use logger dns mysql postgresql antivirus
}

check_configuration() {
if [ ! -e /etc/proftpd/proftpd.conf ] ; then
eerror "To execute the ProFTPD server you need a /etc/proftpd/proftpd.conf configuration"
eerror "file. In /etc/proftpd you can find a sample configuration."
return 1
fi
/usr/bin/proftpd -t &>/dev/null
if [ $? -ne 0 ] ; then
eerror "The ProFTPD configuration file /etc/proftpd/proftpd.conf is invalid! You have to"
eerror "fix your configuration in order to run the ProFTPD server. For more information"
eerror "you may execute the ProFTPD configuration check '/usr/bin/proftpd -t'."
return 2
fi
}

start() {
checkpath -d /run/proftpd
[ "${RC_CMD}" = "restart" ] || check_configuration || return 1
ebegin "Starting ProFTPD"
start-stop-daemon --start --quiet \
--exec /usr/bin/proftpd \
--pidfile /run/proftpd/proftpd.pid
eend $?
}

stop() {
[ "${RC_CMD}" != "restart" ] || check_configuration || return 1
ebegin "Stopping ProFTPD"
start-stop-daemon --stop --quiet --retry 20 \
--pidfile /run/proftpd/proftpd.pid
eend $?
}

reload() {
check_configuration || return 1
ebegin "Reloading ProFTPD"
start-stop-daemon --quiet --signal HUP \
--pidfile /run/proftpd/proftpd.pid
eend $?
}

As root, create a file named "proftpd" and put the above in there. Then after that, simply run.
Code: [Select]
# rc-update add proftpd default

That should enable it on boot.

Re: Start a command on boot with superuser access

Reply #3
OpenRC executes on startup all scripts inside /etc/local.d ending with .start and on shutdown those ending in .stop
The scripts must be executable (chmod +x). I use a local.start script which executes /etc/rc.local and put all my stuff in the latter.



 

Re: Start a command on boot with superuser access

Reply #4
Yea, I edited the pkgbuild & it worked out ok - it runs.
Thanks guys. I've got this bookmarked for future reference.