Can Gambas be used to write a system service?

Post your Gambas programming questions here.
Post Reply
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Can Gambas be used to write a system service?

Post by sadams54 »

Unfortunately the search feature does not allow us to search on "system service" so unable to see if this is already answered.

I am wanting to know if we can write a system service in gambas? What restrictions are there? I assume we can't put in a GUI for it.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Can Gambas be used to write a system service?

Post by cage »

Yes you can if you are talking about running terminal commands. Try using the Gambas terminal view you can make a GUI for it. Look on the Gambas farm for setting up the terminal view.
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Can Gambas be used to write a system service?

Post by sadams54 »

I would love to access the software farm and take a look however I can't. Gambas locks up sitting waiting on the software farm. I can register or login. well I don't have a login so that means register. But register just times out waiting for me to answer an e-mail that never arrives. And yes I am giving it the correct email and checking it. So I can't see the software farm and the only option gambas gives is a command line project that does not allow me to create a window to view for messages.
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Can Gambas be used to write a system service?

Post by cage »

You can access the farm directly at https://farm.gambas.one/. However here is the source code for a program that I use. It's nothing fancy but gets the job done.

Code: Select all

' Gambas class file

''NEEDS gb.form.terminal
Public TermCmd As String
Public CmdNum As Integer
TerminalView1 As TerminalView
pProcess As Process
Timer1 As Timer
HBox1 As HBox

Public Sub Form_Open()

  Setup

  pProcess = TerminalView1.Exec(["bash"])

End

Public Sub Timer1_Timer()

  If pProcess Then
    If pProcess.State = Process.Stopped Then
      Timer1.Stop
      If CmdNum = 1 Then
        Message("Bash Command Has Completed!", " OK ")
      Endif
      pProcess = TerminalView1.Exec(["bash"])
      TerminalView1.SetFocus
    End If
  Endif

Catch
  Message.Info(Error.Text)

End

Public Sub Setup() 'This just sets up the Form and its components

  With Me
    .H = 480
    .W = 640
    .Padding = 5
    .Arrangement = Arrange.Vertical
    
  End With 
  
  With HBox1 = New HBox(Me)
    .Expand = True
    .Padding = 5
  End With
  'Setup TerminaqlView
  With TerminalView1 = New TerminalView(HBox1)
    .Expand = True
    .Blink = True
    .Background = Color.black
    .Foreground = Color.green
  End With

  With Timer1 = New Timer As "Timer1"
    .Enabled = True
    .Delay = 250
  End With

  Me.Center

End

Public Sub mnuClear_Click()

  TermCmd = "clear"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")

End

Public Sub Form_Close()

  Quit

End

Public Sub mnuClose_Click()

  Quit 0

End

Public Sub mnuCleanCache_Click()

  TermCmd = "sudo paccache -ruk0"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")
 
End

Public Sub CheckOrphans_Click()

  TermCmd = "pacman -Qtdq"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")

End

Public Sub mnuOrphansRemove_Click()

  TermCmd = "sudo pacman -Rns $(pacman -Qtdq)"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")

End


Public Sub MtBu_Click()

  TermCmd = "cp -avr /home/cage/.minetest/  /mnt/Secondary/Minetest_Backup"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n") 
  
End

Public Sub mnuUdate_Click()

  TermCmd = "yay -Syu"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")
 
End

Public Sub mnuCheckConfigSize_Click()

  TermCmd = "sudo du -sh ~/.cache/"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")
  
End

Public Sub mnuClearConfig_Click()

  TermCmd = "rm -rf ~/.cache/*"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")
 
End

Public Sub mmnUpdateCheck_Click()

  TermCmd = "checkupdates + aur"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")
  
End

Public Sub mnuRankMirrors_Click()

  TermCmd = "sudo reflector --protocol https --verbose --latest 25 --sort rate --save /etc/pacman.d/mirrorlist "
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")

End

Public Sub mnuRankEOS_Click()

  TermCmd = "sudo eos-rankmirrors --verbose"
  Timer1.Start
  TerminalView1.Input(TermCmd & ";\n")

End
Hope it helps you out.
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Can Gambas be used to write a system service?

Post by sadams54 »

I will have to do some digging on that and play a bit but thank you.

so you can take that program and do systemctl enable {progname} and have it run as a system service?
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Can Gambas be used to write a system service?

Post by BruceSteers »

I think you'll need to know how to set up and install a system service.

I don't think gambas does it for you but I'm sure a system service could be a gambas application.


Application.Daemon might interest you but I'm not sure it's relevant to a system service or not? lol.
https://gambaswiki.org/wiki/comp/gb/application/daemon
If at first you don't succeed , try doing something differently.
BruceS
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Can Gambas be used to write a system service?

Post by sadams54 »

I set up the stuff needed to run as a service, that is not too tough. but it fails and this is what I get as a result... I will start researching to find out why but if anybody sees it right off let me know. I am assuming it is the graphical component but at some points this service has to create a message in the GUI for the user when he needs to do something.

[root@localhost bin]# journalctl -xe
░░
░░ The job identifier is 7356.
Oct 04 16:00:13 localhost.localdomain audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel msg='unit=LCARS comm="systemd" exe="/usr/lib>
Oct 04 16:00:13 localhost.localdomain gbr3[18574]: cannot open display:
Oct 04 16:00:13 localhost.localdomain systemd[1]: LCARS.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/l ... temd-devel
░░
░░ An ExecStart= process belonging to unit LCARS.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Oct 04 16:00:13 localhost.localdomain systemd[1]: LCARS.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/l ... temd-devel
░░
░░ The unit LCARS.service has entered the 'failed' state with result 'exit-code'.
Oct 04 16:00:13 localhost.localdomain audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=kernel msg='unit=LCARS comm="systemd" exe="/usr/lib/>
Oct 04 16:01:01 localhost.localdomain CROND[18586]: (root) CMD (run-parts /etc/cron.hourly)
Oct 04 16:01:01 localhost.localdomain run-parts[18589]: (/etc/cron.hourly) starting 0anacron
Oct 04 16:01:01 localhost.localdomain run-parts[18595]: (/etc/cron.hourly) finished 0anacron
Oct 04 16:01:01 localhost.localdomain CROND[18585]: (root) CMDEND (run-parts /etc/cron.hourly)
Post Reply