You are not logged in.

#1 2015-08-28 19:00:44

Lax Lexis
Member
Registered: 2013-09-30
Posts: 80

[SOLVED][systemd] daemon does not start shell script after login

Good evening,
I want to start a script after login. The script is located in '/opt/nbfc/Linux/bin/ReleaseLinux/start-nbfcservice.sh'.
The service "nbfc" starts if I run the script by the command "sudo /opt/nbfc/Linux/bin/ReleaseLinux/start-nbfcservice.sh".

I have made a service file in '/etc/systemd/system/nbfc.service' with the following content:

[Unit]
Description=Starts NoteBook FanControll

[Service]
ExecStart=/opt/nbfc/Linux/bin/ReleaseLinux/start-nbfcservice.sh
Type=oneshot

[Install]
WantedBy=multi-user.target

I enabled this service by the command "sudo systemctl enable nbfc.service" and start the service by the command "sudo systemctl start nbfc.service".
The output of "sudo systemctl status nbfc.service" is the following:

● nbfc.service - Starts NoteBook FanControll
   Loaded: loaded (/etc/systemd/system/nbfc.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fr 2015-08-28 20:54:20 CEST; 4s ago
  Process: 5832 ExecStart=/opt/nbfc/Linux/bin/ReleaseLinux/start-nbfcservice.sh (code=exited, status=0/SUCCESS)
 Main PID: 5832 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nbfc.service

Aug 28 20:54:20 UX32VD systemd[1]: Starting Starts NoteBook FanControll...
Aug 28 20:54:20 UX32VD systemd[1]: Started Starts NoteBook FanControll.

But nothing happens! It does not work!

https://github.com/hirschmann/nbfc

Last edited by Lax Lexis (2015-08-29 07:59:09)

Offline

#2 2015-08-28 19:33:57

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED][systemd] daemon does not start shell script after login

That start-nbfservice.sh script, is it the same as https://github.com/hirschmann/nbfc/blob … service.sh?

That uses mono-service, which runs the service in the background as a daemon. To use that with systemd, you need Type=forking, otherwise the background process will be killed as soon as the foreground process exits. Then it's best to also specify a PIDFile and for that you need to either figure out what name mono-service uses for this by default (if that is always the same), or, more reliably, have systemd execute mono-service directly and specify a path for the PID file:

[Unit]
Description=Starts NoteBook FanControll

[Service]
ExecStart=/usr/bin/mono-service -l:/run/nbfc.pid -m:NbfcService /opt/nbfc/Linux/bin/ReleaseLinux/NbfcService.exe"
Type=forking
PIDFile=/run/nbfc.pid

[Install]
WantedBy=multi-user.target

You may want to check that the path to the .exe is correct.

Offline

#3 2015-08-28 20:38:46

Lax Lexis
Member
Registered: 2013-09-30
Posts: 80

Re: [SOLVED][systemd] daemon does not start shell script after login

@Raynman

Thanks so much! It works great. But you have forgotten a quote at the beginning on the path in your code field. wink

Here the output of "sudo systemctl status nbfc.service"

● nbfc.service - Starts NoteBook FanControll
   Loaded: loaded (/etc/systemd/system/nbfc.service; enabled; vendor preset: disabled)
   Active: active (running) since Fr 2015-08-28 22:30:36 CEST; 1min 12s ago
  Process: 560 ExecStart=/usr/bin/mono-service -l:/run/nbfc.pid -m:NbfcService /opt/nbfc/Linux/bin/ReleaseLinux/NbfcService.exe (code=exited, status=0/SUCCESS)
 Main PID: 564 (mono)
   CGroup: /system.slice/nbfc.service
           └─564 /usr/bin/mono /usr/lib/mono/4.5/mono-service.exe -l:/run/nbfc.pid -m:NbfcService /opt/nbfc/Linux/bin/ReleaseLinux/NbfcService.exe

Aug 28 22:30:36 UX32VD systemd[1]: Starting Starts NoteBook FanControll...
Aug 28 22:30:36 UX32VD systemd[1]: nbfc.service: PID file /run/nbfc.pid not readable (yet?) after start: No such file or directory
Aug 28 22:30:36 UX32VD systemd[1]: Started Starts NoteBook FanControll.
Aug 28 22:30:36 UX32VD mono[564]: NbfcService: Service NoteBookFanControlService started

Thanks again!

Offline

#4 2015-08-28 20:52:22

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED][systemd] daemon does not start shell script after login

Lax Lexis wrote:

@Raynman

Thanks so much! It works great. But you have forgotten a quote at the beginning on the path in your code field. wink

Actually, I removed the quote at the beginning after copy-pasting, but forgot to remove the one at the end smile Quotes are allowed, but not necessary here.

You still have a warning about the PID file. That might just be mono-service behaving somewhat badly (I've never used it myself) and creating that file only after it forks. Does a PID (and of course preferably the right one) eventually get written to that file?

Edit: and then please edit your original post and prepend [SOLVED] to the title.

Last edited by Raynman (2015-08-28 20:53:37)

Offline

#5 2015-08-29 08:14:58

Lax Lexis
Member
Registered: 2013-09-30
Posts: 80

Re: [SOLVED][systemd] daemon does not start shell script after login

Raynman wrote:

Does a PID (and of course preferably the right one) eventually get written to that file?

There are 10 processes of

/usr/bin/mono /usr/lib/mono/4.5/mono-service.exe -l:/run/nbfc.pid -m:NbfcService /opt/nbfc/Linux/bin/ReleaseLinux/NbfcService.exe 

and thus 10 PIDs.

In the "/run/nbfc.pid" is only one of these listed.

Offline

Board footer

Powered by FluxBB