Forum > Linux PDAs

Service for Raspberry Pi

(1/2) > >>

nhatdung:
Hi!
I'm trying write a daemon service for raspberry pi use lazarus, follow the tutorial but the service cannot start.
I follow this
http://wiki.freepascal.org/Daemons_and_Services#Linux_.28only_for_older_Debian.29

any1 known how to make the service work ?

Thaddy:
Don't use the older example, but the example for fedora etc.

There is a recent thread here that shows you how. Raspbian also moved to Jessie, which means it uses systemd and not init.d. You may have to copy a part of the init.d configuration, though. I will see if I can edit the wiki to be more current. The examples are not very clear and outdated. But the above should help....

If you can't figure it out yourself, plz report back. I have several Pi's running fpc daemons and my Pi3 is due to arrive today <JAJ!>

nhatdung:
YAH, i also use jessie, let me try write 1 and see if can install it or not

nhatdung:
i cannot make it work
lazarus 1.2.4
seem i can install it correctly, i follow this tutorial

http://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

my code is really simple

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit DaemonUnit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, DaemonApp; type   { TDaemon1 }   TDaemon1 = class(TDaemon)    procedure DataModuleCreate(Sender: TObject);    procedure DataModuleDestroy(Sender: TObject);    procedure DataModuleExecute(Sender: TCustomDaemon);    procedure DataModuleShutDown(Sender: TCustomDaemon);    procedure DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);    procedure DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);    procedure Timer1Timer(Sender: TObject);  private    { private declarations }  public    { public declarations }  end;   { TMyThread }   TMyThread = class(TThread)  protected    procedure Execute; override;  end; var  Daemon1: TDaemon1;  implementation procedure RegisterDaemon;begin  RegisterDaemonClass(TDaemon1)end; {$R *.lfm} { TDaemon1 }procedure add_to_file(s: ansistring; FileName: string = 'log.log';  NewLine: boolean = True);var  f: TFileStream;begin  try    if FileExists(FileName) then    begin      f := TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyNone);      f.Seek(0, soEnd);    end    else      f := TFileStream.Create(FileName, fmCreate or fmShareDenyNone);    if NewLine then      s := s + #$D#$A;    f.Write(PChar(s)^, Length(s));    f.Free;  except  end;end; { TMyThread } procedure TMyThread.Execute;var s : string;begin  sleep(10000);  s := 'start delay @ ' + DateTimeToStr(Now);  add_to_file(s, '/home/pi/dung.txt');end; procedure TDaemon1.DataModuleCreate(Sender: TObject);beginend; procedure TDaemon1.DataModuleDestroy(Sender: TObject);beginend; procedure TDaemon1.DataModuleExecute(Sender: TCustomDaemon);beginend; procedure TDaemon1.DataModuleShutDown(Sender: TCustomDaemon);begin end; procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);var s : string;begin  s := 'start at ' + DateTimeToStr(Now);  add_to_file(s, '/home/pi/dung.txt');   TMyThread.Create(False);end; procedure TDaemon1.DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);var s : string;begin  s := 'finis at ' + DateTimeToStr(Now);  add_to_file(s, '/home/pi/dung.txt');end; procedure TDaemon1.Timer1Timer(Sender: TObject);var s : string;begin  s := DateTimeToStr(Now);  add_to_file(s, '/home/pi/dung.txt');end;  initialization  RegisterDaemon;end. whole data here:
https://www.dropbox.com/s/me1bcpbhr0wnuxb/testdaemon.zip?dl=0

trying install follow those tutorial seem it working but dunno why the script write to file not run

--- Quote ---
[Unit]
Description=My Script Service
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/pi/Projects/testdaemon/testdm

[Install]
WantedBy=multi-user.target




--- End quote ---


--- Quote ---pi@raspberrypi:~/Projects $ sudo systemctl status dung.service
‚óŹ dung.service - My Script Service
   Loaded: loaded (/lib/systemd/system/dung.service; enabled)
   Active: inactive (dead) since Fri 2016-04-08 03:43:42 UTC; 8min ago
  Process: 818 ExecStart=/home/pi/Projects/testdaemon/testdm (code=exited, statu                                                                                        s=0/SUCCESS)

Apr 08 03:43:42 raspberrypi testdm[818]: Usage: /home/pi/Projects/testdaemon...]
Apr 08 03:43:42 raspberrypi testdm[818]: Where command is one of the following:
Apr 08 03:43:42 raspberrypi testdm[818]: -i --install   To install the progr...e
Apr 08 03:43:42 raspberrypi testdm[818]: -u --uninstall To uninstall the service
Apr 08 03:43:42 raspberrypi testdm[818]: -r --run       To run the service
Apr 08 03:43:42 raspberrypi systemd[1]: Started My Script Service.
Hint: Some lines were ellipsized, use -l to show in full.

--- End quote ---

nhatdung:
still cannot make it work, anyone ?

Navigation

[0] Message Index

[#] Next page

Go to full version