Вы должны определить ее как функцию и вызвать ее с псевдонимом:
function __blacklight() {
echo "$@";
cd ~/Code/MSI-Backlight;
sudo nodejs ~/Code/MSI-Backlight/msi-backlight.js "$@";
}
alias backlight='__blacklight'
Gracias Patrick por tan explicada respuesta y despejar algunas de mis dudas.
Gracias maravilla por hacer las pruebas en mi nombre.
Como menciona la respuesta de Patrick , debido al orden indefinido, puede comportarse mal. B.service
no puede ejecutar mkdir
porque el directorio ya existe y A.service
aún no lo ha eliminado.
Puede definir un orden para ambos. No importa cuál comience primero, se comportarán de la misma manera según sus requisitos actuales.
O puede crear archivos pid
separados para ambos servicios y en ExecStopPost
simplemente elimine el archivo pid
en lugar del directorio.
Tenga en cuenta que si está siguiendo el segundo método, ExecStartPre
no será necesario.
FYI, después de revisar algunos de los scripts init.d
, creo que el mejor lugar para colocar los archivos pid
es /var/run/
sin crear ningún directorio adicional. Esto será válido solo si sus servicios se inician como root ya que la ubicación está protegida contra escritura solo para root.
Вы не указали никаких ограничений по порядку между двумя службами. Таким образом, происходит следующее: B.service
запускает (и выполняетmkdir
)до того, как A.service
завершит остановку (и выполнитrm
).
Соответствующий раздел документации systemd.unit:
Conflicts=
Note that this setting is independent of and orthogonal to the After= and Before= ordering dependencies.
Решение состоит в том, чтобы добавить другую службу в каждый After=
список (добавить A.service
к B.service
After=
и наоборот ).
См. также соответствующий раздел документации :
Before=, After=
Given two units with any ordering dependency between them, if one unit is shut down and the other is started up, the shutdown is ordered before the start-up. It doesn't matter if the ordering dependency is After= or Before=, in this case. It also doesn't matter which of the two is shut down, as long as one is shut down and the other is started up. The shutdown is ordered before the start-up in all cases.
^ означает, что на самом деле не имеет значения, используете ли вы After=
или Before=
. Они оба сделают одно и то же.