In sytstemd service targetctl (/nix/store/a1f9s815jflz86j63r8wzgvkr0gmxcr2-python3.9-rtslib-2.1.74/bin/targetctl) not found saveconfig.json file for restore targets iscsi after reboot nixos 21.11: service for restore in /etc/nixos/configuration.nix:
systemd.services.foo = {
enable=true;
description="iscsi start";
unitConfig = {
Type = "simple";
};
serviceConfig = {
User="root";
Group="root";
RemainAfterExit="yes";
ExecStart = "/root/script.sh";
};
wantedBy = ["multi-user.target"];
after = ["sys-kernel-config.mount network.target local-fs.target"];
};
script.sh:
#!/nix/store/p0s6lymjfi6d9sdx253912zryvw2d2fr-system-path/bin/sh
if [[ -s /root/saveconfig.json ]]
then
echo "saveconfig.json exist"
else
echo "saveconfig.json not exist"
fi
/nix/store/a1f9s815jflz86j63r8wzgvkr0gmxcr2-python3.9-rtslib-2.1.74/bin/targetctl restore /root/saveconfig.json
systemctl status foo.service:
● foo.service - iscsi start
Loaded: loaded (/etc/systemd/system/foo.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2022-05-25 05:02:40 UTC; 27s ago
Process: 818 ExecStart=/root/script.sh (code=exited, status=0/SUCCESS)
Main PID: 818 (code=exited, status=0/SUCCESS)
IP: 0B in, 0B out
CPU: 126ms
May 25 05:02:40 nixos systemd[1]: Started iscsi start.
May 25 05:02:40 nixos script.sh[818]: saveconfig.json exist
May 25 05:02:40 nixos script.sh[820]: No saved config file at /root/saveconfig.json, ok, exiting
/etc/systemd/system/foo.service:
[Unit]
After=sys-kernel-config.mount network.target local-fs.target
Description=iscsi start
Type=simple
[Service]
Environment="LOCALE_ARCHIVE=/nix/store/y9ga08zc1hif37f72vfmi8lys7ki5lmc-glibc-locales-2.33-123/lib/locale/locale-archive"
Environment="PATH=/nix/store/ndkb1hkd009fch9dkzs31p9b7sa61s61-coreutils-9.0/bin:/nix/store/majf16rlq7ggn18p3k380hv66gmpqhc9-findutils-4.8.0/bin:/nix/store/hq0dj7mrf3nn4xppyg4ypmm2jb2cpfla-gnugrep-3.7/bin:/nix/store/zym2hpmaz22x0rc8x09d862g1gr22djw-gnused-4.8/bin:/nix/store/kmxd50nhkzhm8iwscmi05h9kj3p45ghg-systemd-249.7/bin:/nix/store/ndkb1hkd009fch9dkzs31p9b7sa61s61-coreutils-9.0/sbin:/nix/store/majf16rlq7ggn18p3k380hv66gmpqhc9-findutils-4.8.0/sbin:/nix/store/hq0dj7mrf3nn4xppyg4ypmm2jb2cpfla-gnugrep-3.7/sbin:/nix/store/zym2hpmaz22x0rc8x09d862g1gr22djw-gnused-4.8/sbin:/nix/store/kmxd50nhkzhm8iwscmi05h9kj3p45ghg-systemd-249.7/sbin"
Environment="TZDIR=/nix/store/izida45x5809k8pxx7nwnlnvfgi3k6q3-tzdata-2022a/share/zoneinfo"
ExecStart=/root/script.sh
Group=root
RemainAfterExit=yes
User=root
I saw a similar question: Python script as systemd service but I didn 't understand about
adding
with pkgs; [utillinux kmod];
tosystemd.services.iscsi-target.path
, so it’s in the services$PATH
, too.
How to solve the problem? Thanks.