Why does baseInsertService not activate the service?

22 views
Skip to first unread message

Raphael Traviss

unread,
Sep 17, 2024, 12:57:38 PM9/17/24
to kiwi
I have a series of systemd services in the root filesystem:
systemd_services.png


I have the following inside `config.sh`, but in order to actually activate the service, it needs that `systemctl enable mission.service`:

```
#======================================
# Mission setup
#--------------------------------------
baseInsertService mission.service
systemctl enable mission.service
```


When I just use baseInsertService--it doesn't work.

I need the `systemctl enable mission.service` -- does anyone know why?


Raphael Traviss

unread,
Sep 17, 2024, 1:33:27 PM9/17/24
to kiwi
haha--it's the service name: it needs to be `myservice`, not `myservice.service`.

It was not activating because `/etc/systemd/system/myservice.service.service` did not exist:


```
function baseInsertService {
    # /.../
    # Enable a system service using systemctl
    # Examples:
    #
    # baseInsertService sshd
    #   --> enable sshd service
    #
    # ----
    local service=$1
    baseSystemdCall "${service}" "enable"
}

function baseSystemdCall {
    local service_name=$1; shift
    local service
    local legacy_service
    service=$(baseSystemdServiceInstalled "${service_name}")
    if [ -n "${service}" ];then
        systemctl "$@" "${service_name}"
    else
        legacy_service=$(baseSysVServiceInstalled "${service_name}")
        if [ -n "${legacy_service}" ];then
            # systemd is sysV init compatible and still allows
            # to enable those type of services
            systemctl "$@" "${legacy_service}"
        else
          #####
          # the script should fail here
          #####
        fi
    fi
}

function baseSystemdServiceInstalled {
    local service=$1
    local sd_dirs="
        /usr/lib/systemd/system
        /etc/systemd/system
        /run/systemd/system
    "
    local dir
    for dir in ${sd_dirs} ; do
        if [ -f "${dir}/${service}.service" ];then
            echo "${dir}/${service}.service"
            return
        fi
        if [ -f "${dir}/${service}.mount" ];then
            echo "${dir}/${service}.mount"
            return
        fi
    done
}
```

Marcus Schäfer

unread,
Sep 18, 2024, 10:07:43 AM9/18/24
to kiwi-...@googlegroups.com
Hi,

> #======================================
> # Mission setup
> #--------------------------------------
> baseInsertService mission.service
> systemctl enable mission.service

yeah issue here is that baseInsertService only wants the name

baseInsertService mission

should work.

I do not recommend to make use of this helper methods. Just
call systemctl directly. systemd also supports .timer, .target
and other service types that can be enabled/disabled. The
baseInsertService only inserts .service files and expectes
just the basename of the service

Hope this helps

Regards,
Marcus
--
Public Key available via: https://keybase.io/marcus_schaefer/key.asc
keybase search marcus_schaefer
signature.asc

Neal Gompa

unread,
Sep 20, 2024, 6:36:04 AM9/20/24
to kiwi-...@googlegroups.com
I recommend not using those wrappers. They are mostly legacy these days and using systemctl directly is better.

--
You received this message because you are subscribed to the Google Groups "kiwi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kiwi-images...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kiwi-images/b81b6551-0eba-4c45-96d4-09a90a440c10n%40googlegroups.com.


--
真実はいつも一つ!/ Always, there's only one truth!
Reply all
Reply to author
Forward
0 new messages