Thinstation / thinstation

A framework for making thin and light Linux based images for x86 based machines and thinclients.
https://www.thinstation.net/
788 stars 188 forks source link

The systemd service cannot be started automatically #717

Closed AlexanderZhirov closed 2 years ago

AlexanderZhirov commented 2 years ago

I need to display the IP address of a thin client in the corner of the screen. I decided to print it in the background of the image. I wrote a program in D language (a very simple program):

import arsd.jpeg;
import arsd.color;
import arsd.ttf;
import std.conv;
import std.stdio;
import std.file;

struct MyColor
{
    int r;
    int g;
    int b;
}

void main(string[] args)
{
    auto image = readJpeg(args[1].idup);
    auto tci = image.getAsTrueColorImage();

    import std.file;

    TtfFont font = TtfFont(cast(ubyte[]) std.file.read(args[2].idup));

    string ip = "IP: ";
    int printPosX = to!int(args[4].idup);
    int printPosY = to!int(args[5].idup);

    int width, height;
    auto bitmap = font.renderString(ip ~ args[3].idup, to!int(printPosY * 0.05), width, height);

    int xput = printPosX - to!int(printPosY * 0.05 * (1 + (ip ~ args[3].idup).length / 2));
    int yput = to!int(printPosY * 0.05);

    int bitmapOffset = 0;

    MyColor red = {255, 255, 255};

    foreach (y; 0 .. height)
    {
        if (y + yput >= image.height)
            break;

        foreach (x; 0 .. width)
        {
            scope (exit)
                bitmapOffset++;

            if (x + xput >= image.width)
                continue;

            image.setPixel(
                xput + x,
                yput + y,
                image.getPixel(xput + x, yput + y).alphaBlend(Color(red.r, red.g, red.b, bitmap[bitmapOffset]))
            );
        }
    }

    writeJpeg(args[1].idup, tci);
}

Based on this program, I created a service printip, file packages/printip/etc/systemd/system/printip.service:

[Unit]
Description=printip
DefaultDependencies=no
After=icewm-init.service
Before=display-manager.service

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/thinstation.env
ExecStart=/etc/init.d/printip
SyslogIdentifier=thinstation

[Install]
WantedBy=multi-user.target

Also created a link for autorun packages/printip/etc/systemd/system/multi-user.target.wants/printip.service. The startup script packages/printip/etc/init.d/printip looks like this:

#!/bin/sh

if [ -e /var/log/applications/resolutions ]; then
    printip \
        /etc/background.jpg \
        /root/.fonts/JetBrainsMono.ttf \
        "$(cat /etc/hosts | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')" \
        "$(cat /var/log/applications/resolutions | tail -n1 | sed 's/x[0-9]*//g')" \
        "$(cat /var/log/applications/resolutions | tail -n1 | sed 's/[0-9]*x//g')"
fi

I pass 5 values as arguments: background, font, IP address, screen width, screen height.

I include the package in the build. Loading up. No effect occurs.

ts_d85ed3156a39:~# systemctl status printip

● printip.service - printip
     Loaded: loaded (/etc/systemd/system/printip.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2022-04-28 18:10:02 MSK; 6min ago
    Process: 1825 ExecStart=/etc/init.d/printip (code=exited, status=0/SUCCESS)
   Main PID: 1825 (code=exited, status=0/SUCCESS)

апр 28 18:10:02 ts_d85ed3156a39 systemd[1]: Starting printip...
апр 28 18:10:02 ts_d85ed3156a39 systemd[1]: Started printip.

It feels like the /var/log/applications/resolutions file doesn't exist! But it ALREADY exists when IceWM is launched. I connect via ssh and see this file:

ts_d85ed3156a39:~# ls -l /var/log/applications/resolutions
-rw-r--r--    1 root     root           296 Apr 28 18:10 /var/log/applications/resolutions

I remove the check for the existence of the file /var/log/applications/resolutions from the startup script and rebuild the image again. This time, without checking, obvious startup errors are visible:

● printip.service - printip
     Loaded: loaded (/etc/systemd/system/printip.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-04-28 18:27:38 MSK; 18s ago
    Process: 1835 ExecStart=/etc/init.d/printip (code=exited, status=1/FAILURE)
   Main PID: 1835 (code=exited, status=1/FAILURE)

апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x41ce87]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x41c50c]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x4585ab]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x4584a5]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x4582fd]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? __libc_start_main [0x7f2b6c720e09]
апр 28 18:27:38 ts_d85ed3156a39 thinstation[1868]: ??:? [0x4039b9]
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=1/FAILURE
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: printip.service: Failed with result 'exit-code'.
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: Failed to start printip.

I check the log to find an error and I get this:

ts_d85ed3156a39:~# journalctl | grep printip
апр 28 18:27:37 ts_d85ed3156a39 systemd[1]: Starting printip...
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=1/FAILURE
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: printip.service: Failed with result 'exit-code'.
апр 28 18:27:38 ts_d85ed3156a39 systemd[1]: Failed to start printip.
апр 28 18:27:38 ts_d85ed3156a39 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=printip comm="systemd" exe="/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
ts_d85ed3156a39:~# journalctl | grep /var/log/applications/resolutions
апр 28 18:27:37 ts_d85ed3156a39 thinstation[1848]: cat: can't open '/var/log/applications/resolutions': No such file or directory
апр 28 18:27:37 ts_d85ed3156a39 thinstation[1858]: cat: can't open '/var/log/applications/resolutions': No such file or directory

Just those two screen resolution parameters that I'm trying to pass.

If I manually start the service, it turns out like this:

ts_d85ed3156a39:~# systemctl start printip
ts_d85ed3156a39:~# systemctl status printip

● printip.service - printip
     Loaded: loaded (/etc/systemd/system/printip.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2022-04-28 18:33:21 MSK; 15s ago
    Process: 3126 ExecStart=/etc/init.d/printip (code=exited, status=0/SUCCESS)
   Main PID: 3126 (code=exited, status=0/SUCCESS)

апр 28 18:33:20 ts_d85ed3156a39 systemd[1]: Starting printip...
апр 28 18:33:21 ts_d85ed3156a39 systemd[1]: Started printip.

изображение

I also tried to pass the global variable $CLIENT_IP as an argument, but nothing came out. There were also errors when starting, even manually starting the service. As I understand it, it is possible to pass global variables to systemd, but I could not do it by means of systemd through global definitions (through Environment=, EnvironmentFile=) nor through the systemctl --user import-environment command.

It is not even possible to pass arguments statically:

[root@TS_chroot]/build# cat packages/printip/etc/init.d/printip 
#!/bin/sh

printip \
    /etc/background.jpg \
    /root/.fonts/JetBrainsMono.ttf \
    "MyIpAddress" \
    1280 \
    1024

Result after reboot:

ts_d85ed3156a39:~# systemctl status printip

● printip.service - printip
     Loaded: loaded (/etc/systemd/system/printip.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-04-28 20:01:45 MSK; 32min ago
    Process: 1848 ExecStart=/etc/init.d/printip (code=exited, status=127)
   Main PID: 1848 (code=exited, status=127)

апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? [0x41c898]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? [0x4585ab]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? [0x4584a5]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? [0x4582fd]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? __libc_start_main [0x7fa361f55e09]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1849]: ??:? [0x4039b9]
апр 28 20:01:45 ts_d85ed3156a39 thinstation[1848]: /etc/init.d/printip: line 20: MyIpAddress: not found
апр 28 20:01:45 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=127/n/a
апр 28 20:01:45 ts_d85ed3156a39 systemd[1]: printip.service: Failed with result 'exit-code'.
апр 28 20:01:45 ts_d85ed3156a39 systemd[1]: Failed to start printip.

Please help me figure it out. How do I CORRECTLY pass the parameters I specified above as arguments so that the service starts automatically without errors?

AlexanderZhirov commented 2 years ago

UPD

As I understand it, the global variables that I am passing are completely absent.

[Unit]
Description=printip
DefaultDependencies=no
After=icewm-init.service
Before=display-manager.service

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="IP=$CLIENT_IP"
Environment="IFACE=$NET_DEVICE"
EnvironmentFile=/etc/thinstation.env
ExecStart=/etc/init.d/printip
SyslogIdentifier=thinstation

[Install]
WantedBy=multi-user.target

I wrote a utility for diagnosing variables:

import std.stdio : writeln , File;
import std.process : environment;
import std.exception;

int main()
{
    File file;
    int error = 0;

    try
    {
        file = File("/var/log/printip.log", "w");
    }
    catch (Exception e)
    {
        ++error;
        return error;
    }

    try
    {
        file.writeln("\t    IP: " ~ environment["CLIENT_IP"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    try
    {
        file.writeln("\t IFACE: " ~ environment["NET_DEVICE"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    try
    {
        file.writeln("\tTSUSER: " ~ environment["TSUSER"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    file.close();

    return error;
}

After launching checking the status of the service:

ts_d85ed3156a39:~# systemctl status printip

● printip.service - printip
     Loaded: loaded (/etc/systemd/system/printip.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2022-04-29 00:35:52 MSK; 32s ago
    Process: 1814 ExecStart=/etc/init.d/printip (code=exited, status=2)
   Main PID: 1814 (code=exited, status=2)

апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: Starting printip...
апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: printip.service: Failed with result 'exit-code'.
апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: Failed to start printip.

It can be seen that the error is equal to the value 2. Checking the log:

ts_d85ed3156a39:~# cat /var/log/printip.log 
Environment variable not found: CLIENT_IP
Environment variable not found: NET_DEVICE
    TSUSER: root

My set variables were not read. But the variable installed from the file was read.

I start the service from under SSH manually:

ts_d85ed3156a39:~# systemctl start printip
Job for printip.service failed because the control process exited with error code.
See "systemctl status printip.service" and "journalctl -xe" for details.

There were also errors from under SSH:

апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: Starting printip...
апр 29 00:35:52 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
апр 29 00:36:04 ts_d85ed3156a39 crond[2769]: PORT=5900
апр 29 00:37:27 ts_d85ed3156a39 systemd[1]: Starting printip...
-- Subject: Начинается запуск юнита printip.service
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Начат процесс запуска юнита printip.service.
апр 29 00:37:27 ts_d85ed3156a39 systemd[1]: printip.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- An ExecStart= process belonging to unit printip.service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 2.
апр 29 00:37:27 ts_d85ed3156a39 systemd[1]: printip.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The unit printip.service has entered the 'failed' state with result 'exit-code'.
апр 29 00:37:27 ts_d85ed3156a39 systemd[1]: Failed to start printip.
-- Subject: Ошибка юнита printip.service
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Произошел сбой юнита printip.service.
-- 
-- Результат: failed.
апр 29 00:37:27 ts_d85ed3156a39 kernel: kauditd_printk_skb: 4 callbacks suppressed
апр 29 00:37:27 ts_d85ed3156a39 kernel: audit: type=1130 audit(1651181847.291:59): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=p
апр 29 00:37:27 ts_d85ed3156a39 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=printip comm="systemd" exe="

It is not possible to transfer variables from the global environment inside the service being started.

AlexanderZhirov commented 2 years ago

I wrote a utility for diagnosing variables:

import std.stdio : writeln , File;
import std.process : environment;
import std.exception;

int main()
{
    File file;
    int error = 0;

    try
    {
        file = File("/var/log/printip.log", "w");
    }
    catch (Exception e)
    {
        ++error;
        return error;
    }

    try
    {
        file.writeln("\t    IP: " ~ environment["CLIENT_IP"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    try
    {
        file.writeln("\t IFACE: " ~ environment["NET_DEVICE"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    try
    {
        file.writeln("\tTSUSER: " ~ environment["TSUSER"].idup);
    }
    catch (Exception e)
    {
        file.writeln(e.msg);
        ++error;
    }

    file.close();

    return error;
}

I made a typo in the code. Even after the edits, it's still not the data I need.

ts_d85ed3156a39:~# cat /var/log/printip.log 
        IP: $CLIENT_IP
     IFACE: $NET_DEVICE
    TSUSER: root
AlexanderZhirov commented 2 years ago
[Unit]
Description=printip
DefaultDependencies=no
After=icewm-init.service
Before=display-manager.service

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="IP=$CLIENT_IP"
Environment="IFACE=$NET_DEVICE"
EnvironmentFile=/etc/thinstation.env
ExecStart=/etc/init.d/printip
SyslogIdentifier=thinstation

[Install]
WantedBy=multi-user.target

As far as I understand, there through the % specifier I can get access to already installed system variables. And then how to get access to other global variables?

Doncuppjr commented 2 years ago

I don't think system init is the right place to put that. Try .xinitrc

On Thursday, April 28, 2022, 07:03:04 AM PDT, Alexander Zhirov @.***> wrote:

   [Unit] Description=printip DefaultDependencies=no After=icewm-init.service Before=display-manager.service

[Service] Type=oneshot RemainAfterExit=yes Environment="IP=$CLIENT_IP" Environment="IFACE=$NET_DEVICE" EnvironmentFile=/etc/thinstation.env ExecStart=/etc/init.d/printip SyslogIdentifier=thinstation

[Install] WantedBy=multi-user.target

As far as I understand, there through the % specifier I can get access to already installed system variables. And then how to get access to other global variables?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

AlexanderZhirov commented 2 years ago

I don't think system init is the right place to put that. Try .xinitrc

You mean add variables to .xinitrc and will they be visible in the service being launched? Or run the service itself as a regular command in .xinitrc?

Thinstation commented 2 years ago

Run the service itself as a regular command from .xinitrc

On Thu, Apr 28, 2022 at 8:25 AM Alexander Zhirov @.***> wrote:

I don't think system init is the right place to put that. Try .xinitrc

You mean add variables to .xinitrc and will they be visible in the service being launched? Or run the service itself as a regular command in .xinitrc?

— Reply to this email directly, view it on GitHub https://github.com/Thinstation/thinstation/issues/717#issuecomment-1112345314, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVW47SFKLQWJMFTNCFDBSTVHKUXTANCNFSM5URYNXIA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AlexanderZhirov commented 2 years ago

Run the service itself as a regular command from .xinitrc

And how can I correctly add such an opportunity to the package so that in .xinitrc got my command to run my program? After all, the file is generated when you log in.

AlexanderZhirov commented 2 years ago

Run the service itself as a regular command from .xinitrc

And how can I correctly add such an opportunity to the package so that in .xinitrc got my command to run my program? After all, the file is generated when you log in.

Figured it out. I added the printip/build/finalize startup file and wrote there:

echo "printip /etc/background.jpg /root/.fonts/JetBrainsMono.ttf \$(cat /var/log/applications/resolutions | tail -n1 | sed 's/x[0-9]*//g') \$(cat /var/log/applications/resolutions | tail -n1 | sed 's/[0-9]*x//g')" >> /etc/skel/.xinitrc

Collected the image. Launch. There are no changes on the screen. Checking the file .xinitrc:

ts_d85ed3156a39:~# cat .xinitrc 

(. /etc/thinstation.global; use_idesk &)
printip /etc/background.jpg /root/.fonts/JetBrainsMono.ttf $(cat /var/log/applications/resolutions | tail -n1 | sed 's/x[0-9]*//g') $(cat /var/log/applications/resolutions | tail -n1 | sed 's/[0-9]*x//g')

I downloaded the background image via SSH and here is the result:

изображение

Now everything has worked out! Now it remains to understand how to run my script before starting WM.

AlexanderZhirov commented 2 years ago

Now everything has worked out! Now it remains to understand how to run my script before starting WM.

And what does the first line at the beginning of the ica/build/finalize file mean?

#ica 25

I thought this was the launch priority... I tried to add a string with different values to my file printip/build/finalize. Most likely I'm doing something wrong.

#printip 10

I want to make the launch of my utility a priority in .xinitrc.

Thinstation commented 2 years ago

You could also create a file in /etc/X11/xinit/xinitrc.d that calls your script. This will be run before the window manager or .xinitrc

AlexanderZhirov commented 2 years ago

You could also create a file in /etc/X11/xinit/xinitrc.d that calls your script.

Yes, it works, thank you! But, still I need to use systemd as a service.

I have a remote website through which I can manage a thin client. If the thin client has a connection of monitors more than 1, then set their location remotely, through the portal. This requires DISPLAY visibility. xrandr copes with this task. But for it to work, access to the display is required.

AlexanderZhirov commented 2 years ago

As far as I understand, the /etc/xinitrc script is executed before icewm is started:

#!/bin/bash

xinitrcd=/etc/X11/xinit/xinitrc.d
if [ -d $xinitrcd ]; then
    for file in `ls -A $xinitrcd`; do
        . $xinitrcd/$file
    done
fi
# Just run xrandr 1 time to populate some settings in case we don't use a window manager
xrandr
cd /
if [ -n "$1" ]; then
    exec $1
elif [ -e $WKDIR/windowapps ] ; then
        exec $WKDIR/windowapps
fi

Why does xrandr work here, and in my case the user service refuses to access DISPLAY?

AlexanderZhirov commented 2 years ago

Why does xrandr work here, and in my case the user service refuses to access DISPLAY?

@Thinstation As far as I understand, it is necessary to create a user systemd service. Is there an example of creating such a service within thinstation? To have access to the management of the user environment from under the systemd service.

Doncuppjr commented 2 years ago

Because the DISPLAY variable is exported to the environment.  Add. /etc/thonstation.global to the top of your script.

Sent from Yahoo Mail for iPhone

On Thursday, May 12, 2022, 10:59 PM, Alexander Zhirov @.***> wrote:

As far as I understand, the /etc/xinitrc script is executed before icewm is started:

!/bin/bash

xinitrcd=/etc/X11/xinit/xinitrc.d if [ -d $xinitrcd ]; then for file in ls -A $xinitrcd; do . $xinitrcd/$file done fi

Just run xrandr 1 time to populate some settings in case we don't use a window manager

xrandr cd / if [ -n "$1" ]; then exec $1 elif [ -e $WKDIR/windowapps ] ; then exec $WKDIR/windowapps fi

Why does xrandr work here, and in my case the user service refuses to access DISPLAY?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

AlexanderZhirov commented 2 years ago

Here is the hierarchy of my service:

.
├── bin
│   └── myprogram
└── etc
     ├── init.d
     │   └── myprogram
     └── systemd
         └── user
             ├── default.target.wants
             │   └── myprogram.service -> ../myprogram.service
             └── myprogram.service

Where /bin/myprogram is the program itself. File /etc/init.d/myprogram:

#!/bin/sh

. /etc/thinstation.global

myprogram

And the /etc/systemd/user/myprogram.service file looks like this:

[Unit]
Description=myprogram
BindsTo=graphical-session.target

[Service]
ExecStart=/etc/init.d/myprogram

As a result, it turns out that the service starts, but still does not see the screen:

● myprogram.service - myprogram
     Loaded: loaded (/etc/systemd/user/myprogram.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2022-05-20 01:34:18 MSK; 21s ago
    Process: 3454 ExecStart=/etc/init.d/myprogram (code=exited, status=1/FAILURE)
   Main PID: 3454 (code=exited, status=1/FAILURE)

may 20 01:34:18 ts_080027b3b812 systemd[3451]: Started myprogram.
may 20 01:34:18 ts_080027b3b812 myprogram[3593]: Can't open display :0.0
may 20 01:34:18 ts_080027b3b812 systemd[3451]: myprogram.service: Main process exited, code=exited, status=1/FAILURE
may 20 01:34:18 ts_080027b3b812 systemd[3451]: myprogram.service: Failed with result 'exit-code'.

Here, at the moment when the xrandr call string is being processed in the code, the service crashes because there is no access to the display.

Other information (network interface) collects and logs into a file:

ts_080027b3b812:~# cat /var/log/myprogram.log 
IFace("enp0s8", "08:00:27:ff:42:ed", "192.168.56.107")

Information about the screen should also have been recorded in this file. But alas, the service does not see the display.

I start the service manually - everything works, since the display is available:

ts_080027b3b812:~# systemctl --user start myprogram.service
ts_080027b3b812:~# systemctl --user status myprogram.service
● myprogram.service - myprogram
     Loaded: loaded (/etc/systemd/user/myprogram.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2022-05-20 02:04:39 MSK; 28s ago
    Process: 4673 ExecStart=/etc/init.d/myprogram (code=exited, status=0/SUCCESS)
   Main PID: 4673 (code=exited, status=0/SUCCESS)

may 20 02:04:39 ts_080027b3b812 systemd[3451]: Started myprogram.
may 20 02:04:39 ts_080027b3b812 systemd[3451]: myprogram.service: Succeeded.

ts_080027b3b812:~# cat /var/log/myprogram.log
IFace("enp0s8", "08:00:27:ff:42:ed", "192.168.56.107")
[Monitor("VGA-1", true, 1280, 1024)]

I still don't understand what I'm doing wrong.

Thinstation commented 2 years ago

If your program is meant to interact with the graphical portion, I would stop with systemd. Just put your script in /etc/X11/xinit/xinitrc.d/99-myprogram.sh and make sure it is executable.

AlexanderZhirov commented 2 years ago

If your program is meant to interact with the graphical portion, I would stop with systemd

No, there is no work with the graphical interface. This is just one of the internal elements of the mechanism, but it is needed. Still, if there is an opportunity, and there definitely is, I want to try to run the service from under systemd.

Thinstation commented 2 years ago

set it to start after display-manager.service

AlexanderZhirov commented 2 years ago

I managed to create a service that runs with access to the display:

.
├── bin
│   └── myprogram
├── build
│   └── finalize
└── etc
    ├── systemd
    │   └── user
    │       └── myprogram.service
    └── skel
        └── .config
            └── systemd
                └── user
                    └── graphical-session.target.wants
                        └── myprogram.service -> /etc/systemd/user/myprogram.service

/etc/systemd/user/myprogram.service:

[Unit]
Description=myprogram
PartOf=graphical-session.target

[Service]
ExecStart=/bin/myprogram

[Install]
WantedBy=default.target

/etc/skel/finalize:

echo "export XDG_RUNTIME_DIR=/run/user/\$(id -u)" >> /etc/skel/.profile
echo "systemctl --user start myprogram.service" >> /etc/skel/.xinitrc

After that, the service started to run after downloading the distribution. Everything is just amazing, except for one thing! @Thinstation Please tell me how (and how it is regulated) it is possible to add processing of my package FIRST?

After downloading the distribution ~/.xinitrc looks like this:

(. /etc/thinstation.global; use_idesk &)
systemctl --user start myprogram.service

I need to run my service first, and then run DE.

Doncuppjr commented 2 years ago

Put you commands in  /etc/X11/xinit/xinitrc.d/10-mystuff chmod +x that file, then that should run before ~/.xinitrc