User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gentoo:locald [2024/04/05 07:57] willygentoo:locald [2024/07/30 09:40] (current) willy
Line 8: Line 8:
  
 Let me show how i am managing this approach. Let me show how i am managing this approach.
 +
 +*NOTE:* this approach _do not applies_ to podman containers. See [[gentoo:containers|Using Containers on Gentoo]] for more info on how i manage to autostart containers on boot.
  
 ===== local.d ===== ===== local.d =====
Line 30: Line 32:
 The other way is to use local.d service leveraging a specific script with symlinks: the idea is to use one script for most of the services, and just create a symlink to the start and stop scripts themselves.  The other way is to use local.d service leveraging a specific script with symlinks: the idea is to use one script for most of the services, and just create a symlink to the start and stop scripts themselves. 
  
-Assuming you have a service called **myservice**, which is a podman container, run as //myuser// user, all you need to do it: +For simple non-containerized service called **mynormalservice** running as user **myotheruser**:
-<code bash> +
-cd /etc/local.d +
-ln -s _servicer.sh 50-myservice-myuser-podman.start  +
-ln -s _servicer.sh 50-myservice-myuser-podman.stop +
-</code> +
- +
-and that's it. This will automatically create the **/var/run/myservice.pid** file for service-monitoring, and allow proper start and stop of the service. This will require the usual //docker-compose.yml// file in the //myuser// folder. +
- +
-Similarly, for a simple non-containerized service:+
 <code bash> <code bash>
 cd /etc/local.d cd /etc/local.d
Line 68: Line 61:
 #  - user is the user the service will run as. Can be omitted, in this case use two "--", and user=service #  - user is the user the service will run as. Can be omitted, in this case use two "--", and user=service
 #  - type is one of: #  - type is one of:
-#        - podman: the service is a podman-compose based containeration 
 #        - script: the service is managed by a script ($user_home/myservice_start.sh or $user_home/myservice.sh, and $user_home/myservice_stop.sh (optional)) #        - script: the service is managed by a script ($user_home/myservice_start.sh or $user_home/myservice.sh, and $user_home/myservice_stop.sh (optional))
 #        - service: the service command is specified inside a service_${service}_start file in the user home folder #        - service: the service command is specified inside a service_${service}_start file in the user home folder
Line 91: Line 83:
 USER_HOME=$(echo ${passwd_entry} | cut -d: -f 6) USER_HOME=$(echo ${passwd_entry} | cut -d: -f 6)
  
-echo "$(date): ${ACTION}-ing service '${SERVICE}' for user '${USER}', as '${TYPE}' (${USER_HOME}'" >> ${actions_logs}+echo "$(date): ${ACTION}-ing service '${SERVICE}' for user '${USER}', as '${TYPE}' (${USER_HOME})" >> ${actions_logs}
  
 if [ "${ACTION}" = "start" ] if [ "${ACTION}" = "start" ]
Line 99: Line 91:
         } && chown -R ${USER} "${LOG_PATH}/${SERVICE}"         } && chown -R ${USER} "${LOG_PATH}/${SERVICE}"
         extra_opts=(-1 "${LOG_PATH}/${SERVICE}/${SERVICE}.out.log" -2 "${LOG_PATH}/${SERVICE}/${SERVICE}.err.log")         extra_opts=(-1 "${LOG_PATH}/${SERVICE}/${SERVICE}.out.log" -2 "${LOG_PATH}/${SERVICE}/${SERVICE}.err.log")
-        if [ "${TYPE}" = "podman"+        if [ "${TYPE}" = "script" ]
-        then +
-                COMMAND="$(which podman)" +
-                ARGUMENTS=(compose up) +
-                echo "          ... ensuring nat table is loaded ..." >> ${actions_logs} +
-                iptables -L -t nat &> /dev/null +
-                echo "          ... creating '${SERVICE}-net' ..." >> ${actions_logs} +
-                podman network create ${SERVICE}-net &> /dev/null +
-                echo "          ... running a 'podman compose down' just in case ..." >> ${actions_logs} +
-                su - "${USER}" -c "$(which podman) compose down" &> /dev/null +
-        elif [ "${TYPE}" = "script" ]+
         then         then
                 echo "          ... checking for start scripts ..." >> ${actions_logs}                 echo "          ... checking for start scripts ..." >> ${actions_logs}
Line 132: Line 114:
 then then
         extra_opts=()         extra_opts=()
-        if [ "${TYPE}" = "podman"+        if [ "${TYPE}" = "script" ]
-        then +
-                echo "          ... running 'podman compose down' ..." >> ${actions_logs} +
-                su - "${USER}" -c "$(which podman) compose down" &> /dev/null +
-                action=(--stop "${SERVICE}"+
-        elif [ "${TYPE}" = "script" ]+
         then         then
                 echo "          ... checking for stop script ..." >> ${actions_logs}                 echo "          ... checking for stop script ..." >> ${actions_logs}
Line 152: Line 129:
 fi fi
  
-start-stop-daemon -p /var/run/${SERVICE}.pid ${extra_opts[@]} -${SERVICE} -u ${USER} -d ${USER_HOME} ${action[@]}+echo start-stop-daemon -p /var/run/${SERVICE}.pid ${extra_opts[@]} -u ${USER} -d ${USER_HOME} ${action[@]} >> ${actions_logs} 
 +start-stop-daemon -p /var/run/${SERVICE}.pid ${extra_opts[@]} -u ${USER} -d ${USER_HOME} ${action[@]}
  
-echo "$(date): ${ACTION}-ed service '${SERVICE}' for user '${USER}', as '${TYPE}' (${USER_HOME}'" >> ${actions_logs}+echo "$(date): ${ACTION}-ed service '${SERVICE}' for user '${USER}', as '${TYPE}' (${USER_HOME})" >> ${actions_logs}
 </file> </file>
  
Line 173: Line 151:
 **User name:** which user shall run the service. Can be omitted (just leave two "--") and in this case a user with the same name as the service will be used. The user __must__ exist. **User name:** which user shall run the service. Can be omitted (just leave two "--") and in this case a user with the same name as the service will be used. The user __must__ exist.
  
-**Service type:** can be //podman//, //service// or //script//: +**Service type:** can be //service// or //script//:
-  - //podman//: run **podman compose up (or down)** as the user+
   - //service//: source the file $HOME/service_<service>_start and execute COMMAND ARGUMENTS (see example below)   - //service//: source the file $HOME/service_<service>_start and execute COMMAND ARGUMENTS (see example below)
   - //script//: will run $HOME/<service>_start.sh / $HOME/<service>_stop.sh   - //script//: will run $HOME/<service>_start.sh / $HOME/<service>_stop.sh
Line 194: Line 171:
 If you use (and you sohuld) LogRotate to keep your logs sanely rotated and trimmed, add the following **/etc/logrotate.d/servicer** file: If you use (and you sohuld) LogRotate to keep your logs sanely rotated and trimmed, add the following **/etc/logrotate.d/servicer** file:
 <file - servicer> <file - servicer>
-/var/log/servicer.log{+/var/log/servicer/*/.log{ 
 +    missingok 
 +
 +/var/log/servicer/servicer.log{
     missingok     missingok
 } }

This website uses technical cookies only. No information is shared with anybody or used in any way but provide the website in your browser.

More information