Closed AlexanderZhirov closed 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.
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
[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?
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: @.***>
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
?
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: @.***>
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.
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.
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
.
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
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.
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
?
Why does
xrandr
work here, and in my case the user service refuses to accessDISPLAY
?
@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
.
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:
xinitrcd=/etc/X11/xinit/xinitrc.d
if [ -d $xinitrcd ]; then
for file in ls -A $xinitrcd
; do
. $xinitrcd/$file
done
fi
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: @.***>
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.
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.
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.
set it to start after display-manager.service
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.
Put you commands in /etc/X11/xinit/xinitrc.d/10-mystuff chmod +x that file, then that should run before ~/.xinitrc
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):
Based on this program, I created a service
printip
, filepackages/printip/etc/systemd/system/printip.service
:Also created a link for autorun
packages/printip/etc/systemd/system/multi-user.target.wants/printip.service
. The startup scriptpackages/printip/etc/init.d/printip
looks like this: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.
It feels like the
/var/log/applications/resolutions
file doesn't exist! But it ALREADY exists whenIceWM
is launched. I connect via ssh and see this file: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:I check the log to find an error and I get this:
Just those two screen resolution parameters that I'm trying to pass.
If I manually start the service, it turns out like this:
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 tosystemd
, but I could not do it by means ofsystemd
through global definitions (throughEnvironment=
,EnvironmentFile=
) nor through thesystemctl --user import-environment
command.It is not even possible to pass arguments statically:
Result after reboot:
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?