Service for Raspberry Pi lazarus / 37-Linux PDAs ---------------------------------------------------------------------- nhatdung · 2016-04-07 07:45 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_olde r_Debian.29 any1 known how to make the service work ? ---------------------------------------------------------------------- Thaddy · 2016-04-07 08:21 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 ---------------------------------------------------------------------- nhatdung · 2016-04-08 03:04 YAH, i also use jessie, let me try write 1 and see if can install it or not ---------------------------------------------------------------------- nhatdung · 2016-04-08 04:41 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 Quotepi@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. ---------------------------------------------------------------------- nhatdung · 2016-04-14 11:34 still cannot make it work, anyone ? ---------------------------------------------------------------------- Thaddy · 2016-04-14 11:47 Plz, if you do what I wrote it will work....