RaspberryPi/StartupServices
From charlesreid1
brief explanation of how to manipulate startup services on a raspberry pi SD card without having to actually run the pi and execute commands to enable/disable system services. handy if you are trying to modify what startup services run on a pi, especially if a particular startup service is preventing you from SSHing into the pi.
To have a startup service available to run on boot, you need a .service file in either /lib/systemd/system/ or /etc/systemd/system/. However, just having a service file in these folders does not automatically run them at boot, the service must be enabled first.
To enable a service with command line access, you would run systemctl enable servicename which would enable the service at /{etc,lib}/systemd/system/servicename.service to start on boot.
When doing this for a Raspberry Pi, you will be mounting the Pi's filesystem on the SD card on some other Linux computer. So you have to be careful about absolute vs relative paths. We assume here that the Raspberry Pi filesystem is mounted somewhere like
/media/ubuntu/boot /media/ubuntu/rootfs
We will deal with the rootfs partition for enabling startup services.
To enable a service manually, you must create a symlink to the .service file in /etc/systemd/system/multi-user.target.wants/ on the Pi. However, the symlink that is actually created should have a relative path, so that it is created on the SD card.
Starting from the Pi's root filesystem:
cd /media/ubuntu/rootfs
Now we create the symlink with the TARGET being absolute (it will end up pointing to the correct file once the Pi boots up), and the DESTINATION being relative (so the symlink ends up on the SD card, not the host system):
SERVICENAME="mydb"
ln -fs /etc/systemd/system/${SERVICENAME}.service etc/systemd/system/multi-user.target.wants/${SERVICENAME}.service