Skip to content

How to run a script every started? #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhangguanzhang opened this issue Sep 6, 2021 · 6 comments
Closed

How to run a script every started? #786

zhangguanzhang opened this issue Sep 6, 2021 · 6 comments

Comments

@zhangguanzhang
Copy link
Contributor

zhangguanzhang commented Sep 6, 2021

There are inexplicable permissions problems in some environments. I want to execute chown before the mysqld process to fix these problems. How could I use the root user to run the script, :

chown -R mysql:mysql /var/log/mysql  /var/run/mysql /var/lib/mysql
chmod 1777 /tmp
@zhangguanzhang
Copy link
Contributor Author

something like this MariaDB/mariadb-docker#284 (comment)
But I dont't want to hijack the docker-entrypoint.sh

@zhangguanzhang zhangguanzhang changed the title why remove the /always-initdb.d How to run a script every started? Sep 6, 2021
@tianon
Copy link
Member

tianon commented Sep 7, 2021

Duplicate of #642

@tianon tianon marked this as a duplicate of #642 Sep 7, 2021
@tianon tianon closed this as completed Sep 7, 2021
@zhangguanzhang
Copy link
Contributor Author

not Duplicate. the scripts in /docker-entrypoint-initdb.d/ cannot use gosu root to run a command

@yosifkit
Copy link
Member

yosifkit commented Sep 8, 2021

gosu can only be used to drop from root to another user; not to go from an arbitrary user up to root.

See also https://github.com/tianon/gosu/tree/9f7cd138a1ebc0684d43ef6046bf723978e8741f#warning

@tianon
Copy link
Member

tianon commented Sep 8, 2021

If you want to run the startup scripts as root, you'll need to implement your own entrypoint.

@zhangguanzhang
Copy link
Contributor Author

If you want to run the startup scripts as root, you'll need to implement your own entrypoint.

I think the script should change to this:

		if [ "$(id -u)" = "0" ]; then
			mysql_note "Switching to dedicated user 'mysql'"
                        docker_process_init_files /docker-entrypoint-root-run.d/*
			exec gosu mysql "$BASH_SOURCE" "$@"
		fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants