Score:1

Attempting to enable a custom service in Ubuntu 18.04 Minimal returns "Failed to enable unit: Unit file backuptos3.service does not exist."

es flag

Apologies for the length:

I posted the same post on Stack Overflow: https://stackoverflow.com/questions/69671377/attempting-to-enable-a-custom-service-in-ubuntu-18-04-minimal-returns-failed-to

On this system, I have AWS CLI2 installed, along with the supporting packages, and various generic packages like unzip and wget.

I have an AWS instance running Ubuntu 18.04 LTS Minimal (ami-006e7e4c46a45d7d7). I have a .service file (backuptos3.service) that I have created and is running on several CentOS servers. It performs a script. (Backup_To_S3.sh) There is a companion .timer file that is supposed to trigger this the .service file. (backuptos3.timer)

I have "Backup_To_S3.sh" in "/home/users/bin" with 755 permissions (which may not be the right word). The "backuptos3.service" and "backuptos3.timer" files are in "~/.config/systemd/user" with 755 permissions also. The owner here is the same as the owner of the folder.

When I run the command:

sudo systemctl enable backuptos3.service

I get the error: "Failed to enable unit: Unit file backuptos3.service does not exist."

I have not found a cogent explanation of why and what to do to fix it. Any Ideas?

I replaced the server (It's AWS after all) with a 18.04 LTS (Not minimal) but that did not fix it. I checked the release notes (on the off chance...) nothing.

This did not seem to fit: https://stackoverflow.com/questions/53297867/enable-docker-services-in-ubuntu-18-04

These two seemed to fit, but I don't understand what was going on: https://github.com/nix-community/lorri/issues/68 and https://github.com/abraunegg/onedrive/issues/250

I also saw this one: Failed to start gunicorn.service: Unit gunicorn.service not found. Ubunto 18.04. The problem is that the suggested answer is where my problem begins.

I used https://www.linux.com/training-tutorials/systemd-timers-two-use-cases-0/ to build the files initially.

I have included the .service and .timer files below.

# backuptos3.service

[Unit]
Description= Uploads Backups to AWS S3
Documentation= ""

[Service]
Type= simple
User= ubuntu
ExecStart= /home/ubuntu/bin/Backup_To_S3.sh

TimeoutStopSec= 21600 # 6 hours

[Install]
WantedBy= multi-user.target

and

# backuptos3.timer
[Unit]
Description=backuptos3

[Timer]
Unit=backuptos3.service
OnCalendar=*-*-* 02:30:00
Persistent=true

[Install]
WantedBy=basic.target

UPDATE: After a suggestion from Doug Smythies, I did a little more searching on enabling user vs root services. Found a stack overflow article (https://stackoverflow.com/questions/66534369/error-failed-to-enable-unit-invalid-argument) that discussed the Argument invalid issue. This led to another article (https://stackoverflow.com/questions/48177558/what-does-failed-to-execute-operation-invalid-argument-mean-when-running-syst) that had a systems analyzer sudo systemd-analyze verify yourname.service I ran this and came up with:

Configuration file /etc/systemd/system/./backuptos3.service is marked executable. Please remove executable permission bits. Proceeding anyway. backuptos3.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing. backuptos3.service: Failed to create backuptos3.service/start: Unit backuptos3.service is not loaded properly: Invalid argument. backuptos3.service: Command /home/centos/bin/PDFS3Uploader.sh is not executable: No such file or directory Attempted to remove disk file system, and we can't allow that.

I will be working through this block to see if I can make progress.

user535733 avatar
cn flag
Did you remember to run `sudo systemctl daemon-reload` after adding the .timer and .system files?
LeviRCoding avatar
es flag
I would forget initially to do so but would go back for it when I forgot. I did not think that there was an issue if I missed it on the first round. It appears to succeed when I run it. After another test. Same result.
Doug Smythies avatar
gn flag
I am not familiar with root (sudo run) services being in `~/.config/systemd/user`. That location seems incorrect to me. Services that I wrote are in `/etc/systemd/system` and `/etc/systemd/system/multi-user.target.wants`, the latter being a link to the former.
LeviRCoding avatar
es flag
I moved to the `/etc/systemd/system` set permissions appropriately then reloaded daemon., tried to enable. Invalid argument error.
Score:0
es flag

Doug Smythies was correct above. (Can't figure out how to give credit other than this.) I had several issues as noted in the block above.

The one that was returning the error I first posted had to do by placing the .service and .timer files in the wrong location.

Other issues had to do with permissions. I had to check in the .service file for the user and user directory as well as using

sudo chmod 775 <Service-name>

and

sudo chown ubuntu:ubuntu <Service-name>

I also found out that, somehow... I had double pasted my code into the .service file. (I have a guess: sometimes my right-click does pastes on both the depressing and the lift action of my mouse button.) Nano was useful here, obviously.

Thanks for all the help!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.