User avatar
Arkeen00
Posts: 7
Joined: Fri Sep 30, 2016 12:06 am

[Solved]Unable to enable systemd service (but able to start)

Mon Feb 06, 2017 11:13 pm

Hello RPi-ers !

Having some issue with Raspbian lately, I reinstalled it (Jessie PIXEL), and copied some scripts I had on my old former configuration. One of them is meant to launch OpenVPN (and another basic operation), and to be runned on startup. So I created a service file that launchs it. So far so good, the service works great when started with systemctl start, but error come when I want to systemctl enable it :

Code: Select all

$ sudo systemctl enable startvpn.service
Failed to execute operation: Bad message
I really don't know what is the problem is, the error message do not help, and it start just fine. Any Idea ?
Thanks in advance !

Here is my startvpn.service file :

Code: Select all

*** startvpn.service ***

[Unit]
Description=Start VPN
After=multi-user.target

[Service]
Type=forking
ExecStart=/bin/sh /usr/local/bin/startvpn.sh
User=pi
Restart=on-failure

[Install]
WantedBy=multi-user.target
And my very simple script launching OpenVPN, startvpn.sh :

Code: Select all

#! /bin/sh
rm -f /home/pi/Desktop/openvpn.log
sudo openvpn --config /etc/openvpn/config/my_conf_file.conf > /home/pi/Desktop/openvpn.log &
Last edited by Arkeen00 on Tue Feb 07, 2017 10:02 am, edited 1 time in total.

epoch1970
Posts: 6692
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Unable to enable systemd service (but able to start it)

Mon Feb 06, 2017 11:55 pm

Arkeen00 wrote:And my very simple script launching OpenVPN, startvpn.sh :

Code: Select all

#! /bin/sh
Do you have an extra space after the exclamation point?
You want "#!/bin/sh" instead
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
Arkeen00
Posts: 7
Joined: Fri Sep 30, 2016 12:06 am

Re: Unable to enable systemd service (but able to start it)

Tue Feb 07, 2017 2:15 am

Yeah, small mistake here, but the issue persist after correcting it, this is not the problem here ...

User avatar
Paeryn
Posts: 3305
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Unable to enable systemd service (but able to start it)

Tue Feb 07, 2017 3:36 am

Arkeen00 wrote: Here is my startvpn.service file :

Code: Select all

*** startvpn.service ***

[Unit]
Description=Start VPN
After=multi-user.target

[Service]
Type=forking
ExecStart=/bin/sh /usr/local/bin/startvpn.sh
User=pi
Restart=on-failure

[Install]
WantedBy=multi-user.target
Change that first line! Comment lines must begin with either # or ;
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

User avatar
Paeryn
Posts: 3305
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Unable to enable systemd service (but able to start it)

Tue Feb 07, 2017 3:39 am

epoch1970 wrote:
Arkeen00 wrote:And my very simple script launching OpenVPN, startvpn.sh :

Code: Select all

#! /bin/sh
Do you have an extra space after the exclamation point?
You want "#!/bin/sh" instead
That doesn't make any difference, spaces are allowed after the #!
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

User avatar
Arkeen00
Posts: 7
Joined: Fri Sep 30, 2016 12:06 am

Re: Unable to enable systemd service (but able to start it)

Tue Feb 07, 2017 10:01 am

Paeryn wrote:Change that first line! Comment lines must begin with either # or ;
That was the issue indeed ! Since I copy-pasted that from the Internet, I thought it was legit ... And then I don't really understand why the start command was working.

Anyway, thanks a lot !

Return to “Troubleshooting”