22

I've created a systemd service file (specifically for svnserve; I'm actually using the example from here https://stackoverflow.com/a/40584047/464087), and when I enable it, typing

sudo systemctl enable svnserve

I get the response

Failed to execute operation: Invalid argument

Running

sudo systemctl status svnserve

yields

● svnserve.service - Subversion protocol daemon
   Loaded: loaded (/etc/systemd/system/svnserve.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

not giving me any clue about anything being wrong. I can then start the service without any error, and it seems to be running as expected, and after starting systemctl status I still get no clue about anything being wrong:

● svnserve.service - Subversion protocol daemon
   Loaded: loaded (/etc/systemd/system/svnserve.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-01-09 22:10:14 UTC; 6s ago
  Process: 9677 ExecStart=/usr/bin/svnserve $DAEMON_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 9678 (svnserve)
    Tasks: 1
   Memory: 964.0K
      CPU: 2ms
   CGroup: /system.slice/svnserve.service
           └─9678 /usr/bin/svnserve --daemon --pid-file /run/svnserve/svnserve.pid --root /srv/svn/repos --log-file /var/log/svnserve/svnserve.log

So what does this error message mean? And to which level of things is "invalid argument" supposed to apply? An argument to the svnserve command? Some property in the service file? A command line argument to the servicectl command itself?

FWIW this is on a Ubuntu 16.04 LTS server.

EricS
  • 569
  • 1
  • 3
  • 15
  • I wondered it had to do with running "sudo systemctl enable svnserve" rather than "sudo systemctl enable svnserve.service" but no, that made no difference. – EricS Jan 09 '18 at 22:54

9 Answers9

23

If you copy/paste the file from a system with one encoding (e.g. Windows) to another (e.g. linux), there may be issues with the file encoding, or characters being interpreted differently. You can convert the file and re-analyze to see if it is being interpreted correctly.

  1. Run the analyzer

$ sudo systemd-analyze verify yourname.service /etc/systemd/system/yourname.service:1: Assignment outside of section. Ignoring.

  1. Fix the encoding of the service file, e.g. using vim (answer from here)

$ vim +"set nobomb | set fenc=utf8 | x" yourname.service

  1. Edit the file and remove any strange characters that are now exposed at e.g. the start of the file. e.g. it might have characters like ^[[200~

  2. Save the file and re-enable the service

$ sudo systemctl enable yourname.service

culix
  • 10,188
  • 6
  • 36
  • 52
  • 1
    ```sudo systemd-analyze verify yourname.service``` is what finally led me to the hidden issue. In my case I had some white space at the end of the file from a copy paste. – Robert Kearns Mar 17 '20 at 20:51
  • @RobertKearns Fantastic. Glad it helped! – culix Mar 17 '20 at 23:46
20

I had a similar case, in my case problem went away after removing the Alias line from the [Install] section. Thanks to Anton in another thread: https://stackoverflow.com/a/34978908/2711456 - alias' name may not be the same as service name.

T .
  • 376
  • 3
  • 5
  • 2
    Wasted hours on this. Why don't they make the error clearer... – sscirrus Jun 28 '20 at 03:31
  • Thanks for the solution. Still the same vague error message in 2022. I spent ages on this, as previous solutions actually suggested adding the Alias. – carpii Feb 05 '22 at 20:22
7

What I also found is the bug with comments (at least at systemd 219), if you have comment after any code of service file, it will failed to enable it. So bring comment to new string, or remove it. I tested and it works for me:

WantedBy=multi-user.target
# runs in init 3 (multi-user mode for linux)

this one will not work:

WantedBy=multi-user.target  # runs in init 3 (multi-user mode for linux)

some discussion is here: https://github.com/rabbitmq/rabbitmq-server/issues/1422

Evgeny
  • 71
  • 1
  • 1
3

I experienced the exactly same thing. Deleting "Alias" works, but actually, alias can have the same name with the service file.

The reason it doesn't work is related to the directory where service file is put.

What systemd enable does is creating an alias in the directory "/etc/systemd/system" and in the target directory which wants this service. If the original service file is already located in "/etc/systemd/system", when systemd tries to enable this service, the alias can't be created.

The solution is putting the service file in directory "/lib/systemd/system/", and it will work.

3

So, I guess we already have a similar answer. I just want to indicate the reason.

Answer:

cd /etc/systemd/system/multi-user.target.wants/  # it can be other WantedBy item
ls -lA              # notice that <your>.service is not a link
rm <your>.service   # remove it

And now try:

sudo systemctl enable <your>.service

It should create right link and enable your service.

Andrei
  • 750
  • 8
  • 9
  • Same here, `/etc/systemd/system/multi-user.target.wants/docker.service` was not a symlink to `/ib/systemd/system/docker.service` but some outdated, previous copy of it... removing the copy is what allowed `sudo systemctl enable ...` to now complete without error. – cueedee Mar 05 '20 at 10:15
2

you try this, i was resolved it:

  1. cd /etc/systemd/system/multi-user.target.wants

  2. ls

  3. find name service error "Failed to execute operation: Invalid argument"

  4. rm -rf yourname.service

  5. cd /etc/systemd/system/

  6. nano yourname.service

edit your content service (maybe your content mistake (checking symboy [, ],...bla..bla)

==> save it

  1. systemctl daemon-reload

  2. systemctl enable yourname.service

good luck!!!

2

After last line of your /etc/systemd/system/youunit.service file, CR symbol is required. Check it and remove /etc/systemd/system/multi-user.target.wants/youunit.service. Then try systemctl enable youunit again.

Joe Go
  • 21
  • 1
1

I my case the problem was that the service was a symlink to another file. systemd-analyze did not find any issue but systemctl enable failed. When I removed the symlink and copied the file, it started to work.

Leos Literak
  • 8,805
  • 19
  • 81
  • 156
0

In my case, my /etc/systemd/system/my-service.service was a symlink :S

Fulldump
  • 783
  • 5
  • 10